| ContributionFactories are used by the IMenuService to populate
ContributionManagers. In
AbstractContributionFactory.createContributionItems(IServiceLocator,IContributionRoot) you fill in the additions List with
IContributionItem to be inserted at this
factory's location. For example:
AbstractContributionFactory contributions = new AbstractContributionFactory(
"menu:org.eclipse.ui.tests.api.MenuTestHarness?after=additions") {
public void createContributionItems(IMenuService menuService, List additions) {
CommandContributionItem item = new CommandContributionItem(
"org.eclipse.ui.tests.menus.helloWorld",
"org.eclipse.ui.tests.commands.enabledHelloWorld", null, null,
"Say Hello", null);
additions.add(item);
item = new CommandContributionItem(
"org.eclipse.ui.tests.menus.refresh",
"org.eclipse.ui.tests.commands.refreshView", null, null,
"Refresh", null);
menuService.registerVisibleWhen(item, new MyActiveContextExpression(
"org.eclipse.ui.tests.myview.context"));
additions.add(item);
}
public void releaseContributionItems(IMenuService menuService, List items) {
// we have nothing to do
}
};
IMenuService service = (IMenuService) PlatformUI.getWorkbench().getService(
IMenuService.class);
service.addContributionFactory(contributions);
Only the abstract methods may be implemented.
since: 3.3 See Also: org.eclipse.ui.menus.IMenuService See Also: org.eclipse.jface.action.MenuManager See Also: org.eclipse.jface.action.ToolBarManager |