01: package net.sf.jmoney.model2;
02:
03: import org.eclipse.core.commands.ExecutionException;
04: import org.eclipse.core.commands.operations.AbstractOperation;
05: import org.eclipse.core.runtime.IAdaptable;
06: import org.eclipse.core.runtime.IProgressMonitor;
07: import org.eclipse.core.runtime.IStatus;
08: import org.eclipse.core.runtime.Status;
09:
10: public abstract class AbstractDataOperation extends AbstractOperation {
11:
12: private Session session;
13:
14: public AbstractDataOperation(Session session, String label) {
15: super (label);
16: this .session = session;
17: }
18:
19: /**
20: * The changes that need to be undone to 'undo' this operation (i.e. these
21: * are the changes made when the operation was executed or last redone), or
22: * null if this operation has not yet been executed or has been undone.
23: */
24: private ChangeManager.UndoableChange redoChanges = null;
25:
26: /**
27: * The changes that need to be undone to 'redo' this operation (i.e. these
28: * are the changes made when the operation was last undone), or null if this
29: * operation has not yet been executed or has not yet been undone, or if
30: * this operation was redone since it was last undone.
31: */
32: private ChangeManager.UndoableChange undoChanges = null;
33:
34: @Override
35: public IStatus execute(IProgressMonitor monitor, IAdaptable info)
36: throws ExecutionException {
37: session.getChangeManager().setUndoableChange();
38:
39: execute();
40:
41: redoChanges = session.getChangeManager().takeUndoableChange();
42:
43: return Status.OK_STATUS;
44: }
45:
46: @Override
47: public IStatus redo(IProgressMonitor monitor, IAdaptable info)
48: throws ExecutionException {
49: session.getChangeManager().setUndoableChange();
50:
51: undoChanges.undoChanges();
52: undoChanges = null;
53:
54: redoChanges = session.getChangeManager().takeUndoableChange();
55:
56: return Status.OK_STATUS;
57: }
58:
59: @Override
60: public IStatus undo(IProgressMonitor monitor, IAdaptable info)
61: throws ExecutionException {
62: session.getChangeManager().setUndoableChange();
63:
64: redoChanges.undoChanges();
65: redoChanges = null;
66:
67: undoChanges = session.getChangeManager().takeUndoableChange();
68:
69: return Status.OK_STATUS;
70: }
71:
72: public abstract IStatus execute() throws ExecutionException;
73: }
|