com.levigo.util.swing.action.injection
Class InjectedCommand

java.lang.Object
  extended by com.levigo.util.swing.action.injection.InjectedCommand
All Implemented Interfaces:
Command
Direct Known Subclasses:
AbstractContextCommand, AbstractNavigablePreviewCommand, ShowProductInfoWindowCommand, ThumbnailResizeCommand, ToggleCaseSensitiveCommand, ToggleToolbarVisibilityCommand, ToggleWholeWordsOnlyCommand

public abstract class InjectedCommand
extends Object
implements Command

An abstract Command which relieves its subclasses from the chore of dealing with the extraction and validation of arguments from the context. This happens by the way of argument injection. Setters annotated with Argument are automatically injected with the necessary arguments prior to command execution.


Constructor Summary
InjectedCommand()
           
 
Method Summary
protected  boolean canExecute()
          Subclasses may override this method to perform argument validation beyond the validation that happens automatically during the injection phase.
 boolean canExecute(Collection<Object> args)
          Permission checking for a command works as follows:
protected abstract  void execute()
          This method is called in order to execute the command.
 void execute(Collection<Object> args)
          Execute the command.
protected  String getKey()
           
 boolean isAvailable()
          Returns an indicator whether the command is available and therefore integrable.
protected  boolean isSelected()
          Returns the selected state of this command.
 boolean isSelected(Collection<Object> args)
          Returns the selected state of this command.
 void setKey(String key)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InjectedCommand

public InjectedCommand()
Method Detail

canExecute

public final boolean canExecute(Collection<Object> args)
Description copied from interface: Command
Permission checking for a command works as follows:

1. Check user privileges if the command is executable.
2. Ask if the command is executable with the given objects.

Specified by:
canExecute in interface Command
Parameters:
args - arguments for the command
Returns:
true - executable with these arguments,
false - impossible to execute this command with these arguments

canExecute

protected boolean canExecute()
Subclasses may override this method to perform argument validation beyond the validation that happens automatically during the injection phase. This method is called after the context has been found to match the requirements specified via the Argument annotations and the arguments have been injected.

Returns:
true if the command can/may be executed in the current context, false otherwise.

execute

public final void execute(Collection<Object> args)
Description copied from interface: Command
Execute the command.

Specified by:
execute in interface Command
Parameters:
args - arguments for the command (contains all items for all actions inside of the context!)

execute

protected abstract void execute()
This method is called in order to execute the command. It is only called, after the arguments have been validated and injected and only if canExecute() has returned true.


isSelected

public final boolean isSelected(Collection<Object> args)
Description copied from interface: Command
Returns the selected state of this command. This is typically used only for commands with a meaningful selection state.

Specified by:
isSelected in interface Command
Parameters:
args - arguments for the command
Returns:
true - selected with these arguments,
false - not selected with these arguments
See Also:
Command.isSelected(java.util.Collection)

isSelected

protected boolean isSelected()
Returns the selected state of this command. This is typically used only for commands with a meaningful selection state.

Returns:
the selected state

isAvailable

public boolean isAvailable()
Description copied from interface: Command
Returns an indicator whether the command is available and therefore integrable.

Specified by:
isAvailable in interface Command
Returns:
true - available false - not available
See Also:
Command.isAvailable()

setKey

public void setKey(String key)

getKey

protected String getKey()


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.