[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[platform-ui-dev] Restore a workbenchpage with an external memento.xml without closing eclipse 3.1
|
Hello everybody,
I am having a problem concerning a restore of a workbench page.
Reading the bug track from Bug 85373 - [RCP] Missing save/restore
capabilities of workbench state
https://bugs.eclipse.org/bugs/show_bug.cgi?id=85373
I' ve got some insight concerning the concept of using the restore
mechanism in eclipse 3.1 and the ideas for following releases. I am not
sure if I encountered a bug or if my approach is wrong.
Use Case:
I want to switch Perspectives, during runtime and have the page set
(restored) to a predefined state saved previously in a XMLMemento (same
format as the workbech.xml in
../.metadata/.plugins/org.eclipse.ui.workbench/ ) coming from somewhere
in my file system. The views and editors are opened correctly according
to the memento, the only problem I have is that every time I call
WorkbenchPage.restoreState( IMemento myCustomMemento), the editor area
is split in half (this is definitely not in the memento), where the one
half is correctly stacked with the right editors, but the other half is
just painted grey. If I randomly move the opened editors around the grey
areas disappears suddenly and the page looks find now. Could this be an
event problem or do I use the frame work in the wrong way.
the following method performs the switch to another perspective and its
population with a predefined state from the Memento:
public static boolean nextPerspective(String urlWithPageState, String
perspectiveID, IWorkbenchPage activePage)
{
final IWorkbench workbench = PlatformUI.getWorkbench();
final IPerspectiveRegistry registry =
workbench.getPerspectiveRegistry();
try {
XMLMemento memento = XMLMemento.createReadRoot(new
FileReader( urlWithPageState));
IMemento windowMemento =
memento.getChild(IWorkbenchConstants.TAG_WINDOW);
IMemento pageMemento =
windowMemento.getChild(IWorkbenchConstants.TAG_PAGE);
IPerspectiveDescriptor realDesc =
registry.findPerspectiveWithId(perspectiveID);
IPerspectiveDescriptor oldPerspectiveDesc =
activePage.getPerspective();
activePage.closePerspective(oldPerspectiveDesc, true, false);
((WorkbenchPage) activePage).restoreState(pageMemento, null);
activePage.setPerspective(realDesc);
activePage.resetPerspective();
} catch (IOException e) {
e.printStackTrace();
handleException(e, page);
return false;
} catch (WorkbenchException e) {
e.printStackTrace();
handleException(e, page);
return false;
}
return true;
}
XML Memento:
<?xml version="1.0" encoding="UTF-8"?>
<workbench version="2.0" progressCount="13">
<workbenchAdvisor/>
<window maximized="true" x="132" y="132" width="1024" height="768">
<fastViewData fastViewLocation="1024"/>
<perspectiveBar>
<itemSize x="160"/>
</perspectiveBar>
<coolbarLayout locked="0">
<coolItem id="group.file" itemType="typeGroupMarker"/>
<coolItem id="org.eclipse.ui.workbench.file"
itemType="typeToolBarContribution" x="95" y="22"/>
<coolItem id="additions" itemType="typeGroupMarker"/>
<coolItem id="KalypsoDSSPlanerClient.actionSet"
itemType="typeToolBarContribution" x="59" y="22"/>
<coolItem id="org.eclipse.debug.ui.launchActionSet"
itemType="typeToolBarContribution" x="49" y="22"/>
<coolItem id="org.eclipse.search.searchActionSet"
itemType="typeToolBarContribution" x="36" y="22"/>
<coolItem id="group.nav" itemType="typeGroupMarker"/>
<coolItem id="org.eclipse.ui.workbench.navigate"
itemType="typeToolBarContribution" x="108" y="22"/>
<coolItem id="group.editor" itemType="typeGroupMarker"/>
<coolItem id="org.eclipse.ui.DefaultTextEditor"
itemType="typeToolBarContribution" x="-1" y="-1"/>
<coolItem id="group.help" itemType="typeGroupMarker"/>
<coolItem id="org.eclipse.ui.workbench.help"
itemType="typeToolBarContribution" x="-1" y="-1"/>
</coolbarLayout>
<page label="<Unknown Label> - Kalypso Planer-Client Phase 2"
focus="true">
<editors>
<editorArea activeWorkbook="DefaultEditorWorkbook">
<info part="DefaultEditorWorkbook">
<folder expanded="2" appearance="1">
<presentation
id="org.eclipse.ui.presentations.WorkbenchPresentationFactory">
<part id="0"/>
</presentation>
</folder>
</info>
<info part="org.eclipse.ui.internal.EditorStack@45f4ae"
relative="DefaultEditorWorkbook" relationship="4" ratioLeft="335"
ratioRight="336" ratio="0.49925485">
<folder expanded="2" appearance="1">
<presentation
id="org.eclipse.ui.presentations.WorkbenchPresentationFactory">
<part id="0"/>
</presentation>
</folder>
</info>
</editorArea>
<editor title="phase2.txt" name="phase2.txt"
id="org.eclipse.ui.DefaultTextEditor" tooltip="MyTestProject/phase2.txt"
partName="phase2.txt" workbook="DefaultEditorWorkbook" activePart="true"
focus="true"
path="D:/eclipse3.1/runtime-workspace/MyTestProject/phase2.txt">
<input factoryID="org.eclipse.ui.part.FileEditorInputFactory"
path="/MyTestProject/phase2.txt"/>
</editor>
<editor title="filelInFolder2.txt" name="filelInFolder2.txt"
id="org.eclipse.ui.DefaultTextEditor"
tooltip="MyTestProject/Folder2/filelInFolder2.txt"
partName="filelInFolder2.txt"
workbook="org.eclipse.ui.internal.EditorStack@45f4ae" focus="true"
path="D:/eclipse3.1/runtime-workspace/MyTestProject/Folder2/filelInFolder2.txt">
<input factoryID="org.eclipse.ui.part.FileEditorInputFactory"
path="/MyTestProject/Folder2/filelInFolder2.txt"/>
</editor>
</editors>
<views>
<view id="org.kalypso.dss.planerclient.view.browser" partName="Kalypso
Browser">
<viewState url="file:///D:/TEMP/Perspectives/DssPlanerClient.htm">
<scrolbars/>
</viewState>
</view>
<view id="org.eclipse.ui.views.ResourceNavigator" partName="Navigator">
<viewState sorter="1" LINK_NAVIGATOR_TO_EDITOR="1">
<filters>
<filter element="*.class" isEnabled="false"/>
<filter element=".*" isEnabled="true"/>
</filters>
<expanded>
<element path="/MyTestProject"/>
<element path="/MyTestProject/Folder1"/>
<element path="/MyTestProject/Folder2"/>
</expanded>
<selection>
<element path="/MyTestProject/phase2.txt"/>
</selection>
</viewState>
</view>
</views>
<perspectives
activePerspective="org.kalypso.dss.planerclient.perspectiv.phase.two"
activePart="org.eclipse.ui.DefaultTextEditor">
<perspective version="0.016" editorAreaVisible="1" fixed="0">
<descriptor id="org.kalypso.dss.planerclient.perspectiv.phase.two"
label="Kalypso Planer-Client Phase 2"
class="org.kalypso.dss.planerclient.perspectives.KalypsoDssPlanerPhaseTwoClientPerspectiveFactory"/>
<alwaysOnActionSet id="org.eclipse.ui.cheatsheets.actionSet"/>
<alwaysOnActionSet id="org.eclipse.search.searchActionSet"/>
<alwaysOnActionSet
id="org.eclipse.ui.edit.text.actionSet.openExternalFile"/>
<alwaysOnActionSet id="org.eclipse.ui.edit.text.actionSet.navigation"/>
<alwaysOnActionSet
id="org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo"/>
<alwaysOnActionSet id="org.eclipse.ui.externaltools.ExternalToolsSet"/>
<alwaysOnActionSet id="KalypsoDSSPlanerClient.actionSet"/>
<alwaysOnActionSet id="org.eclipse.ui.actionSet.keyBindings"/>
<alwaysOnActionSet id="org.eclipse.update.ui.softwareUpdates"/>
<new_wizard_action id="org.eclipse.ui.wizards.new.folder"/>
<new_wizard_action id="org.eclipse.ui.wizards.new.file"/>
<view id="org.eclipse.ui.views.ResourceNavigator"/>
<view id="org.kalypso.dss.planerclient.view.browser"/>
<layout>
<mainWindow>
<info part="org.eclipse.ui.editorss"/>
<info part="stickyFolderRight" relative="org.eclipse.ui.editorss"
relationship="2" ratioLeft="754" ratioRight="252" ratio="0.74950296"
folder="true">
<folder expanded="2" appearance="2">
<page label="LabelNotFound" content="org.eclipse.help.ui.HelpView"/>
<page label="LabelNotFound" content="org.eclipse.ui.internal.introview"/>
<page label="LabelNotFound"
content="org.eclipse.ui.cheatsheets.views.CheatSheetView"/>
</folder>
</info>
<info part="topRight" relative="org.eclipse.ui.editorss"
relationship="2" ratioLeft="653" ratioRight="353" ratio="0.64910537"
folder="true">
<folder activePageID="org.eclipse.ui.views.ResourceNavigator"
expanded="2" appearance="2">
<page label="Navigator" content="org.eclipse.ui.views.ResourceNavigator"/>
<presentation
id="org.eclipse.ui.presentations.WorkbenchPresentationFactory">
<part id="0"/>
</presentation>
</folder>
</info>
<info part="bottomRight" relative="org.eclipse.ui.editorss"
relationship="4" ratioLeft="440" ratioRight="227" ratio="0.6596702"
folder="true">
<folder activePageID="org.kalypso.dss.planerclient.view.browser"
expanded="2" appearance="2">
<page label="Kalypso Browser"
content="org.kalypso.dss.planerclient.view.browser"/>
<presentation
id="org.eclipse.ui.presentations.WorkbenchPresentationFactory">
<part id="0"/>
</presentation>
</folder>
</info>
</mainWindow>
</layout>
</perspective>
</perspectives>
<navigationHistory/>
<stickyState/>
</page>
<workbenchWindowAdvisor/>
<actionBarAdvisor/>
</window>
<mruList>
<file factoryID="org.eclipse.ui.part.FileEditorInputFactory"
id="org.eclipse.ui.DefaultTextEditor" name="filelInFolder2.txt"
tooltip="MyTestProject/Folder2/filelInFolder2.txt">
<persistable path="/MyTestProject/Folder2/filelInFolder2.txt"/>
</file>
<file factoryID="org.eclipse.ui.part.FileEditorInputFactory"
id="org.eclipse.ui.DefaultTextEditor" name="phase2.txt"
tooltip="MyTestProject/phase2.txt">
<persistable path="/MyTestProject/phase2.txt"/>
</file>
<file factoryID="org.eclipse.ui.part.FileEditorInputFactory"
id="org.eclipse.ui.DefaultTextEditor" name="fileInFolder1.txt"
tooltip="MyTestProject/Folder1/fileInFolder1.txt">
<persistable path="/MyTestProject/Folder1/fileInFolder1.txt"/>
</file>
<file factoryID="org.eclipse.ui.part.FileEditorInputFactory"
id="org.eclipse.ui.DefaultTextEditor" name="phase1.txt"
tooltip="MyTestProject/phase1.txt">
<persistable path="/MyTestProject/phase1.txt"/>
</file>
</mruList>
</workbench>
This method is called from the LocationListener.changed(LocationEvent
event) of my own BrowserViewer (extends ViewPart and decorates the
eclipse BrowserViewer) which allows me to browse different perspectives
with a custom state.
What do I miss here??? Your help is realy appreciated.
Cheers
Christoph