我正在尝试通过在Eclipse Oxygen IDE实例中运行的org.eclipse.e4.ui.workbench.IWorkbench
动态添加菜单项和菜单项(即具有3.x传统/兼容层的内容)。我对以下为什么不起作用感到困惑:
MApplication app = /*org.eclipse.e4.ui.workbench.IWorkbench*/ workbench.getApplication();
assert app.getElementId().equals("org.eclipse.e4.legacy.ide.application");
assert app.getChildren().get(0).getElementId().equals("org.eclipse.ui.main.menu");
// MMenuContribution menuContribution = MMenuFactory.INSTANCE.createMenuContribution();
IEclipseContext context = app.getContext();
EModelService modelService = context.get(EModelService.class);
MMenuContribution menuContribution = modelService.createModelElement(MMenuContribution.class);
menuContribution.setElementId("some.menucontribution.0");
menuContribution.setPositionInParent("after=additions");
menuContribution.setParentId("popup");
menuContribution.getTags().add("scheme:popup");
menuContribution.getTags().add("menuContribution:popup");
menuContribution.setToBeRendered(true);
// MMenu menu = MMenuFactory.INSTANCE.createMenu();
MMenu menu = modelService.createModelElement(MMenu.class);
menu.setElementId("some.menu.0");
menu.setVisible(true);
menu.setLabel("Some Menu");
menu.getTags().add("menuContribution:popup");
menu.setToBeRendered(true);
menuContribution.getChildren().add(menu);
app.getMenuContributions().add(menuContribution);
有没有办法通过IWorkbench
实例以某种方式在运行时修改遗留应用程序的菜单(上下文或主菜单)?