org.pietschy.command.undo

Class UndoController

Implemented Interfaces:
UndoableEditListener

public class UndoController
extends java.lang.Object
implements UndoableEditListener

The UndoController monitors instances of UndoableEventSource and manages undo and redo via its undo and redo commands. The most notable instance of UndoableEventSource is UndoableActionCommand.

The undo state is managed by an instance of UndoContext and can be changed at any time. This allows undo state to be split into separate contexts, such as for a multi file editor.

Version:
$Revision: 1.7 $
Author:
andrewp
See Also:
UndoableEventSource, UndoableActionCommand

Constructor Summary

UndoController(CommandManager commandManager)
Creates a new undo controller.
UndoController(CommandManager commandManager, String undoCommandId, String redoCommandId)
Create a new controller using the specified ids for the undo and redo commands
UndoController(CommandManager commandManager, UndoContext undoContext)
Creates a new controller using the specified UndoContext.
UndoController(CommandManager commandManager, UndoContext undoContext, String undoCommandId, String redoCommandId)
Create a new controller using the specified UndoContext and ids for the undo and redo commands

Method Summary

void
addChangeListener(ChangeListener l)
boolean
canRedo()
boolean
canUndo()
protected void
exportCommands()
CommandManager
getCommandManager()
ActionCommand
getRedoCommand()
Gets an ActionCommand that when invoked will redo the last undone UndoableEditEvent.
ActionCommand
getUndoCommand()
Gets an ActionCommand that when invoked will undo the last registered UndoableEditEvent.
UndoContext
getUndoContext()
Gets the current UndoContext in use.
protected void
redo()
void
registerUndoableCommand(UndoableEventSource command)
Manually registers an UndoableEventSource with this controller.
void
removeChangeListener(ChangeListener l)
void
setUndoContext(UndoContext undoContext)
Configures the controller to use the specified UndoContext.
protected void
undo()
void
undoableEditHappened(UndoableEditEvent e)
Notifies the controller that an undoable event has happened.

Constructor Details

UndoController

public UndoController(CommandManager commandManager)
Creates a new undo controller. The command id used for the undo command will be "gui-commands.undo" and the id used for the redo command will be "gui-commands.redo"
Parameters:
commandManager - the CommandManager to which the controller belongs. It will automatically export its undo and redo commands to the container and track any undoable commands that are registered with it.

UndoController

public UndoController(CommandManager commandManager,
                      String undoCommandId,
                      String redoCommandId)
Create a new controller using the specified ids for the undo and redo commands
Parameters:
commandManager - the CommandManager to which the controller belongs. It will automatically export its undo and redo commands to the container and track any undoable commands that are registered with it.
undoCommandId - the id to use for the undo command.
redoCommandId - the id to use for the redo command.

UndoController

public UndoController(CommandManager commandManager,
                      UndoContext undoContext)
Creates a new controller using the specified UndoContext. The command id used for the undo command will be "gui-commands.undo" and the id used for the redo command will be "gui-commands.redo"
Parameters:
commandManager - the CommandManager to which the controller belongs. It will automatically export its undo and redo commands to the container and track any undoable commands that are registered with it.
undoContext - the UndoContext to use.

UndoController

public UndoController(CommandManager commandManager,
                      UndoContext undoContext,
                      String undoCommandId,
                      String redoCommandId)
Create a new controller using the specified UndoContext and ids for the undo and redo commands
Parameters:
commandManager - the CommandManager to which the controller belongs. It will automatically export its undo and redo commands to the container and track any undoable commands that are registered with it.
undoContext - the UndoContext to use.
undoCommandId - the id to use for the undo command.
redoCommandId - the id to use for the redo command.

Method Details

addChangeListener

public void addChangeListener(ChangeListener l)

canRedo

public boolean canRedo()

canUndo

public boolean canUndo()

exportCommands

protected void exportCommands()

getCommandManager

public CommandManager getCommandManager()

getRedoCommand

public ActionCommand getRedoCommand()
Gets an ActionCommand that when invoked will redo the last undone UndoableEditEvent.
Returns:
an ActionCommand that will undo the the last undone UndoableEditEvent.

getUndoCommand

public ActionCommand getUndoCommand()
Gets an ActionCommand that when invoked will undo the last registered UndoableEditEvent.
Returns:
an ActionCommand that will undo the the last registered UndoableEditEvent.

getUndoContext

public UndoContext getUndoContext()
Gets the current UndoContext in use.
Returns:
the current UndoContext in use by the controller.

redo

protected void redo()

registerUndoableCommand

public void registerUndoableCommand(UndoableEventSource command)
Manually registers an UndoableEventSource with this controller.
Parameters:
command - the UndoableEventSource to register.

removeChangeListener

public void removeChangeListener(ChangeListener l)

setUndoContext

public void setUndoContext(UndoContext undoContext)
Configures the controller to use the specified UndoContext. The undo and redo commands will update according the the state of the context and all new UndoableEditEvents will be registed with it.
Parameters:
undoContext - the undo context to use.

undo

protected void undo()

undoableEditHappened

public void undoableEditHappened(UndoableEditEvent e)
Parameters:
e - the UndoableEditEvent.