Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.pietschy.command.delegate
Class DelegatingCommand

    java.lang.Object
      com.pietschy.command.Command
          com.pietschy.command.ActionCommand
              com.pietschy.command.delegate.DelegatingCommand

All Implemented Interfaces:
  ActionCommandExecutor, Bindable, Identifiable

Direct Known Subclasses:
  DelegatingToggleCommand

    public class DelegatingCommand

extends ActionCommand

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

DelegatingCommands delegate to either `ActionCommandDelegate`s or regular `ActionCommand`s. The DelegatingCommand tracks the enabled state of its delegate and updates accordingly. The command will only be enabled if it finds a non-null delegate that is also enabled.

Mediation between DelegatingCommands and thier delegates is managed by an instance of `DelegateMediator`. DelegateMediators are installed on `CommandContainer`s and discovered by the DelegatingCommands during the binding process.

The most common delegate mediator to use is the `FocusTrackingDelegateMediator`.

The following is an example of creating a delegating command and installing a mediator.

        CommandContainer container = ...;
        DelegateMediator mediator = ...;

        container.setDelegateMediator(mediator);

        DelegatingCommand printCommand = new DelegatingCommand("print");
        // once bound the command will find the mediator and monitor it for
        // "print" delegates.
        printCommand.bind(container);

This class also provides static convenience methods for creating and binding a number of delegating commands at once. The following example creates commands for the standard cut, copy, paste and print operations and binds them to the specified container.

        DelegatingCommand.bindAll(container, "print", "cut", "copy", "paste");

Version:
  $Revision: 1.8 $
Author:
  andrewp
See Also:
  `ActionCommandDelegate`, `DelegatingToggleCommand`, `DelegatingToggleGroup`, `FocusTrackingDelegateMediator`

Field Summary

Fields inherited from class com.pietschy.command.ActionCommand
`PARAMETER_ACTION_EVENT, PARAMETER_INVOKER, PARAMETER_INVOKER_WINDOW, PARAMETER_MODIFIERS`

Fields inherited from class com.pietschy.command.Command
`internalLog, PROPERTY_ENABLED, PROPERTY_VISIBLE`

Constructor Summary
`DelegatingCommand(java.lang.String id)` Creates a new instance with the specified id.

Method Summary
`static void` | `bindAll(CommandContainer container, java.lang.String firstId, java.lang.String... otherIds)` Creates delegating commands for each of the specified id's and binds them to the specified container.
`static void` | `bindAll(java.awt.Component component, java.lang.String firstId, java.lang.String... otherIds)` Creates delegating commands for each of the specified id's and binds them to the specified component.
`static void` | `bindAll(java.lang.String firstId, java.lang.String... otherIds)` Creates delegating commands for each of the specified id's and binds them to the global command container.
`ActionCommandExecutor` | `getDelegate()` Gets this command delegate.
`DelegateMediator` | `getDelegateMediator()` Gets the mediator this command is using to locate its delegates.
`protected void` | `handleExecute()` Main entry point for command subclasses that must be implemented to provide command specific behaviour.
`protected ActionCommandExecutor` | `nullIfEqualsThis(ActionCommandExecutor newDelegate)`
`void` | `setDelegate(ActionCommandExecutor newDelegate)` Sets the delegate for this command to use.
`void` | `setDelegateMediator(DelegateMediator delegateMediator)` Sets the mediator this command will use to update it delegates.
`protected void` | `updateState()`

Methods inherited from class com.pietschy.command.ActionCommand
`addActionCommandListener, addInterceptor, bindToContainer, createButton, createButton, createButton, createButton, createMenuItem, createMenuItem, createMenuItem, createMenuItem, doButtonAttachments, doButtonDetachments, execute, execute, getActionAdapter, getActionAdapter, getActionEvent, getInvoker, getInvokerWindow, getModifiers, getParameter, getParameter, getParameters, installShortCut, installShortCut, postExecute, preExecute, putParameter, putParameters, removeActionCommandListener, removeInterceptor, requestDefaultIn, unbindFromContainer, uninstallShortCut, uninstallShortCut`

