【发布时间】:2011-12-22 09:53:45
【问题描述】:
我有 Eclipse 的自定义编辑器。由于特殊原因,此编辑器提供了两个工具栏区域,它们不是基于 eclipse 为编辑器提供的标准操作栏。这两个地方是专门供其他插件贡献的。我的意图是利用带有自定义menuContribution/locationURI 的“org.eclipse.ui.menus”扩展点,以便其他插件可以使用此扩展并关联toolbar:my.editor.toolbar1 和toolbar:my.editor.toolbar2 作为locationURI。
我的问题是如何将我的工具栏与特定位置“连接”。我尝试了以下方法,但结果并不好。如果我不应该创建自定义ToolbarContributionRoot 事件,我还创建了扩展ExtensionContributionFactory 的CustomContributionFactory。它工作得很好,但问题在于子菜单没有正确解决的下拉命令。
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();
“用户”的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" 扩展名混合在一起有什么建议吗?
【问题讨论】: