0

How do I get the menu instance in the answer given in the following question?

Existing Question

Community
  • 1
  • 1
Jehan Zeb
  • 155
  • 12

1 Answers1

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
  • 1
    Sorry, 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