以编程方式在Eclipse插件上添加上下文菜单

时间:2015-10-22 20:26:29

标签: java eclipse eclipse-rcp

我已经查看了几个类似的问题,但我无法解决此问题,我想在Project Explorer视图中右键单击项目或文件夹时,将子项添加到上下文菜单中。

我在plugin.xml中添加了根元素:

<extension
    point="org.eclipse.ui.menus">
  <menuContribution
     allPopups="true"
     class="com.my.menu.MyMenu"
     locationURI="popup:org.eclipse.ui.popup.any?after=additions">
  </menuContribution>

MyMenu类扩展了ExtensionContributionFactory,并且我覆盖了createContributionItems()方法,如下所示:

@Override
public void createContributionItems(final IServiceLocator serviceLocator, final IContributionRoot additions) {
    // build a command-based contribution parameters
    CommandContributionItemParameter pAA = new CommandContributionItemParameter(
            serviceLocator,
            "Submenu_CommandAA",
            "my.menu.root",
            SWT.PUSH);
    pAA.label = "Command AA";

    // create actual contribution items and add them to the given additions reference
    CommandContributionItem itemAA = new CommandContributionItem(pAA);
    itemAA.setVisible(true);
    additions.addContributionItem(itemAA, null);
}

然后,当我右键单击某个项目时,我收到此错误:

!MESSAGE Unable to create menu item "Submenu_CommandAA", command "my.menu.root" not defined

0 个答案:

没有答案