GEF v2.0

org.eclipse.gef.commands
Class AbstractCommand

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

public abstract class AbstractCommand
extends Object
implements Command


Fields inherited from interface org.eclipse.gef.commands.Command
copyright
 
Constructor Summary
AbstractCommand()
           
AbstractCommand(String label)
           
 
Method Summary
 boolean canExecute()
          This indicates whether the comamad is valid to execute.
 boolean canUndo()
          This returns whether the command can be undone.
 Command chain(Command command)
          This logically chains the given command to this command, by returning a command that represents the composition.
 void dispose()
          This is called to indicate that the command will never be used again.
 void execute()
          This will perform the command activity required for the effect.
 Collection getAffectedObjects()
          This returns the collection of things which this command wishes to present as the objects affected by the command.
 String getDebugLabel()
           
 String getDescription()
          This returns a string suitable to help describe the effect of this command.
 String getLabel()
          This returns a string suitable to represent the label that identifies this command.
 Collection getResult()
          This returns collection of things which this command wishes to present as it's result.
 void redo()
          This will again perform the command activity required to redo the effect after undoing the effect.
 void setDebugLabel(String label)
           
 void setDescription(String label)
           
 void setLabel(String label)
           
 void undo()
          This will perform the command activity required to undo the effects of a preceding execute (or redo).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCommand

public AbstractCommand()

AbstractCommand

public AbstractCommand(String label)
Method Detail

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.
Specified by:
getAffectedObjects in interface Command

getDebugLabel

public String getDebugLabel()

getDescription

public String getDescription()
Description copied from interface: Command
This returns a string suitable to help describe the effect of this command.
Specified by:
getDescription in interface Command

getLabel

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

getResult

public final Collection getResult()
Description copied from interface: Command
This returns collection of things which this command wishes to present as it's result. The result of calling this before an execute or redo, or after an undo, is undefined.
Specified by:
getResult in interface Command

canExecute

public boolean canExecute()
Description copied from interface: Command
This indicates whether the comamad is valid to execute. The UnexecutableCommand.INSTANCE.canExecute() always returns false. This must be called before calling execute.
Specified by:
canExecute in interface Command

canUndo

public boolean canUndo()
Description copied from interface: Command
This returns whether the command can be undone. The result of calling this before execute is well defined, but the result of calling this before calling canExecute is undefined, i.e., a command that retuns false for canExecute may return true for canUndo, even though that is a contradiction.
Specified by:
canUndo in interface Command

chain

public Command chain(Command command)
Description copied from interface: Command
This logically chains the given command to this command, by returning a command that represents the composition. The resulting command may just be this, if this command is capabable of composition. Otherwise, it will be a new command created to compose the two.

Instead of the following pattern of usage

   Command result = x;
   if (condition) result = result.chain(y);
 
you should consider using a CompoundCommand and using CompoundCommand.unwrap() to optimize the result:
   CompoundCommand subcommands = new CompoundCommand();
   subcommands.append(x);
   if (condition) subcommands.append(y);
   Command result = subcommands.unwrap();
 
This gives you more control over how the compound command composes it's result and affected objects.
Specified by:
chain in interface Command

dispose

public void dispose()
Description copied from interface: Command
This is called to indicate that the command will never be used again. Calling any other method after this one has undefined results.
Specified by:
dispose in interface Command

execute

public void execute()
Description copied from interface: Command
This will perform the command activity required for the effect. The effect of calling execute when canExecute returns false, or when canExecute hasn't been called, is undefined.
Specified by:
execute in interface Command

redo

public void redo()
Description copied from interface: Command
This will again perform the command activity required to redo the effect after undoing the effect. The effect, if any, of calling redo before undo is called is undefined. Note that if you implement redo to call execute then any derived class will be restricted to by that decision also.
Specified by:
redo in interface Command

setDebugLabel

public void setDebugLabel(String label)

setDescription

public void setDescription(String label)

setLabel

public void setLabel(String label)

undo

public void undo()
Description copied from interface: Command
This will perform the command activity required to undo the effects of a preceding execute (or redo). The effect, if any, of calling undo before execute or redo have been called, or when canUndo returns false, is undefined.
Specified by:
undo in interface Command

GEF v2.0