T-Plan Robot Enterprise 3.5.1
Build No. 3.5.1-20140411.1

com.tplan.robot.scripting.commands.impl
Class TimerCommand

java.lang.Object
  extended by com.tplan.robot.scripting.commands.AbstractCommandHandler
      extended by com.tplan.robot.scripting.commands.impl.TimerCommand
All Implemented Interfaces:
GUIConstants, Plugin, Configurable, AdvancedCommandHandler, CommandHandler, EditorFriendlyCommandHandler

public class TimerCommand
extends AbstractCommandHandler
implements Plugin, AdvancedCommandHandler, EditorFriendlyCommandHandler

Handler implementing functionality of the Timer command.


T-Plan Robot Enterprise, (C) 2009-2014 T-Plan Limited. All rights reserved.


Field Summary
static String CFG_REPORT_TIME_FORMAT
           
static String PARAM_ACTION
           
static String PARAM_ACTION_PREVIOUS
           
static String PARAM_ACTION_START
           
static String PARAM_ACTION_STOP
           
static String PARAM_DESC
           
static String PARAM_GROUP
           
static String PARAM_LOAD
           
static String PARAM_NAME
           
static String PARAM_REFVALUE
           
static String PARAM_UNGROUP
           
static String PARAM_VALUE
           
static String VAR_TIMER_ERROR
           
 
Fields inherited from class com.tplan.robot.scripting.commands.AbstractCommandHandler
ALT, CONTEXT_COMMAND_CALL_COMPILED_PARAMETER_MAP, CONTEXT_COMMAND_CALL_SOURCE_PARAMETER_MAP, CONTEXT_COMPILE_SINGLE_COMMAND_MODE, CONTEXT_LAST_WAIT_FACTOR, CONTEXT_WAIT_FACTOR_ERR_MSG_SHOWN, CTRL, PARAM_COUNT, PARAM_ONFAIL, PARAM_ONPASS, PARAM_WAIT, SHIFT, WINDOWS
 
Fields inherited from interface com.tplan.robot.scripting.commands.EditorFriendlyCommandHandler
CATEGORY_ADMIN, CATEGORY_DESKTOP, CATEGORY_IMAGE_OPS, CATEGORY_IO, CATEGORY_REPORTING, CATEGORY_UNKNOWN
 
Fields inherited from interface com.tplan.robot.gui.GUIConstants
DEFAULT_TPLAN_ROBOT_FILE_EXTENSION, EVENT_ADD_CUSTOM_ACTION_MSG, EVENT_ADD_STABLE_ACTION_MSG, EVENT_DISPLAY_HASHTABLE, EVENT_DISPLAY_PREFERENCES, EVENT_DOCUMENT_CHANGED, EVENT_MOUSE_MOVED, EVENT_REMOVE_CUSTOM_ACTION_MSG, EVENT_REMOVE_STABLE_ACTION_MSG, EVENT_SELECTION_CHANGED, EVENT_STATUSBAR_MSG, HELP_URL_JAPI, HELP_URL_SPEC, HELP_URLS
 
Constructor Summary
TimerCommand()
           
 
Method Summary
 boolean canRunWithoutConnection()
          This command doesn't require connection to a server to run.
 void checkDependencies(PluginManager manager)
          Check whether the current product installation contains all dependencies (other plugins) required to install this plugin.
 void checkVisualParameters(Map<String,CharSequence> parameters, TestScriptInterpret interpret)
          Check (compile) the map of parameters retrieved through the command editor window before they are used to build and/or update the command or Java method call.
 int execute(List args, Map values, ScriptingContext ctx)
          Execute the command.
 List getArguments(String command, ScriptingContext context)
          Get the list of supported arguments.
 int getCategory(StringBuilder description)
          Get the category the command falls to.
 String[] getCommandNames()
          Get the command name ("step").
 String getContextArgument()
          Implementation of the getContextArgument() method.
 Map getContextAttributes()
          Get a map with context attributes.
 KeyStroke getContextShortcut()
          Get preferred hot key for the GUI command wizard.
 String getDescription()
          Get plugin description to be displayed in the GUI.
 String getDisplayName()
          Get a generic display name.
 List getParameters(String command, ScriptingContext context)
          Get the list of supported parameters.
 List getParameterValues(String paramName, String command, ScriptingContext context)
          Get values of a particular parameter.
 List<Preference> getPreferences()
          Get metadata of displayable/editable configurable parameters.
 String getShortDescription(Map<String,String> parameters, TestScriptInterpret interpret)
          Get short description (up to 50 chars) of what the command does.
 String getUniqueId()
          Get unique ID associated with the plugin.
 List<Preference> getVisualParameters(LinkedHashMap<String,Object> parameters, TestScriptInterpret interpret)
          Get the list of visual parameters for construction of a dynamic command editor window.
 boolean hasCustomParameterComponent(LinkedHashMap<String,Object> parameters, TestScriptInterpret interpret, PreferencePanel[] panel)
          Specify whether the command provides a custom preference panel.
 boolean hasCustomPropertyDialog(LinkedHashMap<String,Object> parameters, TestScriptInterpret interpret, int offset, Action[] action)
          Specify whether the command provides a custom editor.
 boolean hasFixedArgument(List<String> arguments)
          Defines whether the command uses a fixed argument (one-of-a-list).
 void validate(List args, Map values, Map variableContainer, ScriptingContext ctx)
          Compile a command instance.
 
