利用现有的org.eclipse.ui.menus扩展创建自己的工具栏
我有eclipse的自定义编辑器。由于特殊原因,此编辑器提供了两个工具栏区域,它们不是基于eclipse For editor提供的标准操作栏。这两个地方是专门为其他插件作出贡献的。我的意图是利用“org.eclipse.ui.menus”扩展点和自定义利用现有的org.eclipse.ui.menus扩展创建自己的工具栏,eclipse,eclipse-plugin,Eclipse,Eclipse Plugin,我有eclipse的自定义编辑器。由于特殊原因,此编辑器提供了两个工具栏区域,它们不是基于eclipse For editor提供的标准操作栏。这两个地方是专门为其他插件作出贡献的。我的意图是利用“org.eclipse.ui.menus”扩展点和自定义menuContribution/locationURI,以便其他插件可以使用此扩展和相关的toolbar:My.editor.toolbar1和toolbar:My.editor.toolbar2作为locationURI来做出贡献 我的问题是
menuContribution/locationURI
,以便其他插件可以使用此扩展和相关的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();
“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.menu“扩展混合在一起有什么建议吗?正确的方法是:
toolbarManager = new ToolBarManager(SWT.FLAT);
IServiceLocator workbench = PlatformUI.getWorkbench();
IMenuService menuService = (IMenuService) workbench.getService(IMenuService.class);
menuService.populateContributionManager(toolbarManager, TOOLBAR_LOCATION);
toolbar = toolbarManager.createControl(root);
正确的方法是:
toolbarManager = new ToolBarManager(SWT.FLAT);
IServiceLocator workbench = PlatformUI.getWorkbench();
IMenuService menuService = (IMenuService) workbench.getService(IMenuService.class);
menuService.populateContributionManager(toolbarManager, TOOLBAR_LOCATION);
toolbar = toolbarManager.createControl(root);
我正在尝试使用此代码,但它不起作用,因为从call workbench.getService(IMenuService.class)返回的WorkbenchmentUservice版本存在缺陷。该漏洞在于未实现方法populateContributionManager(TOOLBAR Manager,TOOLBAR_LOCATION),并且其中包含//TODO消息。这个未实现的方法来自org.eclipse.ui.workbench_3.104.0.v20130204_164612.jar您是如何让代码工作的?使用eclipse的Indigo版本,此代码可以完美地工作。但是到目前为止,Juno不起作用。我正在尝试使用此代码,但它不起作用,因为从call workbench.getService(IMenuService.class)返回的WorkbenchmentUservice版本存在缺陷。该漏洞在于未实现方法populateContributionManager(TOOLBAR Manager,TOOLBAR_LOCATION),并且其中包含//TODO消息。这个未实现的方法来自org.eclipse.ui.workbench_3.104.0.v20130204_164612.jar您是如何让代码工作的?使用eclipse的Indigo版本,此代码可以完美地工作。但到目前为止,朱诺还没有成功。