我有一个带有View部分的eclipse插件 . 在这个View部分中,我有一个表,当用户右键单击该表中的一行时,我想添加一个子菜单 . 我怎么能以编程方式执行此操作?
我在plugin.xml中定义了命令和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是否正确?
1 回答
我'm kind of taking a stab at this ... but why don' t您为菜单分配了一个id并使用MenuManager中的find(id)方法?