Methods inherited from class com.tplan.robot.scripting.commands.AbstractCommandHandler
addCommandListener, checkPauseAndStop, compileParameters, createConfigureAction, executeFallBackCodeOrProcedure, fireCommandEvent, getBooleanSafely, getCode, getDate, getImplementedInterface, getIntegerSafely, getLowestSupportedVersion, getMessageAfterInstall, getMessageBeforeInstall, getStablePopupMenuItems, getSupportContact, getVendorHomePage, getVendorName, getVersion, isGlobalPrerequisity, multiplyWaitTime, reloadCommand, removeCommandListener, requiresOriginalValues, requiresRestart, setConfiguration, toLinkedMap, validateOnPassAndOnFail, wait
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.tplan.robot.plugin.Plugin
getCode, getDate, getImplementedInterface, getLowestSupportedVersion, getMessageAfterInstall, getMessageBeforeInstall, getSupportContact, getVendorHomePage, getVendorName, getVersion, requiresRestart
 
Methods inherited from interface com.tplan.robot.scripting.commands.CommandHandler
addCommandListener, getStablePopupMenuItems, isGlobalPrerequisity, removeCommandListener
 

Field Detail

PARAM_NAME

public static final String PARAM_NAME
See Also:
Constant Field Values

PARAM_GROUP

public static final String PARAM_GROUP
See Also:
Constant Field Values

PARAM_UNGROUP

public static final String PARAM_UNGROUP
See Also:
Constant Field Values

PARAM_VALUE

public static final String PARAM_VALUE
See Also:
Constant Field Values

PARAM_DESC

public static final String PARAM_DESC
See Also:
Constant Field Values

PARAM_REFVALUE

public static final String PARAM_REFVALUE
See Also:
Constant Field Values

PARAM_LOAD

public static final String PARAM_LOAD
See Also:
Constant Field Values

PARAM_ACTION

public static final String PARAM_ACTION
See Also:
Constant Field Values

PARAM_ACTION_START

public static final String PARAM_ACTION_START
See Also:
Constant Field Values

PARAM_ACTION_STOP

public static final String PARAM_ACTION_STOP
See Also:
Constant Field Values

PARAM_ACTION_PREVIOUS

public static final String PARAM_ACTION_PREVIOUS
See Also:
Constant Field Values

CFG_REPORT_TIME_FORMAT

public static final String CFG_REPORT_TIME_FORMAT
See Also:
Constant Field Values

VAR_TIMER_ERROR

public static final String VAR_TIMER_ERROR
See Also:
Constant Field Values
Constructor Detail

TimerCommand

public TimerCommand()
Method Detail

getContextShortcut

public KeyStroke getContextShortcut()
Description copied from interface: CommandHandler
Get preferred hot key for the GUI command wizard. When such a key is pressed in the editor, the GUI inserts the command template into the editor document. The key returned by this method is just a recommendation and the GUI may decide to assign another one to the command, for example when there is a conflict with another existing one.

Specified by:
getContextShortcut in interface CommandHandler
Overrides:
getContextShortcut in class AbstractCommandHandler
Returns:
hot key invoking insertion of a command template into the GUI editor..

getContextAttributes

public Map getContextAttributes()
Get a map with context attributes.

Specified by:
getContextAttributes in interface CommandHandler
Overrides:
getContextAttributes in class AbstractCommandHandler
Returns:
A hash table containing complete list of supported parameters and their descriptions or list of values.

getContextArgument

public String getContextArgument()
Implementation of the getContextArgument() method. It is necessary as this command has a mandatory argument, which is the test step name.

Specified by:
getContextArgument in interface CommandHandler
Overrides:
getContextArgument in class AbstractCommandHandler
Returns:
description of the mandatory argument.

getCommandNames

public String[] getCommandNames()
Get the command name ("step").

Specified by:
getCommandNames in interface CommandHandler
Returns:
command name.

canRunWithoutConnection

public boolean canRunWithoutConnection()
This command doesn't require connection to a server to run.

Specified by:
canRunWithoutConnection in interface CommandHandler
Overrides:
canRunWithoutConnection in class AbstractCommandHandler
Returns:
always returns true.

validate

public void validate(List args,
                     Map values,
                     Map variableContainer,
                     ScriptingContext ctx)
              throws SyntaxErrorException
Compile a command instance.

Specified by:
validate in interface CommandHandler
Parameters:
args - arguments and parameter names.
values - map of parameter names and values.
variableContainer - a new map for processed parameter/value pairs.
ctx - scripting context.
Throws:
SyntaxErrorException - on syntax error.

execute

public int execute(List args,
                   Map values,
                   ScriptingContext ctx)
            throws SyntaxErrorException,
                   IOException
Description copied from interface: CommandHandler

Execute the command.

Argument context will contain all necessary objects that the command may possibly use, for example the com.tplan.robot.gui.FrameBufferPanel and com.tplan.robot.api.rfb.RfbModule instances etc. If the command e.g. needs to send some key events to the RFB server, you should save the reference to the RfbModuleImpl instance and use its methods to fire the required key events.

Specified by:
execute in interface CommandHandler
Parameters:
args - a list of parameters.
values - a map of [param, value] pairs resulted from parsing of the command.
ctx - execution context.
Returns:
command exit code.
Throws:
SyntaxErrorException - when the command doesn't meet the required syntax.
IOException - an instance of I/O exception may be thrown if an error occurs in communication with the underlying desktop client.

getPreferences

public List<Preference> getPreferences()
Description copied from interface: Configurable
Get metadata of displayable/editable configurable parameters. This method should declare a list of metadata for all configurable parameters which may be editable in the GUI. If the returned list is not null and contains at least one parameter, it gets picked up by the Preferences dialog which creates a panel with GUI components allowing to edit the declared configuration parameters.

Specified by:
getPreferences in interface Configurable
Overrides:
getPreferences in class AbstractCommandHandler
Returns:
a list of metadata for all public editable configuration parameters.

getDisplayName

public String getDisplayName()
Description copied from class: AbstractCommandHandler
Get a generic display name.

Specified by:
getDisplayName in interface Plugin
Overrides:
getDisplayName in class AbstractCommandHandler
Returns:
generic display name which is derived from the AbstractCommandHandler.getCmdDisplayName() method.

getDescription

public String getDescription()
Description copied from interface: Plugin
Get plugin description to be displayed in the GUI.

Specified by:
getDescription in interface Plugin
Overrides:
getDescription in class AbstractCommandHandler
Returns:
plugin description. May be null.

getUniqueId

public String getUniqueId()
Description copied from interface: Plugin

Get unique ID associated with the plugin. The plugin manager uses the ID together with the version string to identify whether a plugin is already installed and whether a newer version of the same plugin is available.

The unique ID in fact identifies a particular plugin delivered by a particular vendor. Plugin developers are recommended to choose an ID and keep it constant for all versions of one particular plugin. The ID is never displayed in the GUI so it doesn't have to be a readable text. To avoid conflicts with other vendors it is recommended to elaborate vendor or author name and feature description into the ID, for example "custom RFB client implemented by John Doe".

Specified by:
getUniqueId in interface Plugin
Overrides:
getUniqueId in class AbstractCommandHandler
Returns:
unique plugin ID.

checkDependencies

public void checkDependencies(PluginManager manager)
                       throws DependencyMissingException
Description copied from interface: Plugin
Check whether the current product installation contains all dependencies (other plugins) required to install this plugin. This method is called before the plugin is installed and it should throw a DependencyMissingException if one or more dependencies are missing.

