|
Cytoscape 2.8.0 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cytoscape.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.
Field Summary | |
---|---|
protected Map<String,List<Tunable>> |
argumentMap
|
protected Map<String,String> |
descriptionMap
|
protected CyCommandNamespace |
namespace
|
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 | |
---|---|
protected void |
addArgument(String command)
This method adds a new command to the list of command supported by this command handler. |
protected void |
addArgument(String command,
String vKey)
Add a new argument key to a command supported by this command handler. |
protected void |
addArgument(String command,
String vKey,
String value)
Add a new argument key with a value to a command supported by this command handler. |
protected void |
addArgument(String command,
Tunable t)
Add a new argument Tunable to a command supported by this command handler. |
protected void |
addDescription(String command,
String description)
This method adds a new description for a command supported by this command handler. |
protected Map<String,Object> |
createKVMap(Collection<Tunable> tList)
Execute a given command with a particular set of arguments. |
protected Collection<Tunable> |
createTunableCollection(Map<String,Object> args)
Use this method to support the Map version of the execute call if you support Tunables. |
protected String |
getArg(String command,
String key,
Map<String,Object> args)
Return the string value of a specific argument from an args map. |
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 |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface cytoscape.command.CyCommandHandler |
---|
execute, execute |
Field Detail |
---|
protected Map<String,List<Tunable>> argumentMap
protected Map<String,String> descriptionMap
protected CyCommandNamespace namespace
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
protected Map<String,Object> createKVMap(Collection<Tunable> tList)
public CyCommandResult execute(String command, Collection<Tunable>args) throws CyCommandException {
return execute(command, createKVMap(args));
}
assuming that you've implemented the Map
tList
- a Collection of Tunables
protected Collection<Tunable> createTunableCollection(Map<String,Object> args)
public CyCommandResult execute(String command, Map<String,Object>args) throws CyCommandException {
return execute(command, createTunableCollection(args));
}
assuming that you've implemented the Collection
args
- a Map of String,Object pairs
protected void addDescription(String command, String description)
command
- the name of the command to add the description todescription
- the description to addprotected void addArgument(String command)
command
- the name of the command to addprotected void addArgument(String command, String vKey)
command
- the name of the command to add this argument key tovKey
- the key to addprotected void addArgument(String command, String vKey, String value)
command
- the name of the command to add this argument key tovKey
- the key to addvalue
- the value to associate with the keyprotected void addArgument(String command, Tunable t)
command
- the name of the command to add this argument key tot
- the Tunable to addprotected String getArg(String command, String key, Map<String,Object> args)
command
- the command we're getting the argument forkey
- the argument we're interested inargs
- the map of arguments that was passed to us
public static Tunable makeTunable(String name, Object value)
|
Cytoscape 2.8.0 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |