Is there a way to provide a static popup menu for a custom view in Eclipse Kepler? Creating a dynamic one is easy, but I would like to be able to define the commands in the plugin.xml file as for the Project Explorer. Looking at my custom view with the Eclipse Spy I see no active menu contribution identifiers. How can I define one?
In your view part set up the context menu like this:
MenuManager contextMenu = new MenuManager();
contextMenu.setRemoveAllWhenShown(true);
Control control = viewer.getControl();
Menu menu = contextMenu.createContextMenu(control);
control.setMenu(menu);
getSite().registerContextMenu(contextMenu, viewer);
The registerContextMenu
call makes the menu available to the org.eclipse.ui.menus
extension point so you can define menu items like this:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:your view id here">
... you menu items ...
来源:https://stackoverflow.com/questions/19183360/popup-menu-on-custom-view-in-eclipse-plug-in-kepler