我有自定义的eclipse编辑器。由于特殊的原因,这个编辑器提供了两个工具栏区域,它们不是基于eclipse为编辑器提供的标准操作栏。这两个地方是专门为其他插件贡献的。我的意图是利用“org.eclipse.ui.menus”扩展点与自定义menuContribution/locationURI
,所以其他插件可以使用此扩展和相关toolbar:my.editor.toolbar1
和toolbar:my.editor.toolbar2
作为locationURI
。利用现有的org.eclipse.ui.menus扩展创建自己的工具栏
我的问题是如何“连接”我的工具栏与特定的位置。我尝试了以下方法,但结果不好。我创建自定义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();
“用户”的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"
一起?
我试图用这个代码,这是行不通的,因为这会从通话workbench.getService返回的WorkbenchMenuService的版本(IMenuService .class)有一个缺陷。缺点是方法populateContributionManager(toolbarManager,TOOLBAR_LOCATION)没有实现,并有一个// TODO消息。这个未实现的方法来自org.eclipse.ui.workbench_3.104.0.v20130204_164612.jar你是如何让你的代码工作的? – twindham 2013-03-01 21:01:48
此代码完美使用Indigo版本的Eclipse。但是到目前为止,这并不适用于Juno。 – 2013-04-17 19:09:51