org.bs.mdi
Class Command

java.lang.Object
  extended byorg.bs.mdi.Command
All Implemented Interfaces:
MessageProcessor
Direct Known Subclasses:
SwingCommand

public abstract class Command
extends Object
implements MessageProcessor

Base class for all commands which can be triggered by users


Constructor Summary
protected Command()
          Creates a new command.
 
Method Summary
 void addTrigger(CommandTrigger trigger)
          Associates the given command trigger with this command.
 int countTriggers()
          Counts the number of associated command triggers.
protected abstract  void doExecute()
          Executes this command.
 void execute(CommandTrigger source)
          Executes this command and notifies all CommandTriggerGroups.
abstract  String getDescription()
          Gets the description of this command, e.g.
 String getLocalizedDescription()
          Gets the localized description of this command.
 String getLocalizedName()
          Gets the localized name of this command.
abstract  String getName()
          Gets the name of this command, e.g.
protected  List getTriggers()
          Gets a list of all triggers associated with this command.
 boolean isAvailable()
          Indicates whether this command is available or not.
abstract  void processMessage(Object source, int type, Object argument)
          Processes messages.
 void removeAllTriggers()
          Removes all associations between command triggers and this command.
 void removeTrigger(CommandTrigger trigger)
          Removes the association between the given command trigger and this command.
 void setAvailable(boolean available)
          Sets the available status of this command.
 void updateTriggers()
          Calls CommandTrigger.commandUpdated() on every associated trigger.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Command

protected Command()
Creates a new command.

Method Detail

execute

public void execute(CommandTrigger source)
Executes this command and notifies all CommandTriggerGroups.


doExecute

protected abstract void doExecute()
Executes this command.


setAvailable

public void setAvailable(boolean available)
Sets the available status of this command. Available means that this command can be executed and that it makes sense to execute it.

Parameters:
available - true if this command should be available, false otherwise

isAvailable

public boolean isAvailable()
Indicates whether this command is available or not. Available means that this command can be executed and that it makes sense to execute it.

Returns:
true if the command is available, false otherwise

processMessage

public abstract void processMessage(Object source,
                                    int type,
                                    Object argument)
Processes messages. Using these messages, this method should try to determine if the command should be available or not and set the available status using setAvailable(boolean). See: MessageProcessor.processMessage(Object, int, Object)

Specified by:
processMessage in interface MessageProcessor
Parameters:
source - the source where this message originated from
type - the message type
argument - an optional argument

getName

public abstract String getName()
Gets the name of this command, e.g. "Undo".

Returns:
the command's name

getLocalizedName

public String getLocalizedName()
Gets the localized name of this command.

Returns:
the command's localized name

getDescription

public abstract String getDescription()
Gets the description of this command, e.g. "undoes the last modification".

Returns:
the command's description

getLocalizedDescription

public String getLocalizedDescription()
Gets the localized description of this command.

Returns:
the command's localized description

addTrigger

public void addTrigger(CommandTrigger trigger)
Associates the given command trigger with this command. The command trigger will be notified when the available status of this command changes.

Parameters:
trigger - the command trigger

removeTrigger

public void removeTrigger(CommandTrigger trigger)
Removes the association between the given command trigger and this command.

Parameters:
trigger - the command trigger

removeAllTriggers

public void removeAllTriggers()
Removes all associations between command triggers and this command.


countTriggers

public int countTriggers()
Counts the number of associated command triggers.

Returns:
the number of command triggers

getTriggers

protected List getTriggers()
Gets a list of all triggers associated with this command.

Returns:
the list of triggers

updateTriggers

public void updateTriggers()
Calls CommandTrigger.commandUpdated() on every associated trigger.