Search code examples
javaeclipsercpe4

e4 RCP how to programmatically edit main menu


I would like to modify main menu items in my code, not in e4xmi. How can I do this?

I have two "handled menu item" type "radio" in Main menu (no in part menu). I want to check which is active. I also want to programmatically change active item.


Solution

  • The MMenuItem represents a menu item. It has isSelected() and setSelection(boolean) methods for testing and setting the menu item selection.

    You can find a MMenuItem using the model service:

    @Inject
    EModelService modelService;
    
    @Inject
    MApplication app;
    
    List<MMenuItem> menuList = modelService.findElements(app, "menu item id", MMenuItem.class, null, EModelService.IN_MAIN_MENU);
    
    MMenuItem menuItem = menuList.get(0);
    

    In handlers you can just inject the current MMenuItem directly in the @Execute method.