Modelers

org.topcased.modeler.commands
Class CommandStack

java.lang.Object
  extended by org.eclipse.gef.commands.CommandStack
      extended by org.topcased.modeler.commands.CommandStack
Direct Known Subclasses:
AdvancedCommandStack

public class CommandStack
extends org.eclipse.gef.commands.CommandStack

Copy of the GEF command stack with some bug fixes. Waiting the bug #39386 will be fixed.


Field Summary
protected  java.util.List listeners
          Deprecated. This field should not be referenced, use notifyListeners()
static int POST_EXECUTE
          Constant indicating notification after a command has been executed (value is 8).
static int POST_REDO
          Constant indicating notification after a command has been redone (value is 16).
static int POST_UNDO
          Constant indicating notification after a command has been undone (value is 32).
static int PRE_EXECUTE
          Constant indicating notification prior to executing a command (value is 1).
static int PRE_REDO
          Constant indicating notification prior to redoing a command (value is 2).
static int PRE_UNDO
          Constant indicating notification prior to undoing a command (value is 4).
 
Constructor Summary
CommandStack()
          Constructs a new command stack.
 
Method Summary
 void addCommandStackEventListener(org.eclipse.gef.commands.CommandStackEventListener listener)
          Appends the listener to the list of command stack listeners.
 void addCommandStackListener(org.eclipse.gef.commands.CommandStackListener listener)
          Appends the listener to the list of command stack listeners.
 boolean canRedo()
           
 boolean canUndo()
           
 void dispose()
          This will dispose() all the commands in both the undo and redo stack.
 void execute(org.eclipse.gef.commands.Command command)
          Executes the specified Command if possible.
 void flush()
          Flushes the entire stack and resets the save location to zero.
 java.lang.Object[] getCommands()
           
protected  java.util.Stack getRedoable()
          Returns the redoable commands
 org.eclipse.gef.commands.Command getRedoCommand()
          Peeks at the top of the redo stack.
protected  int getSaveLocation()
          Returns the save location
protected  java.util.Stack getUndoable()
          Returns the undoable commands
 org.eclipse.gef.commands.Command getUndoCommand()
          Peeks at the top of the undo stack.
 int getUndoLimit()
          Returns the undo limit.
 boolean isDirty()
          Returns true if the stack is dirty.
 void markSaveLocation()
          Marks the last executed or redone Command as the point at which the changes were saved.
protected  void notifyListeners()
          Deprecated.  
protected  void notifyListeners(org.eclipse.gef.commands.Command command, int state)
           
 void redo()
          Calls redo on the Command at the top of the redo stack, and pushes that Command onto the undo stack.
 void removeCommandStackEventListener(org.eclipse.gef.commands.CommandStackEventListener listener)
          Removes the first occurrence of the specified listener.
 void removeCommandStackListener(org.eclipse.gef.commands.CommandStackListener listener)
          Removes the first occurrence 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 java.util.List listeners
Deprecated. This field should not be referenced, use notifyListeners()
The list of CommandStackListeners.


PRE_EXECUTE

public static final int PRE_EXECUTE
Constant indicating notification prior to executing a command (value is 1).

See Also:
Constant Field Values

PRE_REDO

public static final int PRE_REDO
Constant indicating notification prior to redoing a command (value is 2).

See Also:
Constant Field Values

PRE_UNDO

public static final int PRE_UNDO
Constant indicating notification prior to undoing a command (value is 4).

See Also:
Constant Field Values

POST_EXECUTE

public static final int POST_EXECUTE
Constant indicating notification after a command has been executed (value is 8).

See Also:
Constant Field Values

POST_REDO

public static final int POST_REDO
Constant indicating notification after a command has been redone (value is 16).

See Also:
Constant Field Values

POST_UNDO

public static final int POST_UNDO
Constant indicating notification after a command has been undone (value is 32).

See Also:
Constant Field Values
Constructor Detail

CommandStack

public CommandStack()
Constructs a new command stack. By default, there is no undo limit, and isDirty() will return false.

Method Detail

addCommandStackListener

public void addCommandStackListener(org.eclipse.gef.commands.CommandStackListener listener)
Appends the listener to the list of command stack listeners. Multiple adds will result in multiple notifications.

Overrides:
addCommandStackListener in class org.eclipse.gef.commands.CommandStack
Parameters:
listener - the listener

