Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Saving and restoring all open editors including layout / Replace parts of the UI model
icon5.gif  Saving and restoring all open editors including layout / Replace parts of the UI model [message #1163853] Thu, 31 October 2013 09:03 Go to next message
Christoph K is currently offline Christoph KFriend
Messages: 2
Registered: July 2009
Junior Member
Hi everybody,

I am trying to save the state of all currently opened editors into a "session" which can then later be restored. For this, I would also like to save the GUI state of the editors, e.g. whether the editor area has been split etc.

I tried to use the same mechanism that eclipse uses on shutdown to save the workbench state, but only for the editor area for a WorkbenchPage.

Saving already works, like this:

MUIElement area = ((WorkbenchPage) page).findSharedArea();
if (area instanceof MPlaceholder) {
	area = ((MPlaceholder) area).getRef();
}

ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
resourceSetImpl.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new E4XMIResourceFactory());

resourceSetImpl.getPackageRegistry().put(ApplicationPackageImpl.eNS_URI, ApplicationPackageImpl.eINSTANCE);
resourceSetImpl.getPackageRegistry().put(CommandsPackageImpl.eNS_URI, CommandsPackageImpl.eINSTANCE);
resourceSetImpl.getPackageRegistry().put(UiPackageImpl.eNS_URI, UiPackageImpl.eINSTANCE);
resourceSetImpl.getPackageRegistry().put(MenuPackageImpl.eNS_URI, MenuPackageImpl.eINSTANCE);
resourceSetImpl.getPackageRegistry().put(BasicPackageImpl.eNS_URI, BasicPackageImpl.eINSTANCE);
resourceSetImpl.getPackageRegistry().put(AdvancedPackageImpl.eNS_URI, AdvancedPackageImpl.eINSTANCE);
resourceSetImpl.getPackageRegistry().put(org.eclipse.e4.ui.model.application.descriptor.basic.impl.BasicPackageImpl.eNS_URI, org.eclipse.e4.ui.model.application.descriptor.basic.impl.BasicPackageImpl.eINSTANCE);

URI uri = URI.createFileURI(PresentationPlugin.getDefault().getStateLocation().append("editors.xmi").toFile().getAbsolutePath());

Resource res = resourceSetImpl.createResource(uri);
EObject obj=EcoreUtil.copy((EObject)area);
res.getContents().add(obj);
res.save(null);	



This creates a file ("editors.xmi") that contains the contents of the editor area.
I use the following code to recreate the MUIElement of the editor area:

URI uri = URI.createFileURI(PresentationPlugin.getDefault().getStateLocation().append("editors.xmi").toFile().getAbsolutePath());

Resource res = resourceSetImpl.getResource(uri, true);
MUIElement restoredArea = (MUIElement) res.getContents().get(0);


However, I did not yet find a way to exchange the current editor area with my restored one. I tried the following code:

MUIElement areaPlaceHolder = ((WorkbenchPage) page).findSharedArea();
if (areaPlaceHolder instanceof MPlaceholder) {
	MUIElement oldArea = ((MPlaceholder) areaPlaceHolder).getRef();
	restoredArea.setParent(oldArea.getParent());
	restoredArea.setRenderer(oldArea.getRenderer());		
	((MPlaceholder) areaPlaceHolder).setRef(restoredArea);
}


Unfortunately, this does not exchange any editor and puts the workbench in a completely unusable state where I get all kinds of exceptions.

Is there a way to replace parts of the ui model with a model I loaded from file?

Best regards,
Christoph
Re: Saving and restoring all open editors including layout / Replace parts of the UI model [message #1181337 is a reply to message #1163853] Mon, 11 November 2013 14:40 Go to previous message
Christoph K is currently offline Christoph KFriend
Messages: 2
Registered: July 2009
Junior Member
It seems nobody knows how to replace parts of the ui model at runtime..
Is there another way to save the "workbench editor state" and restore it?

Best regards,
Christoph
Previous Topic:Get visible parts of a partstack
Next Topic:them selection is empty in the appearance preferences
Goto Forum:
  


Current Time: Wed Apr 24 15:43:02 GMT 2024

Powered by FUDForum. Page generated in 0.02941 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top