Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

E4/EAS/State Persistence

< E4‎ | EAS

A component should be able to persist its state in a platform-independent way that allows itself to present itself to the user much in the same way that the user last left it. These may include, but are not limited to, layout, tree expansion and checkbox state, and dialog positions.

Eclipse 3.x API

In Eclipse 3.x, state persistence is usually achieved by using the IMemento or the IDialogSettings interface. Classes can put whatever they want in there when they've been disposed of and when they are constructed again later, they are passed this information so that they can set themselves up in the same way that they were last left.

Critique:

  • The API is currently defined in a UI bundle and as such is not available to lower level bundles.
  • IMemento is flagged with @noimplement so it is not possible for clients to provide their own implementation for storing information.

Initialization phase

private String fPath;
 
public void init(IViewSite site, IMemento memento) throws PartInitException {
  super.init(site, memento);
  fPath = memento.getString(LAST_USED_FS_PATH);
}

Construction phase

private Text fPathText;
 
public void createPartControl(Composite) {
  fPathText = new Text(composite, SWT.LEAD);
  fPathText.setText(fPath);
  fPathText.addListener(SWT.Modify, new Listener() {
    public void handleEvent(Event event) {
      fPath = fPathText.getText();
    }
  });
}

Storage phase

public void saveState(IMemento memento) {
  super.saveState(memento);
  memento.putString(LAST_USED_FS_PATH, fPath);
}

e4 (Java)

At the time of this writing, the MContribution model object defines a getPersistedState() method which returns a String.

Back to the top