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.
Difference between revisions of "E4/EAS/Saveable Life Cycle"
Line 41: | Line 41: | ||
} | } | ||
}); | }); | ||
+ | </source> | ||
+ | |||
+ | ==e4 (Java)== | ||
+ | ===Saveable declaration=== | ||
+ | <source lang="java"> | ||
+ | public class MyPart { | ||
+ | |||
+ | @Inject | ||
+ | private MDirtyable dirtyable; | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | ===Dirty state modification=== | ||
+ | <source lang="java"> | ||
+ | public void setDirty(boolean dirty) { | ||
+ | dirtyable.setDirty(dirty); | ||
+ | } | ||
</source> | </source> |
Revision as of 16:14, 4 November 2009
When a user modifies something, a component may choose to notify the user of this in some way. This state transition from "unmodified" to "modified" is known as the "dirty state". When something is dirty, it means that the user has interacted with the object in some way. It may or may not actually be different from the original object but is an indicator to the user that something may be different.
One example of where an editor may be dirty but no actually have its contents be different from the file on disk is where a user has inserted a character and then removed it from the document. Both the insertion and deletion operation are modification operations even if the contents are identical to what's on the disk. However, if the user were to undo the insertion operation instead of using a deletion operation to remove the change, then the dirty state should be cleared.
Contents
Eclipse 3.x API
In Eclipse 3.x, the visual cue to the user that a workbench part is dirty is by appending the asterisk character ('*') in front of the part's title. So if the original file was called 'Main.java' and it was edited by the user in the text editor, the title in the tab would switch from 'Main.java' to '*Main.java'. Workbench parts that wish to expose this functionality do so by implementing the org.eclipse.ui.ISaveablePart interface.
Saveable declaration
public class ModelTransformationView extends ViewPart implements ISaveablePart { private boolean fDirty = false; /** * Alters the dirty state of this part and notifies the workbench * of the change. */ private void setDirty(boolean dirty) { fDirty = dirty; firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY); } public boolean isDirty() { return fDirty; } /* Other code not included... */ }
Dirty state modification
fStateCheckbox.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { // modify the model based on what the user selected // in the UI fModel.setState(fStateCheckbox.getSelection()); // send out a dirty notification setDirty(true); } });
e4 (Java)
Saveable declaration
public class MyPart { @Inject private MDirtyable dirtyable; }
Dirty state modification
public void setDirty(boolean dirty) { dirtyable.setDirty(dirty); }