## org.eclipse.emf.common.command
Class BasicCommandStack

    java.lang.Object
      org.eclipse.emf.common.command.BasicCommandStack

All Implemented Interfaces:
  CommandStack

Direct Known Subclasses:
  PersistentCommandStack

    public class BasicCommandStack

extends java.lang.Object
implements CommandStack

A basic and obvious implementation of an undoable stack of commands. See `Command` for more details about the command methods that this implementation uses.

Field Summary
`protected java.util.List<Command>` `commandList` The list of commands.
`protected java.util.Collection<CommandStackListener>` `listeners` The `CommandStackListener`s.
`protected Command` `mostRecentCommand` The command most recently executed, undone, or redone.
`protected int` `saveIndex` The value of `top` when `saveIsDone()` is called.
`protected int` `top` The current position within the list from which the next execute, undo, or redo, will be performed.

Constructor Summary
`BasicCommandStack()` Creates a new empty instance.

Method Summary
`void` `addCommandStackListener(CommandStackListener listener)` Adds a listener to the command stack, which will be notified whenever a command has been processed on the stack.
`boolean` `canRedo()` Returns whether there are commands past the top of the stack that can be redone.
`boolean` `canUndo()` Returns whether the top command on the stack can be undone.
`void` `execute(Command command)` Clears any redoable commands not yet redone, adds the command, and then executes the command.
`void` `flush()` Disposes all the commands in the stack.
`Command` `getMostRecentCommand()` Returns the command most recently executed, undone, or redone.
`Command` `getRedoCommand()` Returns the command that will be redone if `CommandStack.redo()` is called.
`Command` `getUndoCommand()` Returns the command that will be undone if `CommandStack.undo()` is called.
`protected void` `handleError(java.lang.Exception exception)` Handles an exception thrown during command execution by loging it with the plugin.
`boolean` `isSaveNeeded()` Returns whether the model has changes since `saveIsDone()` was call the last.
`protected void` `notifyListeners()` This is called to ensure that `CommandStackListener.commandStackChanged(java.util.EventObject)` is called for each listener.
`void` `redo()` Moves the top of the stack up, redoing the new top command.
`void` `removeCommandStackListener(CommandStackListener listener)` Removes a listener from the command stack.
`void` `saveIsDone()` Called after a save has been successfully performed.
`void` `undo()` Moves the top of the stack down, undoing what was formerly the top command.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### commandList

    protected java.util.List<Command> commandList

  The list of commands.

### top

    protected int top

  The current position within the list from which the next execute, undo, or redo, will be performed.

### mostRecentCommand

    protected Command mostRecentCommand

  The command most recently executed, undone, or redone.

### listeners

    protected java.util.Collection<CommandStackListener> listeners

  The `CommandStackListener`s.

### saveIndex

    protected int saveIndex

  The value of `top` when `saveIsDone()` is called.

Constructor Detail

### BasicCommandStack

    public BasicCommandStack()

  Creates a new empty instance.

Method Detail

### execute

    public void execute(Command command)

  Description copied from interface: `CommandStack`
  Clears any redoable commands not yet redone, adds the command, and then executes the command.

  Specified by:
    `execute` in interface `CommandStack`
  Parameters:
    `command` - the command to execute.

### canUndo

    public boolean canUndo()

  Description copied from interface: `CommandStack`
  Returns whether the top command on the stack can be undone.

  Specified by:
    `canUndo` in interface `CommandStack`
  Returns:
    whether the top command on the stack can be undone.

### undo

    public void undo()

  Description copied from interface: `CommandStack`
  Moves the top of the stack down, undoing what was formerly the top command.

  Specified by:
    `undo` in interface `CommandStack`

### canRedo

    public boolean canRedo()

  Description copied from interface: `CommandStack`
  Returns whether there are commands past the top of the stack that can be redone.

  Specified by:
    `canRedo` in interface `CommandStack`
  Returns:
    whether there are commands past the top of the stack that can be redone.

### redo

    public void redo()

  Description copied from interface: `CommandStack`
  Moves the top of the stack up, redoing the new top command.

  Specified by:
    `redo` in interface `CommandStack`

### flush

    public void flush()

  Description copied from interface: `CommandStack`
  Disposes all the commands in the stack.

  Specified by:
    `flush` in interface `CommandStack`

### getUndoCommand

    public Command getUndoCommand()

  Description copied from interface: `CommandStack`
  Returns the command that will be undone if `CommandStack.undo()` is called.

  Specified by:
    `getUndoCommand` in interface `CommandStack`
  Returns:
    the command that will be undone if `CommandStack.undo()` is called.

### getRedoCommand

    public Command getRedoCommand()

  Description copied from interface: `CommandStack`
  Returns the command that will be redone if `CommandStack.redo()` is called.

  Specified by:
    `getRedoCommand` in interface `CommandStack`
  Returns:
    the command that will be redone if `CommandStack.redo()` is called.

### getMostRecentCommand

    public Command getMostRecentCommand()

  Description copied from interface: `CommandStack`
  Returns the command most recently executed, undone, or redone.

  Specified by:
    `getMostRecentCommand` in interface `CommandStack`
  Returns:
    the command most recently executed, undone, or redone.

### addCommandStackListener

    public void addCommandStackListener(CommandStackListener listener)

  Description copied from interface: `CommandStack`
  Adds a listener to the command stack, which will be notified whenever a command has been processed on the stack.

  Specified by:
    `addCommandStackListener` in interface `CommandStack`
  Parameters:
    `listener` - the listener to add.

### removeCommandStackListener

    public void removeCommandStackListener(CommandStackListener listener)

  Description copied from interface: `CommandStack`
  Removes a listener from the command stack.

  Specified by:
    `removeCommandStackListener` in interface `CommandStack`
  Parameters:
    `listener` - the listener to remove.

### notifyListeners

    protected void notifyListeners()

  This is called to ensure that `CommandStackListener.commandStackChanged(java.util.EventObject)` is called for each listener.

### handleError

    protected void handleError(java.lang.Exception exception)

  Handles an exception thrown during command execution by loging it with the plugin.

### saveIsDone

    public void saveIsDone()

  Called after a save has been successfully performed.

### isSaveNeeded

    public boolean isSaveNeeded()

  Returns whether the model has changes since `saveIsDone()` was call the last.

  Returns:
    whether the model has changes since `saveIsDone` was call the last.

Copyright 2001-2006 IBM Corporation and others. All Rights Reserved.