/** * Creates a pop-up menu on the given control. The menu * is registered with this view's site, such that other * plug-ins may contribute to the menu. Subclasses should * call this method, specifying the menu control as the * control used in their viewer (for example, tree viewer). * Subclasses must implement the method * <code>#fillContextMenu(IMenuManager)</code> which will * be called each time the context menu is realized. * * @param menuControl the control with which the pop-up * menu will be associated with. */ protected void createContextMenu(Control menuControl) { MenuManager menuMgr= new MenuManager("#PopUp"); //$NON-NLS-1$ menuMgr.setRemoveAllWhenShown(true); menuMgr.addMenuListener(mgr -> fillContextMenu(mgr)); Menu menu= menuMgr.createContextMenu(menuControl); menuControl.setMenu(menu); // register the context menu such that other plug-ins may contribute to it if (getSite() != null) { getSite().registerContextMenu(menuMgr, getViewer()); } addContextMenuManager(menuMgr); }