I am using the PostContextCreate
part of the life cycle in an e4 RCP application to create the back-end "business logic" part of my application. I then inject it into the context using an IEclipseContext
. I now have a requirement to persist some business logic configuration options between executions of my application. I have some questions:
MContext
) would be really useful here, a straightforward Map<String,String>
sounds ideal for my simple requirements, but how can I get them in PostContextCreate
?clearPersistedState
set to true
? (I'm guessing not).clearPersistedState
off then will it try and persist the other stuff that I injected into the context?Or am I going about this all wrong? Any suggestions would be welcome. I may just give up and read/write my own properties file.
I think the Map
returned by MApplicationElement.getPersistedState()
is intended to be used for persistent data. This will be cleared by -clearPersistedState.
The PostContextCreate method of the life cycle is run quite early in the startup and not everything is available at this point. So you might have to wait for the app startup complete event (UIEvents.UILifeCycle.APP_STARTUP_COMPLETE
) before accessing the persisted state data.
You can always use the traditional Platform.getStateLocation(bundle)
to get a location in the workspace .metadata to store arbitrary data. This is not touched by clearPersistedState.
Update:
To subscribe to the app startup complete:
@PostContextCreate
public void postContextCreate(IEventBroker eventBroker)
{
eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new AppStartupCompleteEventHandler());
}
private static final class AppStartupCompleteEventHandler implements EventHandler
{
@Override
public void handleEvent(final Event event)
{
... your code here
}
}