ContextMenu on TabSheet Header

I am trying to build a contextmenu for the tabsheet to give the user the option to “close other tabs” and “reload tab” etc.

There does not seem to be a built in solution to listen for mouseclicks of each tab. When using the Vaadin ContextMenu addon i have two problems:

  1. I don’t know which tab has been clicked. I could add a ContextMenuOpenListener to the ContextMenu and get x/y in the event, however i don’t find a way to get the tab located at x/y.
  2. The context menu opens not only when the user clicks in the tab header on a specific tab, but also in the whole content area. This is really bad. I want the contextmenu to be opened when the user clicks in the header only.

I initialize the contextmenu like this:

final ContextMenu menu = new ContextMenu(tabSheet, true);
menu.addItem("reload", selectedItem -> LOG.info("reload"));
menu.addItem("close others", selectedItem -> LOG.info("close others"));

Any hints or solutions?

Additional info: I am using 8.1.0.alpha7

you can do something like :

	TabSheet mainTab = new TabSheet();

    mainTab.addContextClickListener(c -> {
        ContextMenu contextMenu = new ContextMenu(mainTab, true);
        MenuItem item = contextMenu.addItem("Close", e -> {
            TabSheet ts = (TabSheet)c.getSource();
            TabSheet.Tab tab = ts.getTab(ts.getSelectedTab());
            ts.removeTab(tab);
        });
        MenuItem item2 = contextMenu.addItem("Close All", e-> {
				for (){ 
				/* remove all tabs */
				}
        });

        contextMenu.open(c.getClientX(),c.getClientY());

    });