我有eclipse的自定义编辑器 . 由于特殊原因,此编辑器提供了两个工具栏区域,这些区域不基于eclipse for editor提供的标准操作栏 . 这两个地方专门为其他插件做出贡献 . 我的意图是利用自定义 menuContribution/locationURI
的"org.eclipse.ui.menus"扩展点,以便其他插件可以使用此扩展并将 toolbar:my.editor.toolbar1
和 toolbar:my.editor.toolbar2
关联为 locationURI
.
我的问题是如何"connect"我的ToolBar具有特定的位置 . 我尝试了以下方法,但结果并不好 . 我创建了自定义 ToolbarContributionRoot
事件,如果我不应该创建 CustomContributionFactory
,它扩展 ExtensionContributionFactory
. 它工作得很好,但问题是下拉命令哪些子菜单无法正确解析 .
toolbarManager = new ToolBarManager(SWT.FLAT);
ToolbarContributionRoot toolbarRoot = new ToolbarContributionRoot(toolbarManager);
IServiceLocator workbench = PlatformUI.getWorkbench();
IConfigurationElement[] allMenuElements
= Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.ui.menus");
for (IConfigurationElement menuContribution : allMenuElements) {
String locationURI = menuContribution.getAttribute("locationURI");
if ("toolbar:my.editor.toolbar1".equals(locationURI)) {
try {
ExtensionContributionFactory factory = CustomContributionFactory.create(menuContribution);
factory.createContributionItems(workbench, toolbarRoot);
} catch (CoreException e) {
e.printStackTrace();
}
}
}
toolbar = toolbarManager.createControl(root);
GridData gridData = new GridData(GridData.FILL, GridData.FILL, false, false, 1, 1);
toolbar.setLayoutData(gridData);
toolbar.pack();
“user”的plugin.xml如下所示:
<extension point="org.eclipse.ui.menus" id="my.helper.id">
<menuContribution locationURI="toolbar:my.editor.toolbar1">
<command commandId="my.editor.special.command1" />...
您对如何将我的自定义工具栏和 "org.eclipse.ui.menus"
扩展名混合在一起有什么建议吗?
1 回答
正确的方法是: