I already have a popup working on the main Eclipse RCP application (3.X).
Now, I am trying to add a popup (menu contribution) to an Eclipse RCP plugin (it is linked to the application as a dependency). This plugin did not have the plugin.xml file that allows to add extensions, so I have created a new one. The popup configuration is as follows:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:table.popupmenu?after=additions">
<command
commandId="copy"
label="Copy"
style="push">
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="copy"
name="Copy">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="package.CopyHandler"
commandId="copy">
</handler>
</extension>
The handler class exists.
Then I have added to my "Table" class the following code to bind the menu (after creating the Table object):
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActivePart().getSite();
MenuManager menuManager = new MenuManager();
Menu menu = menuManager.createContextMenu(this.table);
this.table.setMenu(menu);
site.registerContextMenu("table.popupmenu", menuManager, site.getSelectionProvider());
As I could not get it working I have followed this tutorial (7.Tutorial: Commands and context menus), and works fine. I can not see the configuration i am missing.
If there is another good way to get a popup menu from a control (SWT) I would be glad to try that as well.
question from:
https://stackoverflow.com/questions/65833250/how-can-i-add-a-popup-menu-contribution-from-an-eclipse-plugin 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…