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

Difference between revisions of "E4/EAS/State Persistence"

< E4‎ | EAS
(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...)
 
(Eclipse 3.x API)
Line 4: Line 4:
 
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.
 
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:
+
===Initialization phase===
 
<source lang="java">
 
<source lang="java">
 
public void init(IViewSite site, IMemento memento) throws PartInitException {
 
public void init(IViewSite site, IMemento memento) throws PartInitException {
Line 12: Line 12:
 
</source>
 
</source>
  
Construction phase:
+
===Construction phase===
 
<source lang="java">
 
<source lang="java">
 
public void createPartControl(Composite) {
 
public void createPartControl(Composite) {
Line 20: Line 20:
 
</source>
 
</source>
  
Disposal phase:
+
===Disposal phase===
 
<source lang="java">
 
<source lang="java">
 
public void dispose() {
 
public void dispose() {
Line 27: Line 27:
 
}
 
}
 
</source>
 
</source>
 +
 +
==e4 (Java)==
 +
At the time of this writing, the MContribution model object defines a getPersistedState() method which returns a String.

Revision as of 13:52, 24 October 2009

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();
}

e4 (Java)

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

Back to the top