Specified by:
checkDependencies in interface Plugin
Overrides:
checkDependencies in class AbstractCommandHandler
Parameters:
manager - shared instance of the plugin manager.
Throws:
DependencyMissingException - when one or more dependencies requested by this plugin is missing.

getArguments

public List getArguments(String command,
                         ScriptingContext context)
Description copied from interface: AdvancedCommandHandler
Get the list of supported arguments. For example, the Mouse command should return a list containing "click", "move" etc. Commands which have no argument and rely just on parameters (param=value) should return null.

Specified by:
getArguments in interface AdvancedCommandHandler
Parameters:
command - the current command.
context - a context.
Returns:
list of supported argument values.

getParameters

public List getParameters(String command,
                          ScriptingContext context)
Description copied from interface: AdvancedCommandHandler
Get the list of supported parameters. Command handlers are free to parse the current command and return a filtered list depending on what is already specified. Parameters in the list should be String instances. If they are other objects than String, they may or may not be handled well depending on what the GUI supports.

Specified by:
getParameters in interface AdvancedCommandHandler
Parameters:
command - the current conmmand text (complete).
context - a context.
Returns:
list of supported parameter names.

getParameterValues

public List getParameterValues(String paramName,
                               String command,
                               ScriptingContext context)
Description copied from interface: AdvancedCommandHandler
Get values of a particular parameter. This is to be used for parameters which have a fixed set of acceptable values. The command wizard typically displays the values as a list.

Specified by:
getParameterValues in interface AdvancedCommandHandler
Parameters:
paramName - parameter name.
command - the current conmmand text (complete).
context - a context.
Returns:
list of supported parameter values.

getShortDescription

public String getShortDescription(Map<String,String> parameters,
                                  TestScriptInterpret interpret)
Description copied from interface: EditorFriendlyCommandHandler
Get short description (up to 50 chars) of what the command does. This will be used for the list (menu) of available actions in the GUI.

Specified by:
getShortDescription in interface EditorFriendlyCommandHandler
Parameters:
parameters - map of parameters and their values. All values are in the format recognized by token parser (TokenParserImpl.getParser()) which may be used to convert them to native Java objects such as Number, Point, Rectangle etc.
interpret - test script interpret owning the edited script.
Returns:
short command description.

getVisualParameters

public List<Preference> getVisualParameters(LinkedHashMap<String,Object> parameters,
                                            TestScriptInterpret interpret)
Description copied from interface: EditorFriendlyCommandHandler

Get the list of visual parameters for construction of a dynamic command editor window.

This method will be called only after the EditorFriendlyCommandHandler.hasCustomPropertyDialog(java.util.LinkedHashMap, com.tplan.robot.scripting.interpret.TestScriptInterpret, int, javax.swing.Action[]) and EditorFriendlyCommandHandler.hasCustomParameterComponent(java.util.LinkedHashMap, com.tplan.robot.scripting.interpret.TestScriptInterpret, com.tplan.robot.gui.preferences.PreferencePanel[]) methods return false.

Specified by:
getVisualParameters in interface EditorFriendlyCommandHandler
Parameters:
parameters - input parameters parsed from the already existing command or preselected through the Command Wizard menu.
interpret - test script interpret owning the edited script.
Returns:
list of visual parameters. If the list is null and the command does not provide a custom component through the EditorFriendlyCommandHandler.hasCustomPropertyDialog(java.util.LinkedHashMap, com.tplan.robot.scripting.interpret.TestScriptInterpret, int, javax.swing.Action[]) and EditorFriendlyCommandHandler.hasCustomParameterComponent(java.util.LinkedHashMap, com.tplan.robot.scripting.interpret.TestScriptInterpret, com.tplan.robot.gui.preferences.PreferencePanel[]) methods, it will be considered as not editable through the GUI.

hasFixedArgument

public boolean hasFixedArgument(List<String> arguments)
Description copied from interface: EditorFriendlyCommandHandler
Defines whether the command uses a fixed argument (one-of-a-list). Examples of such commands are Mouse with the arguments of "click", "press" etc. or WaitFor ("match", "mismatch",...). If the command does use a fixed argument it is supposed to return true and populate the argument list with the argument values (if the list is not null).

