|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.pietschy.command.Command
com.pietschy.command.ActionCommand
com.pietschy.command.delegate.DelegatingCommand
public class DelegatingCommand
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 ActionCommandDelegates or regular ActionCommands. 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 CommandContainers 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");
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 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 |
|---|
public DelegatingCommand(java.lang.String id)
id - the id of the delegate this command is to track.| Method Detail |
|---|
public static void bindAll(CommandContainer container,
java.lang.String firstId,
java.lang.String... otherIds)
container - the container to bind the delegates to.firstId - the first delegate id in standard var-args editor.otherIds - any additional ids.
public static void bindAll(java.awt.Component component,
java.lang.String firstId,
java.lang.String... otherIds)
component - the component to bind the delegates to.firstId - the first delegate id in standard var-args editor.otherIds - any additional ids.
public static void bindAll(java.lang.String firstId,
java.lang.String... otherIds)
firstId - the first delegate id in standard var-args editor.otherIds - any additional ids.protected void handleExecute()
ActionCommand
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.
handleExecute in class ActionCommandpublic DelegateMediator getDelegateMediator()
public void setDelegateMediator(DelegateMediator delegateMediator)
delegateMediator - the mediator for this command to use.public void setDelegate(ActionCommandExecutor newDelegate)
protected ActionCommandExecutor nullIfEqualsThis(ActionCommandExecutor newDelegate)
public ActionCommandExecutor getDelegate()
protected void updateState()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||