dsto.dfc.swing.undo
Class AbstractUndoableCommand

java.lang.Object
  extended by dsto.dfc.swing.commands.AbstractCommand
      extended by dsto.dfc.swing.commands.AbstractMutableCommand
          extended by dsto.dfc.swing.undo.AbstractUndoableCommand
All Implemented Interfaces:
Command, Iconic, EditExceptionPolicy, Copyable, PropertyEventSource, ActionListener, Cloneable, EventListener
Direct Known Subclasses:
CmdRedo, CmdUndo

public abstract class AbstractUndoableCommand
extends AbstractMutableCommand
implements EditExceptionPolicy

Abstract super class for undo and redo commands. Provides exception handling and cursor listening behaviour.

Version:
$Revision$
Author:
Peter J Smet

Field Summary
protected  dsto.dfc.swing.undo.CursorUpdatePolicy cursorUpdatePolicy
           
protected  EditExceptionHandler exceptionHandler
           
protected  String name
           
protected  MonitoredUndoManager undoManager
           
 
Fields inherited from class dsto.dfc.swing.commands.AbstractMutableCommand
listeners
 
Fields inherited from class dsto.dfc.swing.commands.AbstractCommand
displayName, icon
 
Fields inherited from interface dsto.dfc.swing.icons.Iconic
NULL_ICON
 
Constructor Summary
AbstractUndoableCommand(MonitoredUndoManager undoManager)
          Used by subclasses to register the MonitoredUndoManager being listened to and construct the cursor update policy.
 
Method Summary
 void execute()
          Template method, should not be overridden
abstract  void execute(UndoableEdit edit)
          Implement this method with the command's behaviour.
 String getGroupInView(String viewName)
          Get the preferred group that this command should appear in for a given view.
 String getName()
          The formal identifying name for this command (eg edit.Copy, file.Open).
protected  int handleNonExecutableEdit()
          Template method, should not be overridden.
 boolean isInteractive()
          True if this command will interact with the user when execute() is called.
protected  void listenForEnablingEvents()
          Start listening for enabling cursor changes.
 void listenForEnablingEvents(boolean listen)
          The boolean listen indicates whether the command should allow itself to be enable-able by listening to cursor changes.
 void pause()
          Override this method to add behaviour when pausing.
 void retry()
          Tries to re-execute the undo or redo.
abstract  UndoableEdit selectedEdit()
          Implement this method to return the edit in question.
abstract  void skip()
          Implement this command to determine how to skip an edit which causes an exception.
protected  void stopListeningForEnablingEvents()
          Stop listening for enabling cursor changes.
abstract  void updateEnabled()
          Implement this method to indicate whether the command is enabled or not.
 
Methods inherited from class dsto.dfc.swing.commands.AbstractMutableCommand
addPropertyChangeListener, clone, isEnabled, removePropertyChangeListener, setEnabled, setIcon
 
Methods inherited from class dsto.dfc.swing.commands.AbstractCommand
actionPerformed, canReplace, getAccelerator, getDefaultDisplayName, getDescription, getDisplayName, getIcon, getLargeIcon, getLogString, getMnemonic, setDisplayName
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected String name

undoManager

protected MonitoredUndoManager undoManager

cursorUpdatePolicy

protected dsto.dfc.swing.undo.CursorUpdatePolicy cursorUpdatePolicy

exceptionHandler

protected EditExceptionHandler exceptionHandler
Constructor Detail

AbstractUndoableCommand

public AbstractUndoableCommand(MonitoredUndoManager undoManager)
Used by subclasses to register the MonitoredUndoManager being listened to and construct the cursor update policy.

Method Detail

execute

public abstract void execute(UndoableEdit edit)
Implement this method with the command's behaviour.


selectedEdit

public abstract UndoableEdit selectedEdit()
Implement this method to return the edit in question.


updateEnabled

public abstract void updateEnabled()
Implement this method to indicate whether the command is enabled or not.


skip

public abstract void skip()
Implement this command to determine how to skip an edit which causes an exception.

Specified by:
skip in interface EditExceptionPolicy

retry

public void retry()
Tries to re-execute the undo or redo.

Specified by:
retry in interface EditExceptionPolicy

pause

public void pause()
Override this method to add behaviour when pausing.

Specified by:
pause in interface EditExceptionPolicy

execute

public void execute()
Template method, should not be overridden

Specified by:
execute in interface Command
Specified by:
execute in class AbstractCommand

handleNonExecutableEdit

protected int handleNonExecutableEdit()
Template method, should not be overridden.


listenForEnablingEvents

public void listenForEnablingEvents(boolean listen)
The boolean listen indicates whether the command should allow itself to be enable-able by listening to cursor changes.


listenForEnablingEvents

protected void listenForEnablingEvents()
Start listening for enabling cursor changes.


stopListeningForEnablingEvents

protected void stopListeningForEnablingEvents()
Stop listening for enabling cursor changes.


isInteractive

public boolean isInteractive()
Description copied from interface: Command
True if this command will interact with the user when execute() is called.

Specified by:
isInteractive in interface Command
Specified by:
isInteractive in class AbstractCommand

getName

public String getName()
Description copied from interface: Command
The formal identifying name for this command (eg edit.Copy, file.Open). This must not change during the lifetime of a command instance.

Specified by:
getName in interface Command
Specified by:
getName in interface Iconic
Specified by:
getName in class AbstractCommand

getGroupInView

public String getGroupInView(String viewName)
Description copied from interface: Command
Get the preferred group that this command should appear in for a given view. This may be overridden by a setting in the CommandRegistry.

If the command changes its group in any view it should generate a groupInView property change event with the old value set to the old group and the new value set to the new group.

Specified by:
getGroupInView in interface Command
Specified by:
getGroupInView in class AbstractCommand
Parameters:
viewName - The name of the view.
Returns:
The group in the view, or null if this command does not appear in the given view.


Copyright © 2008 Commonwealth of Australia