Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Menu bar not displaying in eclipse e4 on restore state

I am creating an RCP application using Eclipse 4.4.1 with the Compatibility Layer (migration from 3.x to 4.x). I have defined menus in the application model. Menus are displaying properly when the application is launched for the first time, but restarting the application is hiding the menu bar completely and only showing the toolbar.

Why might no menus be displaying when the RCP Application is restored?

like image 385
Gaurav Avatar asked Nov 09 '22 22:11

Gaurav


1 Answers

This sounds like this bug here that I just recently myself encountered:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=388808

Personally, the workaround in the bug report did not exactly work for me (it may for you however). What did work for me was based off of the final post here by Karl Puperze, (slightly modified):

https://www.eclipse.org/forums/index.php/t/446433/

public class ForceMainMenuProcessor 
{
    @Execute
    public void execute(@Optional MApplication application, @Optional EModelService modelService) 
    {
        MTrimmedWindow window = (MTrimmedWindow) 
            modelService.find("<id of your main trimmed window>", application);

        if (window == null || window.getMainMenu() != null) 
            { return; }

        final MMenu mainMenu = modelService.createModelElement(MMenu.class);
        mainMenu.setElementId("org.eclipse.ui.main.menu");

        window.setMainMenu(mainMenu);
    }
}

From that, the last steps were to make sure I defined (with no content) a menu in the main e4xmi file that had the org.eclipse.ui.main.menu id, then defined a fragment that contained the menu contents.

To the plugin.xml, added to the org.eclipse.e4.workbench.model extension point a fragment that pointed to the .e4xmi model fragment that was just created and set the 'apply' to always.

Finally, to the same extension point, added a processor and pointed it to the class above. beforefragment was true and apply was always.

The e4xmi files were still used to define the menu, but in code, because of the defined processor above, the menu is forced to appear regardless of whatever persistent state was saved in the workspace. I ended up with this solution after already splitting the menu into a separate model fragment, so I am not sure if that part of the solution is definitely required, but most certainly defining the processor is.

like image 84
Erika Redmark Avatar answered Nov 14 '22 22:11

Erika Redmark