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.

Advertisements
This entry was posted in e(fx)clipse and tagged , . Bookmark the permalink.

2 Responses to Storing custom UI-State in e4+JavaFX

  1. Mario says:

    Hey,
    I have probleme to implement memento pattern for my application !!
    I need your help please.
    Thank you

    • Tom Schindl says:

      Support is provided through public forums. If this is not good enough BestSolution.at provides premium support contracts.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s