addCommandStackEventListener

public void addCommandStackEventListener(org.eclipse.gef.commands.CommandStackEventListener listener)
Appends the listener to the list of command stack listeners. Multiple adds result in multiple notifications.

Overrides:
addCommandStackEventListener in class org.eclipse.gef.commands.CommandStack
Parameters:
listener - the event listener
Since:
3.1

canRedo

public boolean canRedo()
Overrides:
canRedo in class org.eclipse.gef.commands.CommandStack
Returns:
true if it is appropriate to call redo().

canUndo

public boolean canUndo()
Overrides:
canUndo in class org.eclipse.gef.commands.CommandStack
Returns:
true if undo() can be called

execute

public void execute(org.eclipse.gef.commands.Command command)
Executes the specified Command if possible. Prior to executing the command, a CommandStackEvent for PRE_EXECUTE will be fired to event listeners. Similarly, after attempting to execute the command, an event for POST_EXECUTE will be fired. If the execution of the command completely normally, stack listeners will receive stackChanged notification.

If the command is null or cannot be executed, nothing happens.

Overrides:
execute in class org.eclipse.gef.commands.CommandStack
Parameters:
command - the Command to execute
See Also:
CommandStackEventListener

notifyListeners

protected void notifyListeners(org.eclipse.gef.commands.Command command,
                               int state)
Overrides:
notifyListeners in class org.eclipse.gef.commands.CommandStack
Parameters:
command -
post_execute2 -
Since:
3.1

dispose

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

Overrides:
dispose in class org.eclipse.gef.commands.CommandStack

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".

Overrides:
flush in class org.eclipse.gef.commands.CommandStack

getCommands

public java.lang.Object[] getCommands()
Overrides:
getCommands in class org.eclipse.gef.commands.CommandStack
Returns:
an array containing all commands in the order they were executed

getRedoCommand

public org.eclipse.gef.commands.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.

Overrides:
getRedoCommand in class org.eclipse.gef.commands.CommandStack
Returns:
the top of the redo stack, which may be null

getUndoCommand

public org.eclipse.gef.commands.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.

Overrides:
getUndoCommand in class org.eclipse.gef.commands.CommandStack
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.

Overrides:
getUndoLimit in class org.eclipse.gef.commands.CommandStack
Returns:
the undo limit

isDirty

public boolean isDirty()
Returns true if the stack is dirty. The stack is dirty whenever the last executed or redone command is different than the command that was at the top of the undo stack when markSaveLocation() was last called.

Overrides:
isDirty in class org.eclipse.gef.commands.CommandStack
Returns:
true if the stack is dirty

markSaveLocation

public void markSaveLocation()
Marks the last executed or redone Command as the point at which the changes were saved. Calculation of isDirty() will be based on this checkpoint.

Overrides:
markSaveLocation in class org.eclipse.gef.commands.CommandStack

notifyListeners

protected void notifyListeners()
Deprecated. 

Sends notification to all CommandStackListeners.

Overrides:
notifyListeners in class org.eclipse.gef.commands.CommandStack

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.

Overrides:
redo in class org.eclipse.gef.commands.CommandStack

removeCommandStackListener

public void removeCommandStackListener(org.eclipse.gef.commands.CommandStackListener listener)
Removes the first occurrence of the specified listener.

Overrides:
removeCommandStackListener in class org.eclipse.gef.commands.CommandStack
Parameters:
listener - the listener

removeCommandStackEventListener

public void removeCommandStackEventListener(org.eclipse.gef.commands.CommandStackEventListener listener)
Removes the first occurrence of the specified listener.

Overrides:
removeCommandStackEventListener in class org.eclipse.gef.commands.CommandStack
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.

Overrides:
setUndoLimit in class org.eclipse.gef.commands.CommandStack
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.

Overrides:
undo in class org.eclipse.gef.commands.CommandStack

getUndoable

protected java.util.Stack getUndoable()
Returns the undoable commands

Returns:
the list of commands

getRedoable

protected java.util.Stack getRedoable()
Returns the redoable commands

Returns:
the list of commands

getSaveLocation

protected int getSaveLocation()
Returns the save location

Returns:
the save index

Modelers

Copyright (c) 2005 TOPCASED Contributors 2005 - 2007. All rights reserved.