Revision: 1788 http://spring-rich-c.svn.sourceforge.net/spring-rich-c/?rev=1788&view=rev Author: kevinstembridge Date: 2007-07-29 09:03:18 -0700 (Sun, 29 Jul 2007)
Log Message: ----------- Added javadoc, no functional changes Modified Paths: -------------- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/TargetableActionCommand.java Modified: trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/TargetableActionCommand.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/TargetableActionCommand.java 2007-07-25 10:52:48 UTC (rev 1787) +++ trunk/spring-richclient/support/src/main/java/org/springframework/richclient/command/TargetableActionCommand.java 2007-07-29 16:03:18 UTC (rev 1788) @@ -21,27 +21,57 @@ import org.springframework.util.ObjectUtils; /** + * An [EMAIL PROTECTED] ActionCommand} that delegates to an internal [EMAIL PROTECTED] ActionCommandExecutor}. + * The executor can be provided at construction but can also be provided + * programmatically at runtime and replaced during program execution. This enables a shared + * global command feature whereby a single command is specified that can perform different + * actions depending on the currently active context. + * * @author Keith Donald */ public class TargetableActionCommand extends ActionCommand { + private ActionCommandExecutor commandExecutor; private PropertyChangeListener guardRelay; + /** + * Creates a new uninitialized [EMAIL PROTECTED] TargetableActionCommand}. If defined + * in a Spring bean factory, the name of the bean will become the id of this instance. + */ public TargetableActionCommand() { this(null); } + /** + * Creates a new [EMAIL PROTECTED] TargetableActionCommand} with the given identifier. + * The instance will be initialized in a disabled state. + * + * @param commandId The identifier for this instance. + */ public TargetableActionCommand(String commandId) { this(commandId, null); } - public TargetableActionCommand(String commandId, ActionCommandExecutor delegate) { + /** + * Creates a new [EMAIL PROTECTED] TargetableActionCommand} with the given identifier and initial + * executor. The instance will be initialized in a disabled state. + * + * @param commandId The identifier for this instance. + * @param commandExecutor The initial command executor. + */ + public TargetableActionCommand(String commandId, ActionCommandExecutor commandExecutor) { super(commandId); setEnabled(false); - setCommandExecutor(delegate); + setCommandExecutor(commandExecutor); } + /** + * Attaches the given executor to this command instance, detaching the current executor in the process. + * + * @param commandExecutor The executor to be attached. May be null, in which case this command + * will be disabled. + */ public void setCommandExecutor(ActionCommandExecutor commandExecutor) { if (ObjectUtils.nullSafeEquals(this.commandExecutor, commandExecutor)) { return; @@ -58,6 +88,11 @@ } } + /** + * Attaches the currently assigned command executor to this instance. The command will + * be enabled by default unless the executor is a [EMAIL PROTECTED] GuardedActionCommandExecutor}, + * in which case the command will be assigned the enabled state of the executor. + */ private void attachCommandExecutor() { if (this.commandExecutor instanceof GuardedActionCommandExecutor) { GuardedActionCommandExecutor dynamicHandler = (GuardedActionCommandExecutor)commandExecutor; @@ -68,7 +103,7 @@ setEnabled(true); } if (logger.isDebugEnabled()) { - logger.debug("Command delegate '" + this.commandExecutor + "' attached."); + logger.debug("Command executor '" + this.commandExecutor + "' attached."); } } @@ -81,6 +116,9 @@ ((GuardedActionCommandExecutor)commandExecutor).addEnabledListener(guardRelay); } + /** + * Detaches the current executor from this command and sets the command to disabled state. + */ public void detachCommandExecutor() { if (this.commandExecutor instanceof GuardedActionCommandExecutor) { unsubscribeFromGuardedCommandDelegate(); @@ -94,12 +132,17 @@ ((GuardedActionCommandExecutor)this.commandExecutor).removeEnabledListener(guardRelay); } + /** + * Executes this command by delegating to the currently assigned executor. + */ protected void doExecuteCommand() { - if (commandExecutor instanceof ParameterizableActionCommandExecutor) { - ((ParameterizableActionCommandExecutor)commandExecutor).execute(getParameters()); + if (this.commandExecutor instanceof ParameterizableActionCommandExecutor) { + ((ParameterizableActionCommandExecutor) this.commandExecutor).execute(getParameters()); } else { - commandExecutor.execute(); + if (this.commandExecutor != null) { + this.commandExecutor.execute(); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ spring-rich-c-cvs mailing list spring-rich-c-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs