Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to clear persisted state if application model has changed?
How to clear persisted state if application model has changed? [message #1002493] Fri, 18 January 2013 17:48 Go to next message
Markus Wiederkehr is currently offline Markus WiederkehrFriend
Messages: 17
Registered: August 2012
Junior Member
It's a nice feature that E4 automatically persists the current model on shutdown but sometimes during the development process the application model becomes incompatible with the persisted state.

What I'd like to do is clear the persisted state on startup but only if the application model has changed since the application was last started. Is that possible?

Setting the system property "clearPersistedState" in a life cycle manager seems to work:

	@PostContextCreate
	public void startup() {
		if (isNewApplicationModel()) {
			System.setProperty("clearPersistedState", "true");
		}
	}

What I don't know is how to implement isNewApplicationModel()?
Re: How to clear persisted state if application model has changed? [message #1002726 is a reply to message #1002493] Sat, 19 January 2013 08:12 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
I don't know if there is a build in functionality that is helpful.

You can do two launch configuration.

Or isNewApplicationModel() could store the modify time stamp of the e4xmi to another file, and compared the last stored value with the e4xmi. This will only work if you can access the e4xmi file directly. Perhaps, it is problematic if the plugin is packed.
Re: How to clear persisted state if application model has changed? [message #1002784 is a reply to message #1002726] Sat, 19 January 2013 12:07 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
We put a version string in the tags of the application. On startup we check if the string is what we would expect.
Re: How to clear persisted state if application model has changed? [message #1003448 is a reply to message #1002784] Mon, 21 January 2013 09:11 Go to previous messageGo to next message
Markus Wiederkehr is currently offline Markus WiederkehrFriend
Messages: 17
Registered: August 2012
Junior Member
@Christoph: thanks, but how do you access the application's tags? I mean the MApplication object has not been created at the time the @PostContextCreate method gets invoked. And in @ProcessAdditions it is already too late.
Re: How to clear persisted state if application model has changed? [message #1003514 is a reply to message #1003448] Mon, 21 January 2013 12:13 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
@Markus: Yeah. Now that you mention it, I remember stumbling over the same problem. At the end I settled for a complete restart of the application.

I use my own IApplication wrapper so that I can return IApplication.EXIT_RESTART from the start() method. That way, I can check the model in @ProcessAdditions. If the tags don't match, I save the need to reload the application model as a preference and then close the workbench. On startup, if this preference is set, I set the property E4Workbench.CLEAR_PERSISTED_STATE to "true" before I call E4Application.start().

A bit of a hack for sure Wink. If you find a nicer way, please share!
Re: How to clear persisted state if application model has changed? [message #1835975 is a reply to message #1002726] Thu, 17 December 2020 14:52 Go to previous messageGo to next message
Michael Dedina is currently offline Michael DedinaFriend
Messages: 6
Registered: January 2016
Junior Member
It seems problematic that Eclipse does not provide a built-in solution for this. If I ship a new version of my product to customers, and the model has changed in an incompatible way with the previous version, my customers will get the persisted old version of the model. If I add clearPersistedState to the configuration, my customers will lose the UI persistence feature.

Anyone know if Eclipse has added a fix for this in the years since this post?

Edit: On further investigation it seems the answer is no, but there is a bug open for it: https://bugs.eclipse.org/bugs/show_bug.cgi?id=430090

[Updated on: Thu, 17 December 2020 15:08]

Report message to a moderator

Re: How to clear persisted state if application model has changed? [message #1837045 is a reply to message #1835975] Thu, 21 January 2021 11:26 Go to previous message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 493
Registered: July 2009
Senior Member

I found that Window/New Window creates a new window with a fresh copy from the model. Subsequently closing the "old" window has the same effect as running with -clearPersistedState but without the associated complexity.

I think this is a promising path to the solution of this issue because all this could be done programmatically.

Also see bug 570471 https://bugs.eclipse.org/bugs/show_bug.cgi?id=570471
Previous Topic:Main toolbar enable state is not updating
Next Topic:Test a bundle with injected TranslationService
Goto Forum:
  


Current Time: Sat Nov 09 02:23:24 GMT 2024

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

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

Back to the top