我有两个视图View1和View2 set1工具栏项对于两个视图都是通用的,而set2工具栏项应该只在view2中与set1一起显示。
我正在使用eclipse的菜单贡献功能。我创建了两个位置URI toolbar:com.omg.views.Objects.custom - >有共同的项目 toolbar:com.omg.views.Objects.custom1 - >这仅适用于View2。
我试过以下:
CoolBar coolBar = new CoolBar(toolBarComposite, SWT.NONE);
GridData gridData1 = new GridData(GridData.FILL_BOTH);
coolBar.setLayoutData(gridData1);
CoolBarManager coolManager = new CoolBarManager(SWT.DEFAULT);
IMenuService menuService = (IMenuService)
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getService(IMenuService.class);
manager = new ToolBarManager(SWT.FLAT);
menuService.populateContributionManager(manager,
"toolbar:com.omg.views.Objects.custom"); //$NON-NLS-1$
manager.createControl(coolBar);
manager.getControl().setLayoutData(new GridData(SWT.END, SWT.CENTER,
true, false));
manager1 = new ToolBarManager(SWT.FLAT);
menuService.populateContributionManager(manager1,
"toolbar:com.omg.views.Objects.custom1"); //$NON-NLS-1$
manager1.createControl(coolBar);
manager1.getControl().setLayoutData(new GridData(SWT.END,
SWT.CENTER, true, false));
coolManager.add(manager);
coolManager.add(manager1);
coolManager.createControl(toolBarComposite);
coolManager.getControl().setLayoutData(new GridData(SWT.END,
SWT.CENTER, true, false));
不幸的是,上面的代码对我来说不起作用,如果我得到一些建议会很好。