Specified by:
hasFixedArgument in interface EditorFriendlyCommandHandler
Parameters:
arguments - optional output list for the argument values.
Returns:
true if the command uses fixed argument values, false if not.

getCategory

public int getCategory(StringBuilder description)
Description copied from interface: EditorFriendlyCommandHandler
Get the category the command falls to. The method may return one of the predefined CATEGORY_XXX constants defined by this class. Commands which do not fall into any specified category may return EditorFriendlyCommandHandler.CATEGORY_UNKNOWN or a code outside of the recognized constants and pass the desired category name through the argument string builder instance.

Specified by:
getCategory in interface EditorFriendlyCommandHandler
Parameters:
description - string buffer for category name. It is only used if the returned value is other than the standard ones.
Returns:
category code.

checkVisualParameters

public void checkVisualParameters(Map<String,CharSequence> parameters,
                                  TestScriptInterpret interpret)
                           throws IllegalArgumentException
Description copied from interface: EditorFriendlyCommandHandler

Check (compile) the map of parameters retrieved through the command editor window before they are used to build and/or update the command or Java method call. This method may be also used to remove or filter the parameters. This is especially useful if the command editor uses auxiliary settings which are not recognized by the command or method at runtime.

If the command handler extends the AbstractCommandHandler class, it may take advantage of the AbstractCommandHandler.compileParameters(java.util.Map, com.tplan.robot.scripting.interpret.TestScriptInterpret) method which converts a copy of the input map to the legacy parameter format and passes it to the CommandHandler.validate(java.util.List, java.util.Map, java.util.Map, com.tplan.robot.scripting.ScriptingContext) method to verify whether the parameters are recognized and their values are acceptable. This allows to avoid duplication of parameter parsing and compilation code.

Specified by:
checkVisualParameters in interface EditorFriendlyCommandHandler
Parameters:
parameters - map of parameters and their values. All values are in the format recognized by token parser (TokenParserImpl.getParser()) which may be used to convert them to native Java objects such as Number, Point, Rectangle etc.
interpret - test script interpret owning the edited script.
Throws:
IllegalArgumentException - when one or more parameters is not recognized or its value is invalid. The exception should contain a descriptive message because it will be displayed by the GUI.

hasCustomParameterComponent

public boolean hasCustomParameterComponent(LinkedHashMap<String,Object> parameters,
                                           TestScriptInterpret interpret,
                                           PreferencePanel[] panel)
Description copied from interface: EditorFriendlyCommandHandler
Specify whether the command provides a custom preference panel. If it does it is expected to return true and populate the first field of the panel array with an instance of the panel.

Specified by:
hasCustomParameterComponent in interface EditorFriendlyCommandHandler
Parameters:
parameters - map of parameters and their values. All values are in the format recognized by token parser (TokenParserImpl.getParser()) which may be used to convert them to native Java objects such as Number, Point, Rectangle etc.
interpret - test script interpret owning the edited script.
panel - output array of length=1 which should be populated inside the method with the custom panel instance if the method returns true.
Returns:
true if the command creates its own custom preference panel or false otherwise.

hasCustomPropertyDialog

public boolean hasCustomPropertyDialog(LinkedHashMap<String,Object> parameters,
                                       TestScriptInterpret interpret,
                                       int offset,
                                       Action[] action)
Description copied from interface: EditorFriendlyCommandHandler

Specify whether the command provides a custom editor. If it does it is expected to return true and populate the first field of the action array with an instance of an Action which opens up the dialog.

Even though the method is implemented to return false, it may be also used to preprocess parameters parsed from an existing command call before they reach the command editor window. The method may for example change the parameters or their values in the input map. As the argument map the real one rather than a copy, any data change will hold in there and it will be reflected in the GUI.

Specified by:
hasCustomPropertyDialog in interface EditorFriendlyCommandHandler
Parameters:
parameters - map of parameters and their values. All values are in the format recognized by token parser (TokenParserImpl.getParser()) which may be used to convert them to native Java objects such as Number, Point, Rectangle etc.
interpret - test script interpret owning the edited script.
offset - position in the edited script.
action - output array of length=1 which should be populated inside the method with an Action instance if the method returns true.
Returns:
true if the command creates its own dialog or false otherwise.

T-Plan Robot Enterprise 3.5.1
Build No. 3.5.1-20140411.1