Package org.eclipse.gef.commands
Class CompoundCommand
- java.lang.Object
-
- org.eclipse.gef.commands.Command
-
- org.eclipse.gef.commands.CompoundCommand
-
- Direct Known Subclasses:
ForwardUndoCompoundCommand
public class CompoundCommand extends Command
An aggregation of multipleCommands. ACompoundCommandis executable if all of its contained Commands are executable, and it has at least one contained Command. The same is true for undo. When undo is called, the contained Commands are undone in the reverse order in which they were executed.An empty CompoundCommand is not executable.
A CompoundCommand can be
unwrapped. Unwrapping returns the simplest equivalent form of the CompoundCommand. So, if a CompoundCommand contains just one Command, that Command is returned.
-
-
Constructor Summary
Constructors Constructor Description CompoundCommand()Constructs an empty CompoundCommandCompoundCommand(java.lang.String label)Constructs an empty CompoundCommand with the specified label.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Command command)Adds the specified command if it is notnull.booleancanExecute()booleancanRedo()booleancanUndo()voiddispose()Disposes all contained Commands.voidexecute()Execute the command.For a compound command this means executing all of the commands that it contains.java.lang.Object[]getChildren()This is useful when implementingITreeContentProvider.getChildren(Object)to display the Command's nested structure.java.util.ListgetCommands()java.lang.StringgetLabel()booleanisEmpty()voidredo()Re-executes the Command.intsize()voidundo()Undoes the changes performed duringexecute().Commandunwrap()Returns the simplest form of this Command that is equivalent.-
Methods inherited from class org.eclipse.gef.commands.Command
chain, getDebugLabel, setDebugLabel, setLabel
-
-
-
-
Method Detail
-
add
public void add(Command command)
Adds the specified command if it is notnull.- Parameters:
command-nullor a Command
-
canRedo
public boolean canRedo()
- Overrides:
canRedoin classCommand- Returns:
trueif the command can be redone. This method should only be called afterundo()has been called.- Since:
- 3.10
- See Also:
Command.canRedo()
-
canExecute
public boolean canExecute()
- Overrides:
canExecutein classCommand- Returns:
trueif the command can be executed- See Also:
Command.canExecute()
-
canUndo
public boolean canUndo()
- Overrides:
canUndoin classCommand- Returns:
trueif the command can be undone. This method should only be called afterexecute()orredo()has been called.- See Also:
Command.canUndo()
-
dispose
public void dispose()
Disposes all contained Commands.- Overrides:
disposein classCommand- See Also:
Command.dispose()
-
execute
public void execute()
Execute the command.For a compound command this means executing all of the commands that it contains.
-
getChildren
public java.lang.Object[] getChildren()
This is useful when implementingITreeContentProvider.getChildren(Object)to display the Command's nested structure.- Returns:
- returns the Commands as an array of Objects.
-
getCommands
public java.util.List getCommands()
- Returns:
- the List of contained Commands
-
getLabel
public java.lang.String getLabel()
- Overrides:
getLabelin classCommand- Returns:
- a String used to describe this command to the User
- See Also:
Command.getLabel()
-
isEmpty
public boolean isEmpty()
- Returns:
trueif the CompoundCommand is empty
-
redo
public void redo()
Description copied from class:CommandRe-executes the Command. This method should only be called afterundo()has been called.- Overrides:
redoin classCommand- See Also:
Command.redo()
-
size
public int size()
- Returns:
- the number of contained Commands
-
undo
public void undo()
Description copied from class:CommandUndoes the changes performed duringexecute(). This method should only be called afterexecutehas been called, and only whencanUndo()returnstrue.- Overrides:
undoin classCommand- See Also:
Command.undo()
-
unwrap
public Command unwrap()
Returns the simplest form of this Command that is equivalent. This is useful for removing unnecessary nesting of Commands.- Returns:
- the simplest form of this Command that is equivalent
-
-