Eclipse RCP workbench.xmi 保存部分的控制
Eclipse RCP workbench.xmi control of saved parts
关闭 E4 RCP 应用程序后,workbench.xmi 文件中的更改为 recorded/saved。
在一个 partstack 中,关闭应用程序时可能会打开多个部分。
这些部分被标记为
<children xsi:type="basic:PartStack"
xmi:id="_The_ID"
elementId="elemId"
contributorURI="URI"
containerData="3000">
<tags>NoAutoCollapse</tags>
</children>
重新启动应用程序时,将再次创建并显示保存在 workbench.xmi 中的这些部分。
如何在再次启动应用程序时控制这些部分,以便allow/not-allow创建一个部分?
如果您的数据模型(与您的零件连接)保存在文件中,将使用此选项。
例如下面的序列:
1.- RCP 已关闭,某些部分已打开(即 file-to-remain.xml 和 file-to-be-deleted.xml)
2.- 用户删除文件 file-to-be-deleted.xml 删除数据。
3.- RCP 重新启动,因此 file-to-be-deleted.xml 被创建并显示没有数据。
objective是为了避免在第3步中创建file-to-deleted.xml.-
我会在阅读 greg-449 的回答以及他的问题回答后扩展我的解释:“”
我保存了一个 workbench.xmi,其中包含一个 PartStack 和两个部分(2 xml 文件),当时应用程序关闭(file-to-remain.xml,file-未来-deleted.xml)
请注意,元素 ID 是包含文件路径的字符串。通过 part.setElementID(String) 方法在创建部分时完成。
另请注意,零件是由名为 AutodocuForm.class
的 class 创建的
<children xsi:type="basic:PartStack"
xmi:id="_iDPe2cIDEeaAXZB7N2qOIw"
elementId="my-plugin.partstack.0"
contributorURI="platform:/plugin/my-plugin"
containerData="3066"
selectedElement="_6pVbwMNsEeaiI_JEbgNbYQ">
<children xsi:type="basic:Part"
xmi:id="_3ZCIocNsEeaiI_JEbgNbYQ"
elementId="C:\Users\name\Desktop\file-to-remain.xml"
contributorURI="platform:/plugin/my-plugin"
contributionURI="bundleclass://my-plugin/my-plugin.autodocu.AutodocuForm"
label="file-to-remain.xml"
iconURI="platform:/plugin/my-plugin/icons/file_obj.gif"
closeable="true">
</children>
<children xsi:type="basic:Part"
xmi:id="_6pVbwMNsEeaiI_JEbgNbYQ"
elementId="C:\Users\name\Desktop\file-to-be-deleted.xml"
contributorURI="platform:/plugin/my-plugin"
contributionURI="bundleclass://my-plugin/my-plugin.autodocu.AutodocuForm"
label="file-to-be-deleted.xml"
iconURI="platform:/plugin/my-plugin/icons/file_obj.gif"
closeable="true">
</children>
</children>
我创建了一个生命周期class:
public class LifeCycleManager {
@ProcessRemovals
void postContextCreate(IEclipseContext context, MApplication application, EModelService modelService, EPartService partService){
List<MPart> parts = modelService.findElements(application, null, MPart.class, null);
for(MPart elParte: parts){
if(elParte.getContributionURI().endsWith("AutodocuForm")){
Path partPath = Paths.get(elParte.getElementId());
if(Files.exists(partPath, LinkOption.NOFOLLOW_LINKS)){
System.out.println("FILE EXISTS INTO THE FILE SYSTEM...");
}
else{
System.out.println("FILE DOES NOT EXIST INTO THE FILE SYSTEM...");
MElementContainer<MUIElement> parent = elParte.getParent();
elParte.setToBeRendered(false);
parent.getChildren().remove(elParte);
}
}
}
}
}
如果我删除 "file-to-be-deleted.xml" 并重新启动应用程序,该部分不会显示在 partStack 中,但我得到以下异常:
!ENTRY org.eclipse.e4.ui.workbench.swt 4 2 2016-12-20 11:09:38.601
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.e4.ui.workbench.swt".
!STACK 0
java.lang.NullPointerException
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.showTab(LazyStackRenderer.java:160)
...
...
!ENTRY org.eclipse.e4.ui.workbench 4 0 2016-12-20 11:09:38.601
!MESSAGE Exception occurred while rendering: org.eclipse.e4.ui.model.application.ui.basic.impl.PartStackImpl@39478c45
(elementId: my-plugin.partstack.0,
tags: [NoAutoCollapse],
contributorURI: platform:/plugin/my-plugin)
(widget: CTabFolder {},
renderer: org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer@1b62d923,
toBeRendered: true,
onTop: false,
visible: true,
containerData: 3066,
accessibilityPhrase: null)
!STACK 0
java.lang.NullPointerException
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.showTab(LazyStackRenderer.java:160)
...
...
在我看来,零件已从模型中删除,但零件堆栈未更新。
提前致谢
您可以指定 -clearPersistedState
选项使 RCP 忽略 workbench.xmi 并完全按照 Application.e4xmi 中的描述打开。
您还可以指定 -persistState false
以首先停止保存 workbench.xmi。
在 .product 文件编辑器的 'Launching' 选项卡的 'Program Arguments' 部分指定这些。
不支持在启动期间仅恢复模型的一部分。 workbench.xmi 只是应用程序模型的一个副本,就像您退出 RCP 时一样。
如果您有要打开的部件列表,您可以在 RCP 启动期间可能在 'application startup complete' 事件中执行此操作。这可能是您生命周期中的一种方法 class(如果您有的话):
@Optional
@Inject
public void appStartupComplete(@UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event,
EPartService partService)
{
// TODO call partService.showPart for parts to be opened
}
通过删除 parent.getChildren().remove(elParte);
解决了异常。
此外,有必要从模型(从零件堆栈列表)中删除零件,如下一个片段所示:
public class LifeCycleManager {
@ProcessRemovals
void postContextCreate(IEclipseContext context, MApplication application, EModelService modelService, EPartService partService){
List<MPart> parts = modelService.findElements(application, null, MPart.class, null);
for(MPart elParte: parts){
if(elParte.getContributionURI().endsWith("AutodocuForm")){
Path partPath = Paths.get(elParte.getElementId());
if(Files.exists(partPath, LinkOption.NOFOLLOW_LINKS)){
System.out.println("FILE EXISTS INTO THE FILE SYSTEM...");
}
else{
System.out.println("FILE DOES NOT EXIST INTO THE FILE SYSTEM...");
MElementContainer<MUIElement> parent = elParte.getParent();
elParte.setToBeRendered(false);
//parent.getChildren().remove(elParte);
Iterator it = parent.getChildren().iterator();
elParte.setToBeRendered(false);
while(it.hasNext()){
MUIElement el = (MUIElement) it.next();
if(el.getElementId().equals(elParte.getElementId())){
//Remove the part from the PartStack list
parent.getChildren().remove(el);
//Remove the selected element to avoid that the
//deleted file was the selected element prior to
//deletion, which is stored into the
//workbench.xmi file
parent.setSelectedElement(null);
break;
}
}
}
}
}
}
}
关闭 E4 RCP 应用程序后,workbench.xmi 文件中的更改为 recorded/saved。
在一个 partstack 中,关闭应用程序时可能会打开多个部分。
这些部分被标记为
<children xsi:type="basic:PartStack"
xmi:id="_The_ID"
elementId="elemId"
contributorURI="URI"
containerData="3000">
<tags>NoAutoCollapse</tags>
</children>
重新启动应用程序时,将再次创建并显示保存在 workbench.xmi 中的这些部分。
如何在再次启动应用程序时控制这些部分,以便allow/not-allow创建一个部分?
如果您的数据模型(与您的零件连接)保存在文件中,将使用此选项。
例如下面的序列:
1.- RCP 已关闭,某些部分已打开(即 file-to-remain.xml 和 file-to-be-deleted.xml)
2.- 用户删除文件 file-to-be-deleted.xml 删除数据。
3.- RCP 重新启动,因此 file-to-be-deleted.xml 被创建并显示没有数据。
objective是为了避免在第3步中创建file-to-deleted.xml.-
我会在阅读 greg-449 的回答以及他的问题回答后扩展我的解释:“
我保存了一个 workbench.xmi,其中包含一个 PartStack 和两个部分(2 xml 文件),当时应用程序关闭(file-to-remain.xml,file-未来-deleted.xml)
请注意,元素 ID 是包含文件路径的字符串。通过 part.setElementID(String) 方法在创建部分时完成。
另请注意,零件是由名为 AutodocuForm.class
的 class 创建的<children xsi:type="basic:PartStack"
xmi:id="_iDPe2cIDEeaAXZB7N2qOIw"
elementId="my-plugin.partstack.0"
contributorURI="platform:/plugin/my-plugin"
containerData="3066"
selectedElement="_6pVbwMNsEeaiI_JEbgNbYQ">
<children xsi:type="basic:Part"
xmi:id="_3ZCIocNsEeaiI_JEbgNbYQ"
elementId="C:\Users\name\Desktop\file-to-remain.xml"
contributorURI="platform:/plugin/my-plugin"
contributionURI="bundleclass://my-plugin/my-plugin.autodocu.AutodocuForm"
label="file-to-remain.xml"
iconURI="platform:/plugin/my-plugin/icons/file_obj.gif"
closeable="true">
</children>
<children xsi:type="basic:Part"
xmi:id="_6pVbwMNsEeaiI_JEbgNbYQ"
elementId="C:\Users\name\Desktop\file-to-be-deleted.xml"
contributorURI="platform:/plugin/my-plugin"
contributionURI="bundleclass://my-plugin/my-plugin.autodocu.AutodocuForm"
label="file-to-be-deleted.xml"
iconURI="platform:/plugin/my-plugin/icons/file_obj.gif"
closeable="true">
</children>
</children>
我创建了一个生命周期class:
public class LifeCycleManager {
@ProcessRemovals
void postContextCreate(IEclipseContext context, MApplication application, EModelService modelService, EPartService partService){
List<MPart> parts = modelService.findElements(application, null, MPart.class, null);
for(MPart elParte: parts){
if(elParte.getContributionURI().endsWith("AutodocuForm")){
Path partPath = Paths.get(elParte.getElementId());
if(Files.exists(partPath, LinkOption.NOFOLLOW_LINKS)){
System.out.println("FILE EXISTS INTO THE FILE SYSTEM...");
}
else{
System.out.println("FILE DOES NOT EXIST INTO THE FILE SYSTEM...");
MElementContainer<MUIElement> parent = elParte.getParent();
elParte.setToBeRendered(false);
parent.getChildren().remove(elParte);
}
}
}
}
}
如果我删除 "file-to-be-deleted.xml" 并重新启动应用程序,该部分不会显示在 partStack 中,但我得到以下异常:
!ENTRY org.eclipse.e4.ui.workbench.swt 4 2 2016-12-20 11:09:38.601
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.e4.ui.workbench.swt".
!STACK 0
java.lang.NullPointerException
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.showTab(LazyStackRenderer.java:160)
...
...
!ENTRY org.eclipse.e4.ui.workbench 4 0 2016-12-20 11:09:38.601
!MESSAGE Exception occurred while rendering: org.eclipse.e4.ui.model.application.ui.basic.impl.PartStackImpl@39478c45
(elementId: my-plugin.partstack.0,
tags: [NoAutoCollapse],
contributorURI: platform:/plugin/my-plugin)
(widget: CTabFolder {},
renderer: org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer@1b62d923,
toBeRendered: true,
onTop: false,
visible: true,
containerData: 3066,
accessibilityPhrase: null)
!STACK 0
java.lang.NullPointerException
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.showTab(LazyStackRenderer.java:160)
...
...
在我看来,零件已从模型中删除,但零件堆栈未更新。
提前致谢
您可以指定 -clearPersistedState
选项使 RCP 忽略 workbench.xmi 并完全按照 Application.e4xmi 中的描述打开。
您还可以指定 -persistState false
以首先停止保存 workbench.xmi。
在 .product 文件编辑器的 'Launching' 选项卡的 'Program Arguments' 部分指定这些。
不支持在启动期间仅恢复模型的一部分。 workbench.xmi 只是应用程序模型的一个副本,就像您退出 RCP 时一样。
如果您有要打开的部件列表,您可以在 RCP 启动期间可能在 'application startup complete' 事件中执行此操作。这可能是您生命周期中的一种方法 class(如果您有的话):
@Optional
@Inject
public void appStartupComplete(@UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event,
EPartService partService)
{
// TODO call partService.showPart for parts to be opened
}
通过删除 parent.getChildren().remove(elParte);
解决了异常。
此外,有必要从模型(从零件堆栈列表)中删除零件,如下一个片段所示:
public class LifeCycleManager {
@ProcessRemovals
void postContextCreate(IEclipseContext context, MApplication application, EModelService modelService, EPartService partService){
List<MPart> parts = modelService.findElements(application, null, MPart.class, null);
for(MPart elParte: parts){
if(elParte.getContributionURI().endsWith("AutodocuForm")){
Path partPath = Paths.get(elParte.getElementId());
if(Files.exists(partPath, LinkOption.NOFOLLOW_LINKS)){
System.out.println("FILE EXISTS INTO THE FILE SYSTEM...");
}
else{
System.out.println("FILE DOES NOT EXIST INTO THE FILE SYSTEM...");
MElementContainer<MUIElement> parent = elParte.getParent();
elParte.setToBeRendered(false);
//parent.getChildren().remove(elParte);
Iterator it = parent.getChildren().iterator();
elParte.setToBeRendered(false);
while(it.hasNext()){
MUIElement el = (MUIElement) it.next();
if(el.getElementId().equals(elParte.getElementId())){
//Remove the part from the PartStack list
parent.getChildren().remove(el);
//Remove the selected element to avoid that the
//deleted file was the selected element prior to
//deletion, which is stored into the
//workbench.xmi file
parent.setSelectedElement(null);
break;
}
}
}
}
}
}
}