Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

java - How can I add a popup (menu contribution) from an Eclipse plugin?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...