Cytoscape 2.7.0 (c) 2006,2007 ISB, MSKCC, UCSD

cytoscape.command
Class AbstractCommandHandler

java.lang.Object
  extended by cytoscape.command.AbstractCommandHandler
All Implemented Interfaces:
CyCommandHandler

public abstract class AbstractCommandHandler
extends Object
implements CyCommandHandler

This abstract class provides a convenient (but not necessary) base class for writing CyCommandHandlers. It may be used whether your handler handles a single command or multiple commands. The general use of this base class is to add a set of known arguments using the addArgument(java.lang.String)() method and addDescription(java.lang.String, java.lang.String)() methods within the constructor of your command handler:


 public class MyCommandHandler extends AbstractCommandHandler {
   // Define our command name
   private static String COMMAND = "my command";

   // Settings
   private static String ARGKEY1 = "argkey1";
   private static String ARGKEY2 = "argkey2";
   private static String ARGKEY3 = "argkey3";

   public MyCommandHandler(CyCommandNamespace ns) {
     super(ns);
     addDescription(java.lang.String, java.lang.String)(COMMAND, "This command does something really cool");
     addArgument(java.lang.String)(COMMAND, ARGKEY1);
     addArgument(java.lang.String)(COMMAND, ARGKEY2);
     addArgument(java.lang.String)(COMMAND, ARGKEY3, "defaultValue");
   }

   public CyCommandResult execute(String command, Map<String, Object>args) throws CyCommandException {
     // Your execution code goes here....
   }
   ... or ...
   public CyCommandResult execute(String command, Collection<Tunable>args) throws CyCommandException {
     // Your execution code goes here....
   }
 }
 
Note that both of the two CyCommandHandler.execute(java.lang.String, java.util.Map) methods must be overridden, but only one of which must include your functionality. AbstractCommandHandler provides two additional methods to assist command authors with the conversion between the two execute methods. If your plugin uses Tunables, to handle the Map version of the execute method, implement the following method:
 public class execute(String command, Map arguments) {
   return execute(command, createTunableCollection(arguments));
 } 
 
where the createTunableCollection method will create a list of Tunables to call the Tunable version of execute. On the other hand, if your plugin does not use Tunables, you can use:
 public CyCommandResult execute(String command, Collection arguments) {
   return execute(command, createKVMap(arguments));
 }
 
where the createKVMap method will take a Collection of Tunables and create the corresponding Map to call your execute method. The addDescription(java.lang.String, java.lang.String)() method is used by the AbstractCommandHandler's getDescription(java.lang.String)() method to produce a formatted description of the command, including the namespace, command name, description, and options (with default values). To avoid the formatting and provide your own full description, just override the getDescription() method and return your own description. Also note that the CyCommandNamespace must be reserved before the command handler is initialized.


Constructor Summary
AbstractCommandHandler(CyCommandNamespace ns)
          You do not need to call this constructor from you class, but if you don't, you will need to make sure you assign the namespace appropriately.
 
Method Summary
 List<String> getArguments(String command)
          Return the arguments for a given command
 List<String> getCommands()
          Return the command or commands supported by this handler
 String getDescription(String command)
          This method returns a formatted description of the command, including the namespace, command name, plugin-provided description, and arguments.
 Map<String,Object> getSettings(String command)
          Return the current settings for a given command.
 Map<String,Tunable> getTunables(String command)
          Return the current settings for a given command as a map of setting name: tunable.
static Tunable makeTunable(String name, Object value)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cytoscape.command.CyCommandHandler
execute, execute
 

Constructor Detail

AbstractCommandHandler

public AbstractCommandHandler(CyCommandNamespace ns)
You do not need to call this constructor from you class, but if you don't, you will need to make sure you assign the namespace appropriately.

Parameters:
ns - the CyCommandNamespace for this command
Method Detail

getCommands

public List<String> getCommands()
Return the command or commands supported by this handler

Specified by:
getCommands in interface CyCommandHandler
Returns:
a list of strings with one or more commands

getArguments

public List<String> getArguments(String command)
Return the arguments for a given command

Specified by:
getArguments in interface CyCommandHandler
Parameters:
command - the command to check for arguments
Returns:
the list of arguments this command will take

getSettings

public Map<String,Object> getSettings(String command)
Return the current settings for a given command. At this point, for simplicity the only Object type supported as values are those that have "toString()" methods. This allows for simple mappings between textual input and settings without resorting to inspection of the object types. This signature is expected to be removed sometime in the 3.0 timeframe and only the getTunables version will remain.

Specified by:
getSettings in interface CyCommandHandler
Parameters:
command - the command we want the settings for
Returns:
the current settings as a map

getTunables

public Map<String,Tunable> getTunables(String command)
Return the current settings for a given command as a map of setting name: tunable.

Specified by:
getTunables in interface CyCommandHandler
Parameters:
command - the command we want the settings for
Returns:
the current settings as a map of setting name: tunable.

getDescription

public String getDescription(String command)
This method returns a formatted description of the command, including the namespace, command name, plugin-provided description, and arguments. Override this to provide your own description.

Specified by:
getDescription in interface CyCommandHandler
Parameters:
command - the command we're inquiring about
Returns:
the description/documentation for this command

makeTunable

public static Tunable makeTunable(String name,
                                  Object value)

www.cytoscape.org