Blog
Storing custom UI-State in e4+JavaFX
I guess many e4 developers asked: How do I restore custom UI-State? Most likely answer they get is: Use persistedState of org.eclipse.e4.ui.model.application.MApplicationElement who is a Map<String,String> What a bad bad idea! This makes your nice UI code who uses dependency inject depend on the e4 application model! What a bad bad idea! For all users of e4 & JavaFX I'm glad there's a solution now named org.eclipse.fx.core.Memento who allows you to store simple and complex states without getting a dependency on the e4 framework:
public class MyPart {
@PostConstruct
public void init(Memento state) {
int selectionId = state.get("selectionId",-1);
ComplexObjectState complexState = state.get("complexObject",null);
}
@PersistState
public void saveUIState(Memento state) {
state.put("selectionId",getSelectionId());
state.put("complexObject",getComplexObject(),ObjectSerializer.JAXB_SERIALIZER);
}
}
For more information on the cool stuff you get from e4 & JavaFX visit our wiki.