org.pietschy.command.delegate

Class DelegatingCommand

Implemented Interfaces:
ActionCommandExecutor, DelegateMediatorListener, EventListener

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(String id)
Creates a new DelegatingCommand with the specified id.
DelegatingCommand(CommandManager commandManager, String commandId)
Creates a new DelegatingCommand with the specified id and that is bound to the specifed CommandManager.

Method Summary

void
delegatesChanged(DelegateMediatorEvent event)
protected ActionCommandExecutor
getDelegate()
protected void
handleExecute()
protected void
setDelegate(ActionCommandExecutor newDelegate)
Sets the delegate for this command to use.
protected void
setDelegateIdToTrack(String delegateIdToTrack)
Sets the delegate id this command is to track.
DelegatingCommand
trackDelegateIn(String delegateId, Window window)
This method configures the command to track delegates in the specified java.awt.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, handleExecute, 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, attach, buttonIterator, configureButtonAppearance, configureButtonAppearances, configureButtonAppearances, configureButtonStates, createButton, createButton, createButton, createButton, createMenuItem, createMenuItem, createMenuItem, createMenuItem, detach, 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

Constructor Details

DelegatingCommand

public DelegatingCommand(String id)
Parameters:
id - the id of the command.

DelegatingCommand

public DelegatingCommand(CommandManager commandManager,
                         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 Details

delegatesChanged

public void delegatesChanged(DelegateMediatorEvent event)
Specified by:
delegatesChanged in interface DelegateMediatorListener

getDelegate

protected ActionCommandExecutor getDelegate()

handleExecute

protected void handleExecute()
Overrides:
handleExecute in interface 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)

setDelegateIdToTrack

protected void setDelegateIdToTrack(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(String delegateId,
                                         Window window)
This method configures the command to track delegates in the specified java.awt.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();.