Search
Actions and Commands

Undoable interactive actions and programmatic commands that can be carried out by JDiagram are represented by Command subclasses. The Command class provides the necessary interface to execute, undo or redo actions. In some cases, you will have to implement these methods in derived classes, but you should not call them directly. Use the undo or redo methods of the UndoManager to undo or redo a command. The UndoManager methods call the respective Command methods and in addition update the state of the command history and the Diagram.

The following JDiagram classes are derived from Command:

Command

Description

AddGroupCmd
RemoveGroupCmd

Creates a new hierarchical group.
Destroys a group.

AddItemCmd
RemoveItemCmd
ChangeItemCmd

Adds a new item to the diagram.
Removes an item from the diagram.
Handles undo/redo of item changes.

CompositeCmd

Allows several actions to be undo and redone at the same time.

AddToContainerCmd

Adds an item to a container.

FoldContainerCmd

Folds a container node.

GroupAttachCmd

Attaches an item to a group.

GroupDetachCmd

Detaches an item from a group.

ModifyItemCmd

Moves or resizes an item.

RedimTableCmd

Change number of table's columns or rows.

ExpandItemCmd

Expands or collapses a tree of items.

ScrollTableCmd

Scrolls table's rows.

ExpandHeaderRowCmd

Expands or collapses tables sections.

RemoveFromContainerCmd

Removes an item from the container node.

Instances of most of these classes are created implicitly by JDiagram in response to users' actions or method calls. You might need to explicitly instantiate only ChangeItemCmd - to undo or redo property changes - and CompositeCmd - to present several actions as single undoable operation.

The data of your application might be tightly integrated in JDiagram diagrams, for example through tag objects. In these cases, JDiagram cannot detect undo or redo changes to your data. To enable undo of such changes, you must inherit the Command class and implement your versions of the execute, undo and redo methods. To record your own action in the undo/redo history, call the executeCommand method of Diagram.