How do I get the menu
instance in the answer given in the following question?
Asked
Active
Viewed 341 times
0
1 Answers
1
Use the EModelService
to find the menu by its id.
@Inject
EModelService modelService;
List<MMenu> list = modelService.findElements(app, "menu id", MMenu.class,
Collections.emptyList(), EModelService.IN_MAIN_MENU);
You must use the findElements
call with the EModelService.IN_MAIN_MENU
flag to search the menus.

greg-449
- 109,219
- 232
- 102
- 145
-
Unfortunately the `modelService.find("menu id", application);` returns null in my `@AboutToShow` method. Do you know why? – Jehan Zeb Jul 29 '15 at 14:55
-
In @AboutToShow you can get the menu elements list as a parameter - added this to answer – greg-449 Jul 29 '15 at 15:04
-
Yes, but this list is always empty, as also mentioned [here](https://wiki.eclipse.org/Eclipse4/RCP/Dependency_Injection#.40AboutToShow.2C_.40AboutToHide_.28org.eclipse.e4.ui.di.29) – Jehan Zeb Jul 29 '15 at 15:07
-
1Sorry, researching this a bit more the normal find does not work for menus, you have to use findElements with a flag. Updated the answer – greg-449 Jul 29 '15 at 15:30