Undo Redo Design: Difference between revisions
imported>Mathieu m typo + title change |
imported>Mathieu mNo edit summary |
||
Line 26: | Line 26: | ||
[[Category:Design]] | [[Category:Design]] |
Latest revision as of 09:27, 4 March 2009
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:
,
and
. Database changes are added to the history. The
operation is called during addition. Then, operations
and
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.
Implementation for Rodin
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 attribute). This may not be known when recording the operation in the History. To do this, operations have methods
and
which are called by
.
Then to ensure atomicity with respects to the Rodin database, composite operations (TreeOperation) are encapsulated in a class AtomicOperation. It only delegates its methods but it encapsulates in the RodinCore.run().
Available Interface
The interface provided to clients consists of three class:
- OperationFactory
- History
- AtomicOperation
The factory may not be instantiated and its methods are static. History implements the pattern Singleton and delegates to IOperationHistory.