【问题标题】:How to add right click menu in eclipse plugin programmatically如何以编程方式在eclipse插件中添加右键菜单
【发布时间】:2013-07-14 05:36:54
【问题描述】:

我有一个带有 View 部分的 Eclipse 插件。在此视图部分中,我有一个表,当用户右键单击该表中的一行时,我想添加一个子菜单。如何以编程方式执行此操作?

我已经在我的 plugin.xml 中定义了 command 和 menuContribution:

<extension
     point="org.eclipse.ui.menus">
   <menuContribution
        allPopups="true"
        class="com.sintec.eclipseplugins.clippy.menu.DeleteMenuContribution"
        locationURI="menu:delete?after=additions">
   </menuContribution>
</extension>

我还创建了扩展 ExtensionContributionFactory 的贡献类:

public class DeleteMenuContribution extends ExtensionContributionFactory {

@Override
public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
    // build a couple of command-based contribution parameters
    CommandContributionItemParameter pAA = new CommandContributionItemParameter(
        serviceLocator,
        "DeleteCommand",
        "com.sintec.eclipseplugins.clippy.delete",
        SWT.PUSH);
    pAA.label = "Delete Command";

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

}

}

Aaaand 最后但并非最不重要的一点是,我的 ViewPart 中有这段代码,我想在其中将菜单添加到表格中:

IMenuManager mgr = new MenuManager().findMenuUsingPath("menu:delete?after=additions");
MenuManager mgr2 = new MenuManager();
mgr2.add(mgr);
tableViewer.getTable().setMenu(mgr2.createContextMenu(tableViewer.getTable()));

问题是找不到菜单。我很确定我遗漏了什么……菜单 URI 是否正确?

【问题讨论】:

    标签: java eclipse-plugin


    【解决方案1】:

    我有点想尝试一下……但是为什么不给菜单分配一个 id 并在 MenuManager 中使用find(id) 方法呢?

    【讨论】:

    • 因为我使用的教程建议使用 findMenuUsingPath() 方法。 ;D 我是 RCP 框架的新手,仍在试图弄清楚事情是如何工作的。谢谢你的建议。我会在我的计算机启动并再次运行时尝试它。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-07
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多