Dynamic MenuContribution not working [message #1698232] |
Fri, 12 June 2015 11:39 |
Jürgen Weinberger Messages: 42 Registered: August 2012 |
Member |
|
|
Hi! I tried to implement a perspective switcher via a dynamic menu. It works so far that the perspectives are shown in the menu, with the actual one checked. The only problem is that the command/handler is never called when i click on an item. The command though seems fine because when i add a static menu item to the model via xmi and click it, it works.
I played arround a little and found out that in the HandledContributionItem.Listener the select event-type is never called only the dispose-type. While when i do the same with the static menu item only the select-type is called and never the dispose-type.
So imho i think this could be a bug, take a look at my source, i'm not quite sure i've got the creation of the handledmenuitem right.
Code:
public class PerspectivesMenuContribution {
private static final String OPEN_PERSPECTIVE_CMD_ID = "application.command.perspective.open";
@Inject
private EModelService modelService;
@Inject
private MWindow window;
@Inject
private MApplication application;
@AboutToShow
public void aboutToShow(List<MMenuElement> items) {
MPerspective activePerspective = modelService.getActivePerspective(window);
List<MPerspective> perspectives = modelService.findElements(application, MPerspective.class, EModelService.ANYWHERE, x -> {
return x instanceof MPerspective;
});
for(MPerspective perspective : perspectives) {
MHandledMenuItem menuItem = modelService.createModelElement(MHandledMenuItem.class);
menuItem.setElementId("menuitem.perspective."+perspective.getElementId());
menuItem.setLabel(perspective.getLabel());
menuItem.setSelected(activePerspective.equals(perspective));
menuItem.setType(ItemType.CHECK);
menuItem.setContributorURI("platform:/plugin/application");
menuItem.setEnabled(true);
MCommand command = modelService.findElements(application, OPEN_PERSPECTIVE_CMD_ID, MCommand.class, null).get(0);
menuItem.setCommand(command);
items.add(menuItem);
}
}
}
Any help would be appreceated and thanks in advance!
best regards weinma
|
|
|
|
Powered by
FUDForum. Page generated in 0.01919 seconds