GEF v2.0

org.eclipse.gef.commands
Class CompoundCommand

java.lang.Object
  |
  +--org.eclipse.gef.commands.AbstractCommand
        |
        +--org.eclipse.gef.commands.CompoundCommand
All Implemented Interfaces:
Command
Direct Known Subclasses:
ForwardUndoCompoundCommand

public class CompoundCommand
extends AbstractCommand

A command that can be used to combine multple commands into a single undoable action.


Field Summary
protected  List commandList
           
 
Fields inherited from interface org.eclipse.gef.commands.Command
copyright
 
Constructor Summary
CompoundCommand()
           
CompoundCommand(String desc)
           
 
Method Summary
 void add(Command command)
           
 boolean canExecute()
          canExecute method comment.
 boolean canUndo()
          canExecute method comment.
 void dispose()
          cancels the command.
 void execute()
          Execute the command.
 Collection getAffectedObjects()
          This returns the collection of things which this command wishes to present as the objects affected by the command.
 Object[] getChildren()
           
 List getCommands()
          Return a vector of child commands
 String getLabel()
          This returns a string suitable to represent the label that identifies this command.
 boolean isEmpty()
           
 void redo()
          redo the command.
 int size()
           
 void undo()
          Undo the command.
 Command unwrap()
          This returns one of three things: UnexecutableCommand.INSTANCE, if there are no commands, the one command, if there is exactly one command, or this, if there are multiple commands; this command is dispose()d in the first two cases.
 
Methods inherited from class org.eclipse.gef.commands.AbstractCommand
chain, getDebugLabel, getDescription, getResult, setDebugLabel, setDescription, setLabel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commandList

protected List commandList
Constructor Detail

CompoundCommand

public CompoundCommand()

CompoundCommand

public CompoundCommand(String desc)
Method Detail

add

public void add(Command command)

canExecute

public boolean canExecute()
canExecute method comment.
Overrides:
canExecute in class AbstractCommand

canUndo

public boolean canUndo()
canExecute method comment.
Overrides:
canUndo in class AbstractCommand

dispose

public void dispose()
cancels the command. For a compound command this means cancelling all of the commands that it contains.
Overrides:
dispose in class AbstractCommand

execute

public void execute()
Execute the command. For a compound command this means executing all of the commands that it contains.
Overrides:
execute in class AbstractCommand

getAffectedObjects

public Collection getAffectedObjects()
Description copied from interface: Command
This returns the collection of things which this command wishes to present as the objects affected by the command. Typically should could be used as the selection that should be highlighted to best illustrate the effect of the command. The result of calling this before an execute, redo, or undo is undefined. The result may be different after an undo than it is after an execute or redo, but the result should be the same (equivalent) after either an execute or redo.
Overrides:
getAffectedObjects in class AbstractCommand

getChildren

public Object[] getChildren()

getCommands

public List getCommands()
Return a vector of child commands
Returns:
java.util.List The child commands

getLabel

public String getLabel()
Description copied from interface: Command
This returns a string suitable to represent the label that identifies this command.
Overrides:
getLabel in class AbstractCommand

isEmpty

public boolean isEmpty()

redo

public void redo()
redo the command. For a compound command this means redoing all of the commands that it contains.
Overrides:
redo in class AbstractCommand

size

public int size()

undo

public void undo()
Undo the command. For a compound command this means undoing all of the commands that it contains.
Overrides:
undo in class AbstractCommand

unwrap

public Command unwrap()
This returns one of three things: UnexecutableCommand.INSTANCE, if there are no commands, the one command, if there is exactly one command, or this, if there are multiple commands; this command is dispose()d in the first two cases. You should only unwrap a compound command if you created it for that purpose, e.g.,
   CompoundCommand subcommands = new CompoundCommand();
   subcommands.append(x);
   if (condition) subcommands.append(y);
   Command result = subcommands.unwrap();
 
is a good way to create an efficient accumulated result.

GEF v2.0