Undo Redo Design: Difference between revisions
imported>Aurelien New page: == Eclipse History == To implement the history, we have based mechanism History provided by Eclipse [http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.isv/reference... |
imported>Laurent No edit summary |
||
Line 1: | Line 1: | ||
== | == History Mechanism == | ||
Undo / Redo is built on top of the History mechanism provided by Eclipse [http://help.eclipse.org/help32/topic/org.eclipse.platform.doc.isv/guide/wrkAdv_undo.htm]. It is composed of class History and interface IUndoableOperation. Each operation has three methods to act on the database: execute(), undo() and redo(). | |||
Operations are added to the history. The execute() operation is called during addition. Then, operations undo() and redo() are executed by the history when an Undo or Redo action is performed. | |||
As each file has its own history, every operation has a context, which is the name of the file. The History class just manages the history of all files. | |||
== Operations == | == Operations == | ||
First, we have to make objects that | First, we have to make objects that implement IUndoableOperation for each transaction on the database. We use the composite model so that each operation is composed of basic operations (add an element, delete an element, change an attribute ,...). The operations are created by a factory. | ||
Some operations are dependent on an element in their execution ( | Some operations are dependent on an element in their execution (e.g., change an attibute). This may not be known when recording the operation in the History. To do this, operations have methods getCreatedElement() and setParent() which are called by execute() | ||
Then to ensure | Then to ensure atomicity with respects to the Rodin database, composite operations (TreeOperation) are encapsulated in a class AtomicOperation. It only delegate its methods but it encapsulates in the RodinCore.run(). | ||
Revision as of 17:19, 20 October 2008
History Mechanism
Undo / Redo is built on top of the History mechanism provided by Eclipse [1]. It is composed of class History and interface IUndoableOperation. Each operation has three methods to act on the database: execute(), undo() and redo().
Operations are added to the history. The execute() operation is called during addition. Then, operations undo() and redo() are executed by the history when an Undo or Redo action is performed.
As each file has its own history, every operation has a context, which is the name of the file. The History class just manages the history of all files.
Operations
First, we have to make objects that implement IUndoableOperation for each transaction on the database. We use the composite model so that each operation is composed of basic operations (add an element, delete an element, change an attribute ,...). The operations are created by a factory.
Some operations are dependent on an element in their execution (e.g., change an attibute). This may not be known when recording the operation in the History. To do this, operations have methods getCreatedElement() and setParent() which are called by execute()
Then to ensure atomicity with respects to the Rodin database, composite operations (TreeOperation) are encapsulated in a class AtomicOperation. It only delegate its methods but it encapsulates in the RodinCore.run().
Factory
The interface provides to clients consists of three class:
- OperationFactory
- History
- AtomicOperation
The factory is not instantiable and its methods are static. History implements the pattern Singleton and delegates to IOperationHistory.