Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be 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
Revision as of 08:04, 24 October 2009 by Remysuen.ca.ibm.com (Talk | contribs) (New page: 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 in...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

Initialization phase:

public void init(IViewSite site, IMemento memento) throws PartInitException {
  super.init(site, memento);
  fMemento = memento;
}

Construction phase:

public void createPartControl(Composite) {
  Label label = new Label(composite, SWT.LEAD);
  label.setText(fMemento.getString(LAST_USED_FS_PATH));
}

Disposal phase:

public void dispose() {
  fMemento.putString(LAST_USED_FS_PATH, label.getText());
  super.dispose();
}

Back to the top