org.pietschy.command.delegate
Class DelegatingCommand

java.lang.Object
  extended by org.pietschy.command.Command
      extended by org.pietschy.command.ActionCommand
          extended by org.pietschy.command.delegate.DelegatingCommand
All Implemented Interfaces:
java.util.EventListener, ActionCommandExecutor, DelegateMediatorListener

public class DelegatingCommand
extends ActionCommand
implements DelegateMediatorListener

Delegating commands allow a single command to delegate its behaviour to another object. This is most useful when the commands actaul behaviour is dependant on the current context of the UI. A typical examples would be cut, paste and print.

The behaviour of the command is provided by instances of CommandDelegate which are automatically extracted from the DelegateContainer once trackDelegateIn(String, java.awt.Window) has been invoked.

DelegatingCommands are automatically bound to delegates whose id match their own.

Version:
$Revision: 1.9 $
Author:
andrewp
See Also:
DelegateContainer, CommandDelegate

Field Summary
 
Fields inherited from class org.pietschy.command.ActionCommand
HINT_ACTION_EVENT, HINT_INVOKER, HINT_INVOKER_WINDOW, HINT_MODIFIERS
 
Fields inherited from class org.pietschy.command.Command
internalLog, listenerList, pcs
 
Constructor Summary
DelegatingCommand(CommandManager commandManager, java.lang.String commandId)
          Creates a new DelegatingCommand with the specified id and that is bound to the specifed CommandManager.
DelegatingCommand(java.lang.String id)
          Creates a new DelegatingCommand with the specified id.
 
Method Summary
 void delegatesChanged(DelegateMediatorEvent event)
          Invoked when the DelegateContainers of a specific DelegateMediator have changed.
protected  ActionCommandExecutor getDelegate()
           
protected  void handleExecute()
          Main entry point for command subclasses that must be implemented to provide command specific behaviour.
protected  void setDelegate(ActionCommandExecutor newDelegate)
          Sets the delegate for this command to use.
protected  void setDelegateIdToTrack(java.lang.String delegateIdToTrack)
          Sets the delegate id this command is to track.
 DelegatingCommand trackDelegateIn(java.lang.String delegateId, java.awt.Window window)
          This method configures the command to track delegates in the specified Window.
 
Methods inherited from class org.pietschy.command.ActionCommand
addCommandListener, addInterceptor, areEqual, attach, configureButtonStates, detach, execute, execute, getActionAdapter, getActionAdapter, getActionCommand, getActionEvent, getHint, getHint, getHints, getInvoker, getInvokerWindow, getModifiers, installShortCut, installShortCut, postExecute, preExecute, putHint, putHints, removeCommandListener, removeInterceptor, requestDefautIn, setActionCommand, uninstallShortCut, uninstallShortCut
 
Methods inherited from class org.pietschy.command.Command
addFace, addHoverListener, addNewFace, addNotify, addPropertyChangeListener, addPropertyChangeListener, buttonIterator, configureButtonAppearance, configureButtonAppearances, configureButtonAppearances, createButton, createButton, createButton, createButton, createMenuItem, createMenuItem, createMenuItem, createMenuItem, export, faceExists, fireHoverEnded, fireHoverStarted, getAccelerator, getAlternativeFaceNames, getButtonFactory, getButtonIn, getCommandManager, getDefaultFace, getDefaultFace, getDescription, getFace, getFace, getIcon, getId, getLongDescription, getMenuFactory, getMnemonic, getMnemonicIndex, getProperty, getProperty, getPropertyNames, getSelectedIcon, getText, getTextPosition, getToolbarFactory, initCommandManager, installFace, isAnonymous, isAttachedTo, isEnabled, isVisible, putProperty, removeHoverListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, requestFocusIn, setAccelerator, setButtonFactory, setDescription, setEnabled, setIcon, setLongDescription, setMenuFactory, setMnemonic, setMnemonicIndex, setSelectedIcon, setText, setTextPosition, setToolbarFactory, setVisible, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.pietschy.command.ActionCommandExecutor
addPropertyChangeListener, addPropertyChangeListener, isEnabled, removePropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

DelegatingCommand

public DelegatingCommand(java.lang.String id)
Creates a new DelegatingCommand with the specified id. This command will be bound to CommandManager.defaultInstance()

Parameters:
id - the id of the command.

DelegatingCommand

public DelegatingCommand(CommandManager commandManager,
                         java.lang.String commandId)
Creates a new DelegatingCommand with the specified id and that is bound to the specifed CommandManager.

Parameters:
commandManager - the CommandManager to which the command is bound.
commandId - the id of the command.
Method Detail

setDelegateIdToTrack

protected void setDelegateIdToTrack(java.lang.String delegateIdToTrack)
Sets the delegate id this command is to track.

Parameters:
delegateIdToTrack - the id of the delegate that this command will invoke.

trackDelegateIn

public DelegatingCommand trackDelegateIn(java.lang.String delegateId,
                                         java.awt.Window window)
This method configures the command to track delegates in the specified Window. The implementation simply adds the command as a listener to the DelegateManager of the specified window. I.e.
 DelegateManager manager = DelegateManager.getInstanceFor(window);
 manager.addDelegateManagerListener(this);
 

Parameters:
delegateId - the id of the delegate to track.
window - the window in which to track delegates.
Returns:
this as a convenience for creating a new commannd on one line, new DelegatingCommand(...).trackDelegatesIn(win).export();.

handleExecute

protected void handleExecute()
Description copied from class: ActionCommand
Main entry point for command subclasses that must be implemented to provide command specific behaviour.

This method should never be called directly to invoke a comand. All command invocation must be performed using the ActionCommand.execute() and ActionCommand.execute(Map) methods.

Specified by:
handleExecute in class ActionCommand

setDelegate

protected void setDelegate(ActionCommandExecutor newDelegate)
Sets the delegate for this command to use. This method is automatically called when trackDelegateIn(String, java.awt.Window) is invoked. and should not normally be used.

Parameters:
newDelegate - the delegate this command is to use.
See Also:
trackDelegateIn(String, java.awt.Window)

getDelegate

protected ActionCommandExecutor getDelegate()

delegatesChanged

public void delegatesChanged(DelegateMediatorEvent event)
Description copied from interface: DelegateMediatorListener
Invoked when the DelegateContainers of a specific DelegateMediator have changed.

Specified by:
delegatesChanged in interface DelegateMediatorListener
Parameters:
event - the event.