當E4 RCP應用程序關閉時,更改將記錄/保存在workbench.xmi文件中。Eclipse RCP workbench.xmi控制保存的零件
在零件堆中,應用程序關閉時可能會打開幾個零件。當重新啓動應用程序保存在workbench.xmi這些部件被創建並再次顯示
這些部件被標記爲
<children xsi:type="basic:PartStack"
xmi:id="_The_ID"
elementId="elemId"
contributorURI="URI"
containerData="3000">
<tags>NoAutoCollapse</tags>
</children>
。
如何在啓動應用程序時再次控制這些部件以允許/不允許創建零件?
這是爲了防止您的數據模型(與您的零件相連)保存在文件中。
例如,以下序列:
1.- RCP被關閉開有一些部分(即文件到remain.xml和文件到待deleted.xml)
2.-用戶刪除文件待刪除文件文件刪除數據。
3.- RCP重新啓動,因此待刪除文件文件夾被創建並顯示,沒有數據。
目的是爲了避免創建文件,以待deleted.xml在步驟3 .-
我會讀格雷格-449的答案,也是他在回答問題後延長我的解釋: 「e4 - removing elements from the application model」
我有一個workbench.xmi在應用程序關閉時保存了一個PartStack和兩個零件(2個xml文件)(file-to-remaining.xml,待刪除文件)。 xml)
請注意,元素ID是包含文件路徑的字符串。通過part.setElementID(String)方法創建零件。
還要注意的是,部分由一個名爲AutodocuForm.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>
類我創建了一個生命週期類創建:
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);
}
}
}
}
}
如果我刪除「文件將要-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: [email protected]39478c45
(elementId: my-plugin.partstack.0,
tags: [NoAutoCollapse],
contributorURI: platform:/plugin/my-plugin)
(widget: CTabFolder {},
renderer: [email protected],
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)
...
...
在我看來,零件已從模型中刪除,但零件堆棧未更新。
在此先感謝
僅允許步驟2 RCP應用程序內部。 –
如果將setToBeRendered設置爲false,則可能無需從父項中刪除。 –
它工作正常刪除'parent.getChildren()。remove(elParte);'並添加一些代碼在下面的答案中定義。 –