GEF v2.0

org.eclipse.gef.commands
Class DefaultCommandStack

java.lang.Object
  |
  +--org.eclipse.gef.commands.DefaultCommandStack
All Implemented Interfaces:
CommandStack

public class DefaultCommandStack
extends Object
implements CommandStack

A default implementation for the CommandStack interface.


Field Summary
protected  List listeners
           
protected  Command mostRecentCommand
           
protected  int saveIndex
           
 
Fields inherited from interface org.eclipse.gef.commands.CommandStack
copyright
 
Constructor Summary
DefaultCommandStack()
          Default constructor.
 
Method Summary
 void addCommandStackListener(CommandStackListener listener)
          Adds a listener to this CommandStack.
 boolean canRedo()
          Returns true if there is a Command to redo.
 boolean canRedoCommand(Command command)
          Returns true if given Command can be redone.
 boolean canUndo()
          Returns true if the last Command executed can be undone.
 boolean canUndoCommand(Command command)
          Returns true if given Command can be undone.
 void execute(Command command)
          Executes the given Command if it can execute.
 void flush()
          Clears both the undo and redo stacks, then sends a notification to any object listening to the CommandStack.
protected  void flushRedo()
          Clears the redo stack.
protected  void flushUndo()
          Clears the undo stack.
 Object[] getCommands()
          Returns an array containing the commands in both stacks.
 Command getMostRecentCommand()
          Returns the most recently executed command.
 Command getRedoCommand()
          Returns the command at the top of the redo stack.
 Command getUndoCommand()
          Returns the next command to be undone.
 boolean isSaveNeeded()
          Returns true if the model needs to be saved.
protected  void notifyListeners()
          Sends a notification to any object listening to this CommandStack.
 void redo()
          Executes the last undone Command.
 void removeCommandStackListener(CommandStackListener listener)
          Removes the given CommandStackListener.
 void saveIsDone()
          Flushes the undo and redo stacks.
 void undo()
          Undoes the last executed Command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mostRecentCommand

protected Command mostRecentCommand

listeners

protected List listeners

saveIndex

protected int saveIndex
Constructor Detail

DefaultCommandStack

public DefaultCommandStack()
Default constructor.
Method Detail

addCommandStackListener

public void addCommandStackListener(CommandStackListener listener)
Adds a listener to this CommandStack.
Specified by:
addCommandStackListener in interface CommandStack
Parameters:
listener - The Object listening to this CommandStack.

canRedo

public boolean canRedo()
Returns true if there is a Command to redo.
Specified by:
canRedo in interface CommandStack
Returns:
true if there is a Command to redo.

canRedoCommand

public boolean canRedoCommand(Command command)
Returns true if given Command can be redone.
Returns:
true if given Command can be redone.

canUndo

public boolean canUndo()
Returns true if the last Command executed can be undone.
Specified by:
canUndo in interface CommandStack
Returns:
true if the last Command executed can be undone.

canUndoCommand

public boolean canUndoCommand(Command command)
Returns true if given Command can be undone.
Returns:
true if given Command can be undone.

execute

public void execute(Command command)
Executes the given Command if it can execute.
Specified by:
execute in interface CommandStack
Parameters:
command - The Command to execute.

flush

public void flush()
Clears both the undo and redo stacks, then sends a notification to any object listening to the CommandStack.
Specified by:
flush in interface CommandStack

flushRedo

protected void flushRedo()
Clears the redo stack.

flushUndo

protected void flushUndo()
Clears the undo stack.

getCommands

public Object[] getCommands()
Returns an array containing the commands in both stacks.
Returns:
An Object array containing the commands in the stacks.

getMostRecentCommand

public Command getMostRecentCommand()
Returns the most recently executed command.
Specified by:
getMostRecentCommand in interface CommandStack
Returns:
The most recently executed command.

getRedoCommand

public Command getRedoCommand()
Returns the command at the top of the redo stack.
Specified by:
getRedoCommand in interface CommandStack
Returns:
The next command to be redone.

getUndoCommand

public Command getUndoCommand()
Returns the next command to be undone.
Specified by:
getUndoCommand in interface CommandStack

isSaveNeeded

public boolean isSaveNeeded()
Returns true if the model needs to be saved.
Returns:
true if the model needs to be saved.

notifyListeners

protected void notifyListeners()
Sends a notification to any object listening to this CommandStack.

redo

public void redo()
Executes the last undone Command.
Specified by:
redo in interface CommandStack

removeCommandStackListener

public void removeCommandStackListener(CommandStackListener listener)
Removes the given CommandStackListener.
Specified by:
removeCommandStackListener in interface CommandStack
Parameters:
listener - The object to be removed from the list of listeners.

saveIsDone

public void saveIsDone()
Flushes the undo and redo stacks.

undo

public void undo()
Undoes the last executed Command.
Specified by:
undo in interface CommandStack

GEF v2.0