Skip to main content



      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 05:03 Go to next message
Eclipse UserFriend
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 09:40 Go to previous message
Eclipse UserFriend
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: Sun Jul 06 23:48:27 EDT 2025

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

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

Back to the top