Methods inherited from class com.pietschy.command.Command
`addContainerPropertyListener, addFace, addHoverListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, attach, bind, bind, bind, buttonIterator, configureAppearance, configureAppearances, configureButtonAppearances, configureButtonStates, configureButtonStates, createButton, createButton, createButton, createButton, createComponent, createMenuItem, createMenuItem, createMenuItem, createMenuItem, detach, faceExists, findBestFace, fireHoverEnded, fireHoverStarted, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlternativeFaceContexts, getButtonFactory, getButtonIn, getCommandContainer, getContainerProperty, getDefaultFace, getDefaultFace, getFace, getFace, getId, getMenuFactory, getProperty, getProperty, getPropertyNames, getToolbarFactory, isAnonymous, isAttachedTo, isBound, isEnabled, isVisible, loadConfiguration, notifyCommandContainerHierarchyChanged, putProperties, putProperty, rebind, removeContainerPropertyListener, removeHoverListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, requestFocusIn, setButtonFactory, setEnabled, setMenuFactory, setToolbarFactory, setVisible, toString, unbind, validateId`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.pietschy.command.ActionCommandExecutor
`addPropertyChangeListener, addPropertyChangeListener, isEnabled, removePropertyChangeListener, removePropertyChangeListener`

Methods inherited from interface com.pietschy.command.Identifiable
`getId`

Constructor Detail

### DelegatingCommand

    public DelegatingCommand(java.lang.String id)

  Creates a new instance with the specified id. This command will bind to any delegate with the same id.

  Parameters:
    `id` - the id of the delegate this command is to track.

Method Detail

### bindAll

    public static void bindAll(CommandContainer container,
                               java.lang.String firstId,
                               java.lang.String... otherIds)

  Creates delegating commands for each of the specified id's and binds them to the specified container.

  Parameters:
    `container` - the container to bind the delegates to.
    `firstId` - the first delegate id in standard var-args editor.
    `otherIds` - any additional ids.

### bindAll

    public static void bindAll(java.awt.Component component,
                               java.lang.String firstId,
                               java.lang.String... otherIds)

  Creates delegating commands for each of the specified id's and binds them to the specified component.

  Parameters:
    `component` - the component to bind the delegates to.
    `firstId` - the first delegate id in standard var-args editor.
    `otherIds` - any additional ids.

### bindAll

    public static void bindAll(java.lang.String firstId,
                               java.lang.String... otherIds)

  Creates delegating commands for each of the specified id's and binds them to the global command container.

  Parameters:
    `firstId` - the first delegate id in standard var-args editor.
    `otherIds` - any additional ids.

### 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 command. All command invocation must be performed using the `ActionCommand.execute()` and `ActionCommand.execute(Map)` methods.

  Specified by:
    `handleExecute` in class `ActionCommand`

### getDelegateMediator

    public DelegateMediator getDelegateMediator()

  Gets the mediator this command is using to locate its delegates.

  Returns:
    the mediator this command is using to locate its delegates.

### setDelegateMediator

    public void setDelegateMediator(DelegateMediator delegateMediator)

  Sets the mediator this command will use to update it delegates. This method is automatically called once this command has be bound to a command container.

  Parameters:
    `delegateMediator` - the mediator for this command to use.

### setDelegate

    public void setDelegate(ActionCommandExecutor newDelegate)

  Sets the delegate for this command to use. The command will update its state according to the delegate.

### nullIfEqualsThis

    protected ActionCommandExecutor nullIfEqualsThis(ActionCommandExecutor newDelegate)

### getDelegate

    public ActionCommandExecutor getDelegate()

  Gets this command delegate.

  Returns:
    this commands delegate.

### updateState

    protected void updateState()

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2006 - 2007 Andrew Pietsch