Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Main menu persistence(Main menu is not saved in the workbench model file)
Main menu persistence [message #1849756] Tue, 01 February 2022 13:01 Go to next message
Nico Stibbe is currently offline Nico StibbeFriend
Messages: 4
Registered: February 2022
Junior Member
Hi all,

I'm having an issue with my eclipse rcp application. When I start the application the second time, the MainMenu of my MTrimmedWindow disappears. (This only happens, when I don't use the -clearPersistentState flag).
It is not an option to always use the -clearPersistentState flag.
I've noticed that the MainMenu is also not saved to the workbench.xmi file.
It seem like when closing the application the MainMenu object gets removed from the ApplicationModel before the workbench.xmi file is generated.

I've already found this issue (https://www.eclipse.org/forums/index.php/t/446433/) in the forum, which seems to be similar. But the proposed solution does not work for me.

I'm using the Eclipse version 4.21.0 and the org.eclipse.ui.workbench 3.122.100 plugin.

Any ideas how to store the main menu state?

Regards,
Nico
Re: Main menu persistence [message #1849780 is a reply to message #1849756] Wed, 02 February 2022 14:08 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 260
Registered: April 2012
Senior Member
How do you create the main menu, E4 model extensions, E3 API, extension points? Do you have a custom application.e4xmi in your RPC, or do you use the e4xmi definition as provided by platform IDE?
To prevent duplication from menu(item)s, menus added via legacy (e3) API are not persisted in the workbench.xmi anymore.
Re: Main menu persistence [message #1849783 is a reply to message #1849780] Wed, 02 February 2022 14:32 Go to previous messageGo to next message
Nico Stibbe is currently offline Nico StibbeFriend
Messages: 4
Registered: February 2022
Junior Member
Thank you for your fast answer.

The main menu is defined within the Application.e4xmi, which is located in the root of the plugin. But there are also other plugins within the project, who contribute sub menus to the main menu via extension points.

Here is how the menu is defined in the Application.e4xmi:
<?xml version="1.0" encoding="ASCII"?>
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xsi:schemaLocation="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic http://www.eclipse.org/ui/2010/UIModel/application#//ui/basic http://www.eclipse.org/ui/2010/UIModel/application/ui/menu http://www.eclipse.org/ui/2010/UIModel/application#//ui/menu" xmi:id="org.eclipse.e4.legacy.ide.application" elementId="org.eclipse.e4.legacy.ide.application" bindingContexts="_SeXUHO8EEd6BC9cDb6iV7y">
  <children xsi:type="basic:TrimmedWindow" xmi:id="_Ml43cKdbEeuszM-J4Kiyww" elementId="IDEWindow" bindingContexts="_SeXUEO8EEd6FC9cDb6iV7w" width="1200" height="800">
    <mainMenu xmi:id="_C36m0Kv8EeuszM-J4Kiyww" elementId="org.eclipse.ui.main.menu">
      <children xsi:type="menu:Menu" xmi:id="__s94UKv8EeuszM-J4Kiyww" elementId="com.example.menuitem.file" label="File">
        <children xsi:type="menu:HandledMenuItem" xmi:id="_bbtBgG2WEeeUUtkVfsNulA" elementId="com.example.handledmenuitem.file.save" command="_t1WL8Kv7EeuszM-J4Kiyww"/>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_YGn8EG2WEeeUUtkVfsNulA" elementId="com.example.handledmenuitem.file.saveAll" command="_t1k1cKv7EeuszM-J4Kiyww"/>
        <children xsi:type="menu:MenuSeparator" xmi:id="_4q5R0Kv-EeuszM-J4Kiyww" elementId="com.example.menuseparator.1"/>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_k4yZQKv-EeuszM-J4Kiyww" elementId="com.example.handledmenuitem.file.exit" command="_t1y34Kv7EeuszM-J4Kiyww"/>
      </children>
      <children xsi:type="menu:Menu" xmi:id="_DxT3gKv9EeuszM-J4Kiyww" elementId="com.example.menuitem.edit" label="Edit">
        <children xsi:type="menu:HandledMenuItem" xmi:id="_8NH6EEtxEee6tKpYxJ0E8A" elementId="com.example.handledmenuitem.edit.copy" command="_t2CvgKv7EeuszM-J4Kiyww"/>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_9ZMroEtxEee6tKpYxJ0E8A" elementId="com.example.handledmenuitem.edit.paste" command="_t2RZAKv7EeuszM-J4Kiyww"/>
        <children xsi:type="menu:MenuSeparator" xmi:id="_2GkT4Kv-EeuszM-J4Kiyww" elementId="com.example.menuseparator.edit1"/>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_qSb0QHOAEeegQLXWqmsvSQ" elementId="com.example.handledmenuitem.edit.delete" command="_t2hQoKv7EeuszM-J4Kiyww"/>
      </children>
      <children xsi:type="menu:Menu" xmi:id="_ZpsxAKwGEeuszM-J4Kiyww" elementId="com.example.menuitem.run" label="Run"/>
      <children xsi:type="menu:Menu" xmi:id="_FH1lkKv9EeuszM-J4Kiyww" elementId="com.example.menuitem.view" label="View">
        <children xsi:type="menu:HandledMenuItem" xmi:id="_65JUQElaEei_tesvQcOXmA" elementId="com.example.handledmenuitem.showView" command="_t3s8YKv7EeuszM-J4Kiyww"/>
        <children xsi:type="menu:MenuSeparator" xmi:id="_lizKIKv_EeuszM-J4Kiyww" elementId="com.example.menuseparator.0"/>
        <children xsi:type="menu:Menu" xmi:id="_xgt_4HOAEeegQLXWqmsvSQ" elementId="com.example.menu.perspective" label="Perspective">
          <children xsi:type="menu:HandledMenuItem" xmi:id="_zl3HcHOAEeegQLXWqmsvSQ" elementId="com.example.handledmenuitem.showPerspective" command="_t4KPYKv7EeuszM-J4Kiyww"/>
          <children xsi:type="menu:MenuSeparator" xmi:id="_rj4i0Kv_EeuszM-J4Kiyww" elementId="com.example.menuseparator.2"/>
          <children xsi:type="menu:HandledMenuItem" xmi:id="_23rdgHOAEeegQLXWqmsvSQ" elementId="com.example.handledmenuitem.savePerspective" command="__D9NAKv7EeuszM-J4Kiyww"/>
          <children xsi:type="menu:HandledMenuItem" xmi:id="_35NzAHOAEeegQLXWqmsvSQ" elementId="com.example.handledmenuitem.closePerspective" command="_t3dEwKv7EeuszM-J4Kiyww"/>
          <children xsi:type="menu:HandledMenuItem" xmi:id="_6ZvPAHOAEeegQLXWqmsvSQ" elementId="com.example.handledmenuitem.resetPerspective" command="__DpD8Kv7EeuszM-J4Kiyww"/>
        </children>
        <children xsi:type="menu:MenuSeparator" xmi:id="_4RXiEKv_EeuszM-J4Kiyww" elementId="com.example.menuseparator.3"/>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_MnHy4G2WEeeUUtkVfsNulA" elementId="com.example.handledmenuitem.preferences" command="__DR3kKv7EeuszM-J4Kiyww"/>
      </children>
      <children xsi:type="menu:Menu" xmi:id="_G197UKv9EeuszM-J4Kiyww" elementId="com.example.menuitem.help" label="Help">
        <children xsi:type="menu:HandledMenuItem" xmi:id="_cFO6IEt9Eee6tKpYxJ0E8A" elementId="com.example.handledmenuitem.help.contents" command="_typdQKv7EeuszM-J4Kiyww"/>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_FG1RQG2WEeeUUtkVfsNulA" elementId="com.example.handledmenuitem.help.search" command="_t04R4Kv7EeuszM-J4Kiyww"/>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_KvaDUG2WEeeUUtkVfsNulA" elementId="com.example.handledmenuitem.help.context" command="_6WxFIKv7EeuszM-J4Kiyww"/>
        <children xsi:type="menu:MenuSeparator" xmi:id="_CLMt8KwAEeuszM-J4Kiyww" elementId="com.example.menuseparator.4"/>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_ajR_MEt9Eee6tKpYxJ0E8A" elementId="com.example.handledmenuitem.help.about" command="_t1GUUKv7EeuszM-J4Kiyww"/>
      </children>
    </mainMenu>
...
Re: Main menu persistence [message #1849789 is a reply to message #1849783] Wed, 02 February 2022 16:01 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 260
Registered: April 2012
Senior Member
This is a bug in the framework, when the workbench window is closed the main menu is removed.

In WorkbenchWindow#windowWidgetHandler the menu is removed from the window when the widget of the menu is disposed, this should never be done here. Seems to be a regression from Bug 315270, https://bugs.eclipse.org/bugs/show_bug.cgi?id=315270#c25, to prevent duplication of the main menu when eclipse crashes. By now, other mechanisms are in place, and this workaround can be removed.

Please open a bug report for Platfom UI on https://bugs.eclipse.org
Re: Main menu persistence [message #1849798 is a reply to message #1849789] Thu, 03 February 2022 08:01 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 260
Registered: April 2012
Senior Member
Maybe as a workaround, if you use a model snippet with the main menu then you can register it to be added to the model if it does not exist. (Though there are some bugs with snippets too, so mileage might vary).
Re: Main menu persistence [message #1849817 is a reply to message #1849798] Thu, 03 February 2022 14:49 Go to previous messageGo to next message
Nico Stibbe is currently offline Nico StibbeFriend
Messages: 4
Registered: February 2022
Junior Member
Sorry I don't know what you mean with model snippet.

I have tried to add the main menu again by a processor attached to the org.eclipse.e4.workbench.model extension.

It looked like this:
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);
    }
}

(Source: https://stackoverflow.com/questions/27074031/menu-bar-not-displaying-in-eclipse-e4-on-restore-state)

But mainMenu would keep emtpy / has no child elements.

What are model snippets and how do i use them?
Re: Main menu persistence [message #1849818 is a reply to message #1849817] Thu, 03 February 2022 15:00 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 260
Registered: April 2012
Senior Member
Your processer will indeed only create a main menu, but it will not add the child elements as defined in your model. You could add them programmatically as well.

The other options is model-fragments (not snippets):
https://www.vogella.com/tutorials/EclipseRCP/article.html#exercise-contributing-a-part-descriptor-via-model-fragments
https://wiki.eclipse.org/Eclipse4/RCP/Modeled_UI/Contributing_to_the_Model

With a fragment you should be able to move the menu from the main module to the fragment, and then let it be inserted on startup.
Re: Main menu persistence [message #1849826 is a reply to message #1849818] Thu, 03 February 2022 16:30 Go to previous message
Nico Stibbe is currently offline Nico StibbeFriend
Messages: 4
Registered: February 2022
Junior Member
OK I went for the second option and it worked.

I created an additional fragment.e4xmi in the root of the plugin and copied all menu items from the main Application.e4xmi to the fragment.e4xmi.

On the plugin.xml i added the following extension point:
   <extension
         id="com.example.fragment"
         point="org.eclipse.e4.workbench.model">
      <fragment
            apply="always"
            uri="fragment.e4xmi">
      </fragment>
   </extension>


Then i started the application via the product page and it to seem working fine now.

@Rolf Theunissen - Thank you very much for your support!
Previous Topic:Eclipse Toolbar crashes due to CSS
Next Topic:Detached editor "toolbar" corrupt after its window closed
Goto Forum:
  


Current Time: Fri Apr 19 23:06:46 GMT 2024

Powered by FUDForum. Page generated in 0.03285 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top