I have a simple Eclipse 4 RCP application. The parameter "-clearPersistedState" is explicitly not used to make the window have its size and position restored on a later startup. The problem is that the model persisted to ".metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi" contains the whole application state. when I extend the application's model in a later version by e.g. adding a new menu entry and an associated command, these additions are just ignored if a persisted is found. Using "-deltaRestore" doesn't work either.
How can I ensure that specific parts of the application are always rendered how they are defined in the application model instead of restoring their state from "workbench.xmi"? Is it alternatively possible to just persist/restore the window's size and position?
The initial model:
<?xml version="1.0" encoding="UTF-8"?>
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:advanced="http://www.eclipse.org/ui/2010/UIModel/application/ui/advanced" 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" xmi:id="_6wlLcMgZEeSyMNYR5xypkQ" elementId="RCPTest.application" bindingContexts="_6wlLecgZEeSyMNYR5xypkQ">
<children xsi:type="basic:TrimmedWindow" xmi:id="_6wlLccgZEeSyMNYR5xypkQ" elementId="RCPTest.window.main" label="Eclipse 4 RCP Application" width="500" height="400">
<children xsi:type="advanced:PerspectiveStack" xmi:id="_6wlLkMgZEeSyMNYR5xypkQ" elementId="org.eclipse.ui.ide.perspectivestack">
<children xsi:type="advanced:Perspective" xmi:id="_6wlLkcgZEeSyMNYR5xypkQ" elementId="RCPTest.perspective.sample">
<children xsi:type="basic:PartSashContainer" xmi:id="_6wlLksgZEeSyMNYR5xypkQ" elementId="RCPTest.partsashcontainer.sample">
<children xsi:type="basic:PartStack" xmi:id="_6wlLk8gZEeSyMNYR5xypkQ" elementId="RCPTest.partstack.sample">
<children xsi:type="basic:Part" xmi:id="_6wlLlMgZEeSyMNYR5xypkQ" elementId="RCPTest.part.sample" contributionURI="bundleclass://RCPTest/rcptest.parts.SamplePart" label="Sample Part"/>
</children>
</children>
</children>
</children>
<mainMenu xmi:id="_6wlLicgZEeSyMNYR5xypkQ" elementId="org.eclipse.ui.main.menu">
<children xsi:type="menu:Menu" xmi:id="_6wlLisgZEeSyMNYR5xypkQ" elementId="file" label="File">
<children xsi:type="menu:HandledMenuItem" xmi:id="_6wlLjcgZEeSyMNYR5xypkQ" elementId="RCPTest.handleditem.quit" label="Quit" command="_6wlLfMgZEeSyMNYR5xypkQ"/>
</children>
<children xsi:type="menu:Menu" xmi:id="_6wlLjsgZEeSyMNYR5xypkQ" elementId="help" label="Help"/>
</mainMenu>
</children>
<handlers xmi:id="_6wlLfcgZEeSyMNYR5xypkQ" elementId="rcptest.handler.quitCommand" contributionURI="bundleclass://RCPTest/rcptest.handlers.QuitHandler" command="_6wlLfMgZEeSyMNYR5xypkQ"/>
<bindingTables xmi:id="_6wlLfsgZEeSyMNYR5xypkQ" elementId="RCPTest.bindingtable" bindingContext="_6wlLecgZEeSyMNYR5xypkQ">
<bindings xmi:id="_6wlLf8gZEeSyMNYR5xypkQ" elementId="RCPTest.keybinding.m1q" keySequence="M1+Q" command="_6wlLfMgZEeSyMNYR5xypkQ"/>
</bindingTables>
<rootContext xmi:id="_6wlLecgZEeSyMNYR5xypkQ" elementId="org.eclipse.ui.contexts.dialogAndWindow" name="In Dialog and Windows">
<children xmi:id="_6wlLesgZEeSyMNYR5xypkQ" elementId="org.eclipse.ui.contexts.window" name="In Windows"/>
<children xmi:id="_6wlLe8gZEeSyMNYR5xypkQ" elementId="org.eclipse.ui.contexts.dialog" name="In Dialogs"/>
</rootContext>
<commands xmi:id="_6wlLfMgZEeSyMNYR5xypkQ" elementId="org.eclipse.ui.file.exit" commandName="quitCommand"/>
<addons xmi:id="_6wlLcsgZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
<addons xmi:id="_6wlLc8gZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
<addons xmi:id="_6wlLdMgZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/>
<addons xmi:id="_6wlLdcgZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.workbench.commands.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon"/>
<addons xmi:id="_6wlLdsgZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.workbench.handler.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>
<addons xmi:id="_6wlLd8gZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/>
<addons xmi:id="_6wlLeMgZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.workbench.bindings.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon"/>
</application:Application>
The "workbench.xmi" persisted with this version:
<?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:advanced="http://www.eclipse.org/ui/2010/UIModel/application/ui/advanced" 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" xmi:id="_KdFcsQlbEee-eMrs46logg" elementId="RCPTest.application" contributorURI="platform:/plugin/RCPTest" selectedElement="_KdFcsglbEee-eMrs46logg" bindingContexts="_KdFcvwlbEee-eMrs46logg">
<children xsi:type="basic:TrimmedWindow" xmi:id="_KdFcsglbEee-eMrs46logg" elementId="RCPTest.window.main" contributorURI="platform:/plugin/RCPTest" selectedElement="_KdFcswlbEee-eMrs46logg" label="Eclipse 4 RCP Application" x="223" y="217" width="1318" height="610">
<tags>topLevel</tags>
<children xsi:type="advanced:PerspectiveStack" xmi:id="_KdFcswlbEee-eMrs46logg" elementId="org.eclipse.ui.ide.perspectivestack" contributorURI="platform:/plugin/RCPTest" selectedElement="_KdFctAlbEee-eMrs46logg">
<children xsi:type="advanced:Perspective" xmi:id="_KdFctAlbEee-eMrs46logg" elementId="RCPTest.perspective.sample" contributorURI="platform:/plugin/RCPTest" selectedElement="_KdFctQlbEee-eMrs46logg">
<children xsi:type="basic:PartSashContainer" xmi:id="_KdFctQlbEee-eMrs46logg" elementId="RCPTest.partsashcontainer.sample" contributorURI="platform:/plugin/RCPTest" selectedElement="_KdFctglbEee-eMrs46logg">
<children xsi:type="basic:PartStack" xmi:id="_KdFctglbEee-eMrs46logg" elementId="RCPTest.partstack.sample" contributorURI="platform:/plugin/RCPTest" containerData="5000" selectedElement="_KdFctwlbEee-eMrs46logg">
<tags>active</tags>
<children xsi:type="basic:Part" xmi:id="_KdFctwlbEee-eMrs46logg" elementId="RCPTest.part.sample" contributorURI="platform:/plugin/RCPTest" contributionURI="bundleclass://RCPTest/rcptest.parts.SamplePart" label="Sample Part">
<tags>active</tags>
</children>
</children>
</children>
</children>
</children>
<mainMenu xmi:id="_KdFcuAlbEee-eMrs46logg" elementId="org.eclipse.ui.main.menu" contributorURI="platform:/plugin/RCPTest">
<children xsi:type="menu:Menu" xmi:id="_KdFcuQlbEee-eMrs46logg" elementId="file" contributorURI="platform:/plugin/RCPTest" label="File">
<children xsi:type="menu:HandledMenuItem" xmi:id="_KdFcuglbEee-eMrs46logg" elementId="RCPTest.handleditem.quit" contributorURI="platform:/plugin/RCPTest" label="Quit" command="_KdFcwglbEee-eMrs46logg"/>
</children>
<children xsi:type="menu:Menu" xmi:id="_KdFcuwlbEee-eMrs46logg" elementId="help" contributorURI="platform:/plugin/RCPTest" label="Help"/>
</mainMenu>
</children>
<handlers xmi:id="_KdFcvAlbEee-eMrs46logg" elementId="rcptest.handler.quitCommand" contributorURI="platform:/plugin/RCPTest" contributionURI="bundleclass://RCPTest/rcptest.handlers.QuitHandler" command="_KdFcwglbEee-eMrs46logg"/>
<bindingTables xmi:id="_KdFcvQlbEee-eMrs46logg" elementId="RCPTest.bindingtable" contributorURI="platform:/plugin/RCPTest" bindingContext="_KdFcvwlbEee-eMrs46logg">
<bindings xmi:id="_KdFcvglbEee-eMrs46logg" elementId="RCPTest.keybinding.m1q" contributorURI="platform:/plugin/RCPTest" keySequence="M1+Q" command="_KdFcwglbEee-eMrs46logg"/>
</bindingTables>
<rootContext xmi:id="_KdFcvwlbEee-eMrs46logg" elementId="org.eclipse.ui.contexts.dialogAndWindow" contributorURI="platform:/plugin/RCPTest" name="In Dialog and Windows">
<children xmi:id="_KdFcwAlbEee-eMrs46logg" elementId="org.eclipse.ui.contexts.window" contributorURI="platform:/plugin/RCPTest" name="In Windows"/>
<children xmi:id="_KdFcwQlbEee-eMrs46logg" elementId="org.eclipse.ui.contexts.dialog" contributorURI="platform:/plugin/RCPTest" name="In Dialogs"/>
</rootContext>
<commands xmi:id="_KdFcwglbEee-eMrs46logg" elementId="org.eclipse.ui.file.exit" contributorURI="platform:/plugin/RCPTest" commandName="quitCommand"/>
<addons xmi:id="_KdFcwwlbEee-eMrs46logg" elementId="org.eclipse.e4.core.commands.service" contributorURI="platform:/plugin/RCPTest" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
<addons xmi:id="_KdFcxAlbEee-eMrs46logg" elementId="org.eclipse.e4.ui.contexts.service" contributorURI="platform:/plugin/RCPTest" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
<addons xmi:id="_KdFcxQlbEee-eMrs46logg" elementId="org.eclipse.e4.ui.bindings.service" contributorURI="platform:/plugin/RCPTest" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/>
<addons xmi:id="_KdFcxglbEee-eMrs46logg" elementId="org.eclipse.e4.ui.workbench.commands.model" contributorURI="platform:/plugin/RCPTest" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon"/>
<addons xmi:id="_KdFcxwlbEee-eMrs46logg" elementId="org.eclipse.e4.ui.workbench.handler.model" contributorURI="platform:/plugin/RCPTest" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>
<addons xmi:id="_KdFcyAlbEee-eMrs46logg" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributorURI="platform:/plugin/RCPTest" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/>
<addons xmi:id="_KdFcyQlbEee-eMrs46logg" elementId="org.eclipse.e4.ui.workbench.bindings.model" contributorURI="platform:/plugin/RCPTest" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon"/>
</application:Application>
The application model extended by adding a new menu entry:
<?xml version="1.0" encoding="UTF-8"?>
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:advanced="http://www.eclipse.org/ui/2010/UIModel/application/ui/advanced" 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" xmi:id="_6wlLcMgZEeSyMNYR5xypkQ" elementId="RCPTest.application" bindingContexts="_6wlLecgZEeSyMNYR5xypkQ">
<children xsi:type="basic:TrimmedWindow" xmi:id="_6wlLccgZEeSyMNYR5xypkQ" elementId="RCPTest.window.main" label="Eclipse 4 RCP Application" width="500" height="400">
<children xsi:type="advanced:PerspectiveStack" xmi:id="_6wlLkMgZEeSyMNYR5xypkQ" elementId="org.eclipse.ui.ide.perspectivestack">
<children xsi:type="advanced:Perspective" xmi:id="_6wlLkcgZEeSyMNYR5xypkQ" elementId="RCPTest.perspective.sample">
<children xsi:type="basic:PartSashContainer" xmi:id="_6wlLksgZEeSyMNYR5xypkQ" elementId="RCPTest.partsashcontainer.sample">
<children xsi:type="basic:PartStack" xmi:id="_6wlLk8gZEeSyMNYR5xypkQ" elementId="RCPTest.partstack.sample">
<children xsi:type="basic:Part" xmi:id="_6wlLlMgZEeSyMNYR5xypkQ" elementId="RCPTest.part.sample" contributionURI="bundleclass://RCPTest/rcptest.parts.SamplePart" label="Sample Part"/>
</children>
</children>
</children>
</children>
<mainMenu xmi:id="_6wlLicgZEeSyMNYR5xypkQ" elementId="org.eclipse.ui.main.menu">
<children xsi:type="menu:Menu" xmi:id="_6wlLisgZEeSyMNYR5xypkQ" elementId="file" label="File">
<children xsi:type="menu:HandledMenuItem" xmi:id="_rocOUAlbEeeFFeCZvXOsLw" elementId="rcptest.handledmenuitem.test" label="Test" command="_oTNX4AlbEeeFFeCZvXOsLw"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_6wlLjcgZEeSyMNYR5xypkQ" elementId="RCPTest.handleditem.quit" label="Quit" command="_6wlLfMgZEeSyMNYR5xypkQ"/>
</children>
<children xsi:type="menu:Menu" xmi:id="_6wlLjsgZEeSyMNYR5xypkQ" elementId="help" label="Help"/>
</mainMenu>
</children>
<handlers xmi:id="_6wlLfcgZEeSyMNYR5xypkQ" elementId="rcptest.handler.quitCommand" contributionURI="bundleclass://RCPTest/rcptest.handlers.QuitHandler" command="_6wlLfMgZEeSyMNYR5xypkQ"/>
<handlers xmi:id="_pjrhQAlbEeeFFeCZvXOsLw" elementId="rcptest.handler.test" contributionURI="bundleclass://RCPTest/rcptest.handlers.TestHandler" command="_oTNX4AlbEeeFFeCZvXOsLw"/>
<bindingTables xmi:id="_6wlLfsgZEeSyMNYR5xypkQ" elementId="RCPTest.bindingtable" bindingContext="_6wlLecgZEeSyMNYR5xypkQ">
<bindings xmi:id="_6wlLf8gZEeSyMNYR5xypkQ" elementId="RCPTest.keybinding.m1q" keySequence="M1+Q" command="_6wlLfMgZEeSyMNYR5xypkQ"/>
</bindingTables>
<rootContext xmi:id="_6wlLecgZEeSyMNYR5xypkQ" elementId="org.eclipse.ui.contexts.dialogAndWindow" name="In Dialog and Windows">
<children xmi:id="_6wlLesgZEeSyMNYR5xypkQ" elementId="org.eclipse.ui.contexts.window" name="In Windows"/>
<children xmi:id="_6wlLe8gZEeSyMNYR5xypkQ" elementId="org.eclipse.ui.contexts.dialog" name="In Dialogs"/>
</rootContext>
<commands xmi:id="_6wlLfMgZEeSyMNYR5xypkQ" elementId="org.eclipse.ui.file.exit" commandName="quitCommand"/>
<commands xmi:id="_oTNX4AlbEeeFFeCZvXOsLw" elementId="rcptest.command.test" commandName="test"/>
<addons xmi:id="_6wlLcsgZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
<addons xmi:id="_6wlLc8gZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
<addons xmi:id="_6wlLdMgZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/>
<addons xmi:id="_6wlLdcgZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.workbench.commands.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon"/>
<addons xmi:id="_6wlLdsgZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.workbench.handler.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>
<addons xmi:id="_6wlLd8gZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/>
<addons xmi:id="_6wlLeMgZEeSyMNYR5xypkQ" elementId="org.eclipse.e4.ui.workbench.bindings.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon"/>
</application:Application>
That's how the menu looks when the saved "workbench.xmi" is loaded:
And this is the menu when I first delete "workbench.xmi" or any startup after that:
If you just want the position and size saved you could use -clearPersistedState
and save the position and size elsewhere.
You can set the size of the main window from the saved data in your LifeCycle class. The @ProcessAdditions method seems to be the earliest you can do this. Something like:
@ProcessAdditions
public void processAdditions(MApplication app, EModelService modelService)
{
MWindow window = (MWindow)modelService.find("main window id", app);
window.setX(saved value);
window.setY(saved value);
window.setWidth(saved value);
window.setHeight(saved value);
}