Undo management

While working with a diagram, you can undo and redo actions. These operations are available in the DiagramEditor. They not only support all standard changes that can be applied through the editing features, they also support any basic property change applied programmatically, with the corresponding undo object registration. More complex changes can also be supported through customized operations.

UndoManager

This object is available through the getUndoManager method and manages the stacks of actions that can be undone and redone. This component not only provides a basic list of methods to manage these stacks, but it also maintains a complete dictionary of GraphElements by its IDs and their replacements when necessary (during removes on undo, and consecutive redo). The undo manager has these methods:
  • getDiagram: gets the diagram.
  • addAction: adds an action to the undo action stack (clearing the redo stack).
  • undoAction: unstacks an action from the undo stack, applying the undo operation and adding it to the redo stack.
  • redoAction: unstacks an action from the redo stack and applies the redo operation.
  • getUndoStack: gets a copy of the undo action stack.
  • getRedoStack: gets a copy of the redo action stack.
  • setMaximumStackSize: sets the maximum stack size. If null, the size is unlimited.
  • getMaximumStackSize: gets the maximum stack size.
  • getRegisteredGfx: gets the registered GFX corresponding to the given ID. Searches the replacement if necessary.
  • registerGfxReplacement: registers when a GFX ID is replaced by another (when a GFX is removed and a replacement is created, with a new ID)
  • getRegisteredGfxReplacement: gets the registered replacement for the given GFX ID. Searches recursively to find the last replacement. If no replacement is registered, the given GFX ID is returned.
  • getRegisteredParent: returns the graph parent for the given ID. If the ID corresponds to a subgraph, the inner graph is returned.

Undo Action

The Action class is the basic class that contains the undo operation. It provides the basic interface for any undo action and has the following methods:
  • undo: applies the undo function.
  • redo: applies the redo function.
  • getLabel: gets the action label for UI printing.
  • getUndoManager: gets the undoManager that is automatically activated when added to the undo stack.
  • isUndoing: returns true if the undo method is running.
  • isRedoing: returns true if the redo method is running.
The following subset of classes inherit from Action and are useful for customizations or creation of new actions.

SimpleAction

The SimpleAction class is for simple undo actions. It is used to undo and redo basic properties that can be changed by assigning variables or calling a method with a simple argument. Use theSimpleAction class to undo customized editing actions. The move undo action uses this class to undo and redo movement action through the following methods:
  • setOldValue: sets the old value.
  • setNewValue: sets the new value.
  • getOldValue: gets the old value, cloning the set value if the clone function is previously set.
  • getNewValue: gets the new value, cloning the set value if the clone function is previously set.
  • setModifiedElementId: sets the modified object.
  • getModifiedElementId: gets the modified object.
  • getModifiedElement: gets the modified GFX element, or its replacements, if necessary.
  • setMethodOrProperty: sets the property or method name to be modified.
  • setCloneFunction: sets the clone function to clone the value before the change action.

MultipleAction

The MultipleAction class groups a list of UndoActions. It groups a set of Actions in a single complex one and executes every added action in sequential order during the redo and undo operations.

ReparentingAction

The ReparentingAction class allows you to undo and redo any reparenting action. Use it in combination with MultipleAction to create any undo or redo action that involves a reparenting.

UserCustomizedAction

The UserCustomizedAction class is the base class for all actions that do not come with the DiagramEditor. However, it needs to be customized to obtain its complete expected behavior. You can extend it by using DropAction, ConnectAction, and ReConnectAction.