Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Recreate workbench mit different model
Recreate workbench mit different model [message #1844968] Fri, 01 October 2021 08:39 Go to next message
Guenther Mahr is currently offline Guenther MahrFriend
Messages: 36
Registered: September 2011
Member
I have the following problem:
In our application the user can save his current settings (meaning the current state of the workbench) to an external location. This was not difficult, I could do it by overriding the saveModel() - method of the E4Application.

But the more trickier part is the following: by pressing a shortcut key the user should be able to reload the saved workbench state (restart is not feasible, takes to long). I have tried several ways:

1. Close all windows - leading to the shutdown of the workbench. Then copy the saved state (the workbench.xmi) to the local Eclipse and create a new workbench. This first seemed to work, but then I found out that obviously all the "old" objects still exist, e.g. when I activate a renderer sometimes the old renderer is used then again the new renderer. I could not find out how to get rid of all the "old" objects. Do you have any idea?

2. My second try was to leave the workbench open, remove all windows - by a trick I could manage not to bring the event loop to a close - then load the other workbench.xmi as a resource (using the IModelResourceHandler) , then copy all parts of the new MApplication to the old MApplication and then continue. This worked partly - I could reshow the workbench but then I found out that obviously the unloading of the old resource and loading of the new resource (the workbench.xmi) caused a uninject and reinject in all my objects - so that I now had still my old application running, but with new objects - which is not viable either.
Is there a way to avoid this reinject? Unfortunately I'm not very proficient in EMF.

Any ideas how to do what I need to do?

Thanks,
Günther
Re: Recreate workbench mit different model [message #1845003 is a reply to message #1844968] Sat, 02 October 2021 13:49 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 260
Registered: April 2012
Senior Member
What you are trying to do is surely not common use-case in Eclipse. Do expect all kind of issues, as probably nobody tried this before.

Most success, you probably get by adding a new window first, then remove the old window. This would be similar to the "Window > New Window" functionality in Eclipse IDE. It might be possible to mark the old window not visible first, thought that could trigger the close too. The new window might need to be marked not rendered at first too.
You would want to move the window in the persisted file to the MApplication windows of the current running application, e.g. newApp.getWindows().addAll(oldApp.getWindows()). When you don't save the old model, this effectively is a copy too. I expect that now all references are in the new model.
When you copy the objects, you have to ensure that also all non-containment references are updated, EcoreUtil.copy(...) should help you there.

This could be interesting to you too: https://bugs.eclipse.org/bugs/show_bug.cgi?id=570471
Re: Recreate workbench mit different model [message #1845048 is a reply to message #1845003] Mon, 04 October 2021 14:29 Go to previous message
Guenther Mahr is currently offline Guenther MahrFriend
Messages: 36
Registered: September 2011
Member
Thank you for your answer! In the meantime I found the solution:I close all windows but into the last open one I put a dummy Label as a widget: by this trick I achieve that the event loop is not stopped (which would close the workbench).
Then I load the saved workbench.xmi with

ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(workbenchURI);
resource.load(null);

Then I get the MApplication by just saying
(MApplication) resource.getContents().get(0);

I now take the children of this application (the windows) and add them to the old running model.
Then I remove the "dummy" window (the one with the Label in it) which I can now do safely.

And it works....
Previous Topic:Adding a menu contribution for a XMLMultiPageEditorPart
Next Topic:Part Descriptor with Tag "View" not visible in "Show Views" since 2021.06
Goto Forum:
  


Current Time: Thu Apr 25 16:21:32 GMT 2024

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

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

Back to the top