我有一个简单的Eclipse 4 RCP应用程序。参数“-clearPersistedState”明确不用于使窗口的大小和位置在以后的启动时恢复。 问题是模型持久化为“.metadata / .plugins / org.eclipse.e4.workbench / workbench.xmi”包含整个应用程序状态。当我在更高版本中扩展应用程序的模型时,例如添加新的菜单条目和相关命令,如果找到持久性,则忽略这些添加。 使用“-deltaRestore”也不起作用。
如何确保应用程序的特定部分始终呈现在应用程序模型中的定义方式,而不是从“workbench.xmi”恢复其状态? 是否可以只保留/恢复窗口的大小和位置?
初始模型:
<?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>
“workbench.xmi”持续使用此版本:
<?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>
通过添加新菜单条目扩展应用程序模型:
<?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>
答案 0 :(得分:1)
如果您只想保存位置和尺寸,可以使用Colors"
并将位置和尺寸保存在其他位置。
您可以从LifeCycle类中保存的数据设置主窗口的大小。 @ProcessAdditions方法似乎是最早可以做到的。类似的东西:
-clearPersistedState