Eclipse GEF
2.1

org.eclipse.gef.commands
Class CommandStack

java.lang.Object
  |
  +--org.eclipse.gef.commands.CommandStack

public class CommandStack
extends Object

A default implementation for the CommandStack interface.


Field Summary
protected  List listeners
          the list of CommandStackListeners
 
Constructor Summary
CommandStack()
          Constructs a command stack.
 
Method Summary
 void addCommandStackListener(CommandStackListener listener)
          Adds the specified listener.
 boolean canRedo()
           
 boolean canUndo()
           
 void dispose()
          This will dispose() all the commands in both the undo and redo stack.
 void execute(Command command)
          Executes the specified Command if it is executable.
 void flush()
          Flushes the entire stack and resets the save location to zero.
 Object[] getCommands()
           
 Command getRedoCommand()
          Peeks at the top of the redo stack.
 Command getUndoCommand()
          Peeks at the top of the undo stack.
 int getUndoLimit()
          Returns the undo limit.
 boolean isDirty()
           
 void markSaveLocation()
           
protected  void notifyListeners()
          Sends notification to all CommandStackListeners.
 void redo()
          Calls redo on the Command at the top of the redo stack, and pushes that Command onto the undo stack.
 void removeCommandStackListener(CommandStackListener listener)
          Removes the first occurance of the specified listener.
 void setUndoLimit(int undoLimit)
          Sets the undo limit.
 void undo()
          Undoes the most recently executed (or redone) Command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

protected List listeners
the list of CommandStackListeners

Constructor Detail

CommandStack

public CommandStack()
Constructs a command stack.

Method Detail

addCommandStackListener

public void addCommandStackListener(CommandStackListener listener)
Adds the specified listener. Multiple adds will result in multiple notifications.

Parameters:
listener - the listener

canRedo

public boolean canRedo()
Returns:
true if it is appropriate to call redo().

canUndo

public boolean canUndo()
Returns:
true if undo() can be called

execute

public void execute(Command command)
Executes the specified Command if it is executable. Flushes the redo stack.

Parameters:
command - the Command to execute

dispose

public void dispose()
This will dispose() all the commands in both the undo and redo stack. Both stacks will be empty afterwards.


flush

public void flush()
Flushes the entire stack and resets the save location to zero. This method might be called when performing "revert to saved".


getCommands

public Object[] getCommands()
Returns:
an array containing all commands in the order they were executed

getRedoCommand

public Command getRedoCommand()
Peeks at the top of the redo stack. This is useful for describing to the User what will be redone. The returned Command has a label describing it.

Returns:
the top of the redo stack, which may be null

getUndoCommand

public Command getUndoCommand()
Peeks at the top of the undo stack. This is useful for describing to the User what will be undone. The returned Command has a label describing it.

Returns:
the top of the undo stack, which may be null

getUndoLimit

public int getUndoLimit()
Returns the undo limit. The undo limit is the maximum number of atomic operations that the User can undo. -1 is used to indicate no limit.

Returns:
the undo limit

isDirty

public boolean isDirty()

markSaveLocation

public void markSaveLocation()

notifyListeners

protected void notifyListeners()
Sends notification to all CommandStackListeners.


redo

public void redo()
Calls redo on the Command at the top of the redo stack, and pushes that Command onto the undo stack. This method should only be called when canUndo() returns true.


removeCommandStackListener

public void removeCommandStackListener(CommandStackListener listener)
Removes the first occurance of the specified listener.

Parameters:
listener - the listener

setUndoLimit

public void setUndoLimit(int undoLimit)
Sets the undo limit. The undo limit is the maximum number of atomic operations that the User can undo. -1 is used to indicate no limit.

Parameters:
undoLimit - the undo limit

undo

public void undo()
Undoes the most recently executed (or redone) Command. The Command is popped from the undo stack to and pushed onto the redo stack. This method should only be called when canUndo() returns true.


Eclipse GEF
2.1

Copyright (c) IBM Corp. and others 2000, 2003. All Rights Reserved.