|
Cytoscape 2.7.0 (c) 2006,2007 ISB, MSKCC, UCSD | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcytoscape.command.AbstractCommandHandler
public abstract class AbstractCommandHandler
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 Tunable
s, 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 Tunable
s to call the Tunable version of execute. On
the other hand, if your plugin does not use Tunable
s, 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 |
---|
public AbstractCommandHandler(CyCommandNamespace ns)
ns
- the CyCommandNamespace
for this commandMethod Detail |
---|
public List<String> getCommands()
getCommands
in interface CyCommandHandler
public List<String> getArguments(String command)
getArguments
in interface CyCommandHandler
command
- the command to check for arguments
public Map<String,Object> getSettings(String command)
getSettings
in interface CyCommandHandler
command
- the command we want the settings for
public Map<String,Tunable> getTunables(String command)
getTunables
in interface CyCommandHandler
command
- the command we want the settings for
public String getDescription(String command)
getDescription
in interface CyCommandHandler
command
- the command we're inquiring about
public static Tunable makeTunable(String name, Object value)
|
www.cytoscape.org | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |