Package org.eclipse.emf.common.command
Class BasicCommandStack
java.lang.Object
org.eclipse.emf.common.command.BasicCommandStack
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionThe list of commands.protected Collection<CommandStackListener> TheCommandStackListeners.protected CommandThe command most recently executed, undone, or redone.protected intThe value oftopwhensaveIsDone()is called.protected intThe current position within the list from which the next execute, undo, or redo, will be performed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCommandStackListener(CommandStackListener listener) Adds a listener to the command stack, which will be notified whenever a command has been processed on the stack.booleancanRedo()Returns whether there are commands past the top of the stack that can be redone.booleancanUndo()Returns whether the top command on the stack can be undone.voidClears any redoable commands not yet redone, adds the command, and then executes the command.voidflush()Disposes all the commands in the stack.Returns the command most recently executed, undone, or redone.Returns the command that will be redone ifCommandStack.redo()is called.Returns the command that will be undone ifCommandStack.undo()is called.protected voidhandleError(Exception exception) Handles an exception thrown during command execution by logging it with the plugin.booleanReturns whether the model has changes sincesaveIsDone()was call the last.protected voidThis is called to ensure thatCommandStackListener.commandStackChanged(java.util.EventObject)is called for each listener.voidredo()Moves the top of the stack up, redoing the new top command.voidRemoves a listener from the command stack.voidCalled after a save has been successfully performed.voidundo()Moves the top of the stack down, undoing what was formerly the top command.
-
Field Details
-
commandList
The list of commands. -
top
protected int topThe current position within the list from which the next execute, undo, or redo, will be performed. -
mostRecentCommand
The command most recently executed, undone, or redone. -
listeners
TheCommandStackListeners. -
saveIndex
protected int saveIndexThe value oftopwhensaveIsDone()is called.
-
-
Constructor Details
-
BasicCommandStack
public BasicCommandStack()Creates a new empty instance.
-
-
Method Details
-
execute
Description copied from interface:CommandStackClears any redoable commands not yet redone, adds the command, and then executes the command.- Specified by:
executein interfaceCommandStack- Parameters:
command- the command to execute.
-
canUndo
public boolean canUndo()Description copied from interface:CommandStackReturns whether the top command on the stack can be undone.- Specified by:
canUndoin interfaceCommandStack- Returns:
- whether the top command on the stack can be undone.
-
undo
public void undo()Description copied from interface:CommandStackMoves the top of the stack down, undoing what was formerly the top command.- Specified by:
undoin interfaceCommandStack
-
canRedo
public boolean canRedo()Description copied from interface:CommandStackReturns whether there are commands past the top of the stack that can be redone.- Specified by:
canRedoin interfaceCommandStack- Returns:
- whether there are commands past the top of the stack that can be redone.
-
redo
public void redo()Description copied from interface:CommandStackMoves the top of the stack up, redoing the new top command.- Specified by:
redoin interfaceCommandStack
-
flush
public void flush()Description copied from interface:CommandStackDisposes all the commands in the stack.- Specified by:
flushin interfaceCommandStack
-
getUndoCommand
Description copied from interface:CommandStackReturns the command that will be undone ifCommandStack.undo()is called.- Specified by:
getUndoCommandin interfaceCommandStack- Returns:
- the command that will be undone if
CommandStack.undo()is called.
-
getRedoCommand
Description copied from interface:CommandStackReturns the command that will be redone ifCommandStack.redo()is called.- Specified by:
getRedoCommandin interfaceCommandStack- Returns:
- the command that will be redone if
CommandStack.redo()is called.
-
getMostRecentCommand
Description copied from interface:CommandStackReturns the command most recently executed, undone, or redone.- Specified by:
getMostRecentCommandin interfaceCommandStack- Returns:
- the command most recently executed, undone, or redone.
-
addCommandStackListener
Description copied from interface:CommandStackAdds a listener to the command stack, which will be notified whenever a command has been processed on the stack.- Specified by:
addCommandStackListenerin interfaceCommandStack- Parameters:
listener- the listener to add.
-
removeCommandStackListener
Description copied from interface:CommandStackRemoves a listener from the command stack.- Specified by:
removeCommandStackListenerin interfaceCommandStack- Parameters:
listener- the listener to remove.
-
notifyListeners
protected void notifyListeners()This is called to ensure thatCommandStackListener.commandStackChanged(java.util.EventObject)is called for each listener. -
handleError
Handles an exception thrown during command execution by logging 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 sincesaveIsDone()was call the last.- Returns:
- whether the model has changes since
saveIsDonewas call the last.
-