Skip to main content



      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 12:48 Go to next message
Eclipse UserFriend
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 03:12 Go to previous messageGo to next message
Eclipse UserFriend
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 07:07 Go to previous messageGo to next message
Eclipse UserFriend
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 04:11 Go to previous messageGo to next message
Eclipse UserFriend
@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 07:13 Go to previous messageGo to next message
Eclipse UserFriend
@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 09:52 Go to previous messageGo to next message
Eclipse UserFriend
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 10:08] by Moderator

Re: How to clear persisted state if application model has changed? [message #1837045 is a reply to message #1835975] Thu, 21 January 2021 06:26 Go to previous message
Eclipse UserFriend
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: Fri Jun 20 10:51:39 EDT 2025

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

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

Back to the top