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 12:48 Go to next message
Markus Wiederkehr is currently offline Markus Wiederkehr
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 03:12 Go to previous messageGo to next message
Frank Benoit is currently offline Frank Benoit
Messages: 45
Registered: July 2009
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 07:07 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 297
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 04:11 Go to previous messageGo to next message
Markus Wiederkehr is currently offline Markus Wiederkehr
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 07:13 Go to previous message
Christoph Keimel is currently offline Christoph Keimel
Messages: 297
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!
Previous Topic:DI : Define custom parent Composite for inject
Next Topic:How to do ContextInjectionFactory.make with paramatrized constructor?
Goto Forum:
  


Current Time: Thu Apr 17 20:54:40 EDT 2014

Powered by FUDForum. Page generated in 0.01625 seconds