net.refractions.udig.project.command
Class CommandManager

java.lang.Object
  extended by net.refractions.udig.project.command.CommandManager
All Implemented Interfaces:
CommandStack, NavCommandStack

public class CommandManager
extends java.lang.Object
implements CommandStack, NavCommandStack

A commands Manager executes commands in a seperate thread, either synchronously or a synchronously.

Since:
1.0.0
Author:
Jesse

Nested Class Summary
 class CommandManager.Executor
          Executes commands in a seperate thread from the requesting thread.
static class CommandManager.Request
          TODO Purpose of net.refractions.udig.project.command
 
Constructor Summary
CommandManager(java.lang.String managerName, ErrorHandler handler)
          Creates a new instance of CommandManager
CommandManager(java.lang.String managerName, ErrorHandler handler, CommandListener commandCompletionListener)
          Creates a new instance of CommandManager
CommandManager(java.lang.String managerName, ErrorHandler handler, CommandListener commandCompletionListener, long timeout2)
          Creates a new instance of CommandManager
 
Method Summary
 void addErrorHandler(ErrorHandler handler)
          Adds an Errorhandler to the list of error handlers
 boolean aSyncExecute(Command command)
          Execute Command asyncrounously.
 boolean canRedo()
          return true if a command is available to be redone.
 boolean canUndo()
           
 boolean execute(Command command, boolean async)
          Executes a command.
 int getMaxHistorySize()
           
 boolean hasBackHistory()
           
 boolean hasForwardHistory()
           
 void redo(boolean runAsync)
          Executes the last undone command, if there are any commands to undo.
 void removeErrorHandler(ErrorHandler handler)
          Removes an Errorhandler from the list of error handlers
 boolean syncExecute(Command command)
          Execute Command syncrounously.
 void undo(boolean runAsync)
          Undoes the last command if possible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandManager

public CommandManager(java.lang.String managerName,
                      ErrorHandler handler,
                      CommandListener commandCompletionListener)
Creates a new instance of CommandManager

Parameters:
handler - an error handler to use to handle thrown exceptions.

CommandManager

public CommandManager(java.lang.String managerName,
                      ErrorHandler handler)
Creates a new instance of CommandManager

Parameters:
handler - an error handler to use to handle thrown exceptions.

CommandManager

public CommandManager(java.lang.String managerName,
                      ErrorHandler handler,
                      CommandListener commandCompletionListener,
                      long timeout2)
Creates a new instance of CommandManager

Parameters:
handler - an error handler to use to handle thrown exceptions.
Method Detail

execute

public boolean execute(Command command,
                       boolean async)
Executes a command. Calls the Errorhandler if an exception is thrown.

Parameters:
command - The command to execute
async - flag indicating wether command should be executed sync vs async.
Returns:
true if no problems were encountered while queueing command. Problems will typically occur when the command is synchronous and it times out or is interrupted.

redo

public void redo(boolean runAsync)
Executes the last undone command, if there are any commands to undo.

Parameters:
runAsync - true to run undo asynchronously

undo

public void undo(boolean runAsync)
Undoes the last command if possible.

Parameters:
runAsync - true to run undo asynchronously

addErrorHandler

public void addErrorHandler(ErrorHandler handler)
Adds an Errorhandler to the list of error handlers

Parameters:
handler - the error handler to add.
See Also:
ErrorHandler

removeErrorHandler

public void removeErrorHandler(ErrorHandler handler)
Removes an Errorhandler from the list of error handlers

Parameters:
handler - the error handler to remove.
See Also:
ErrorHandler

canUndo

public boolean canUndo()
Specified by:
canUndo in interface CommandStack
Returns:
true if the last command can be undone.
See Also:
CommandStack.canUndo()

canRedo

public boolean canRedo()
Description copied from interface: CommandStack
return true if a command is available to be redone.

Specified by:
canRedo in interface CommandStack
See Also:
CommandStack.canRedo()

hasBackHistory

public boolean hasBackHistory()
Specified by:
hasBackHistory in interface NavCommandStack
Returns:
true if there is a position in the command stack that the viewport can return to.
See Also:
NavCommandStack.hasBackHistory()

hasForwardHistory

public boolean hasForwardHistory()
Specified by:
hasForwardHistory in interface NavCommandStack
Returns:
true if the backHistory method has been called and no new nav commands have occurred;
See Also:
NavCommandStack.hasForwardHistory()

syncExecute

public boolean syncExecute(Command command)
Execute Command syncrounously. IE wait until command is complete before returning.

Returns:
true if no problems were encountered while queueing command. Problems will typically occur when the command is synchronous and it times out or is interrupted.

getMaxHistorySize

public int getMaxHistorySize()

aSyncExecute

public boolean aSyncExecute(Command command)
Execute Command asyncrounously. IE return immediately, do not wait until command is complete before returning.

Returns:
true if no problems were encountered while queueing command. Problems will typically occur when the command is synchronous and it times out or is interrupted.