How to programmatically add menus to the main menu bar? [message #1786257] |
Sat, 28 April 2018 00:15 |
PK Mising name Messages: 44 Registered: July 2009 |
Member |
|
|
Hello,
I am creating parts from a PartDescriptor defined in the e4xmi file. After the creation of the part, I want to add menus under a menu called "Mine" which I have added to the "Window" in the main menu bar. The menus show up correctly under "Mine". The goal is to create menus that when clicked will take the user to the part.
However, clicking on the menu does not invoke the handler? Why is this? Basically I want all new parts to be available under a menu in the menubar. When a part is added a new menu should be added. Selecting the menu will activate the part.
The following is the code I am using:
// Create the command
MCommand command = (MCommand) modelService
.findElements(app, "commandid", MCommand.class, null)
.get(0);
// Find the menu to which the programmatically created menu item will be added
MMenu menu = (MMenu) modelService.find("Mine", window.getMainMenu());
// Create the menu item
MHandledMenuItem dynamicItem = modelService.createModelElement(MHandledMenuItem.class);
dynamicItem.setLabel("my_id");
dynamicItem.setContributorURI(
"bundleclass://plugin.blah/MyHandler");
// Create the menu parameters
MParameter commandParam = modelService.createModelElement(MParameter.class);
commandParam.setName("my_id");
commandParam.setElementId("commandParam");
commandParam.setValue("my_id");
// Set the command parameters
dynamicItem.getParameters().add(commandParam);
// Set the command
dynamicItem.setCommand(command);
// Add the menu to the menu item
menu.getChildren().add(dynamicItem);
I see this warning in the log:
!MESSAGE Unable to generate parameterized command for org.eclipse.e4.ui.model.application.ui.menu.impl.HandledMenuItemImpl@24068086 (elementId: null, tags: null, contributorURI: bundleclass://plugin.blah/MyHandler) (widget: null, renderer: org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer@664db2ca, toBeRendered: true, onTop: false, visible: true, containerData: null, accessibilityPhrase: null) (label: My_id, iconURI: null, tooltip: null, enabled: true, selected: false, type: Push) (mnemonics: null) (wbCommand: null) with {My_id=124}
[Updated on: Sat, 28 April 2018 02:49] Report message to a moderator
|
|
|
|
Re: How to programmatically add menus to the main menu bar? [message #1786292 is a reply to message #1786257] |
Mon, 30 April 2018 02:20 |
Eclipse User |
|
|
|
It's weird, but a parameter's name in a command-reference is the command-parameter's ID in the command-definition.
// Create the menu parameters
MParameter commandParam = modelService.createModelElement(MParameter.class);
commandParam.setName("my_id");
commandParam.setElementId("commandParam");
commandParam.setValue("my_id");
|
|
|
|
Powered by
FUDForum. Page generated in 0.03024 seconds