How to programmatically add menus to the main menu bar? [message #1786257] |
Fri, 27 April 2018 20:15  |
Eclipse User |
|
|
|
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: Fri, 27 April 2018 22:49] by Moderator
|
|
|
|
|
Re: How to programmatically add menus to the main menu bar? [message #1786331 is a reply to message #1786292] |
Tue, 01 May 2018 08:17  |
Eclipse User |
|
|
|
Sorry about the mistake in the code. I made that mistake while cleaning up the code for the posting. I figured out that a HandledMenuItem has a command and a wbCommand. The wbCommand needs to be populated correctly in order for a menu to successfully execute a parametrized command. I could not successfully create a wbCommand that worked...ran into private classes and lack of simple constructors. I gave up on this idea.
Thanks for trying to help.
|
|
|
Powered by
FUDForum. Page generated in 0.05902 seconds