加载时未显示 Eclipse 4 RCP 应用程序模型中的新菜单项 workbench.xmi

New menu entries in Eclipse 4 RCP application model aren't shown when loading workbench.xmi

我有一个简单的 Eclipse 4 RCP 应用程序。参数“-clearPersistedState”明确不用于使 window 在以后启动时恢复其大小和位置。 问题是持久化到“.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi”的模型包含整个应用程序状态。当我通过例如在更高版本中扩展应用程序的模型时添加一个新的菜单条目和一个关联的命令,如果找到一个持久化的,这些添加将被忽略。 使用“-deltaRestore”也不起作用。

如何确保应用程序的特定部分始终按照它们在应用程序模型中的定义呈现,而不是从 "workbench.xmi" 恢复它们的状态? 是否可以仅 persist/restore window 的大小和位置?

初始模型:

<?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>

这就是加载保存的 "workbench.xmi" 时菜单的样子:

这是我第一次删除 "workbench.xmi" 或之后的任何启动时的菜单:

如果您只想保存位置和大小,可以使用 -clearPersistedState 并将位置和大小保存在别处。

您可以根据 LifeCycle class 中保存的数据设置主要 window 的大小。 @ProcessAdditions 方法似乎是您最早可以执行此操作的方法。类似于:

@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);
}