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

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

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

public class ReportCommand
extends AbstractCommandHandler
implements AdvancedCommandHandler, EditorFriendlyCommandHandler, ConfigurationChangeListener

Handler implementing functionality of the Report command.


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


Nested Class Summary
protected  class ReportCommand.ReportAction
           
 
Field Summary
static String PARAM_DESC
           
static String PARAM_FILENAME
           
static String PARAM_PROVIDER
           
static String PARAM_SCOPE
           
static String PARAM_ZIP
           
static String SCOPE_ALL
           
static String SCOPE_COMBINED
           
static String SCOPE_FILE
           
 
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
ReportCommand()
           
 
Method Summary
 boolean canRunWithoutConnection()
          This method should return true if it can be executed even when the tool is not connected to a desktop.
 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.
 void configurationChanged(ConfigurationChangeEvent evt)
          This method gets called when a configuration parameter is changed.
 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 command names.
 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.
static Map<String,List<ReportProvider>> getFormatToProviderMap()
           
 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.
static JFileChooser getReportFileChooser(String file, ScriptingContext context, File folder)
           
 String getShortDescription(Map<String,String> parameters, TestScriptInterpret interpret)
          Get short description (up to 50 chars) of what the command does.
 List<Preference> getVisualParameters(LinkedHashMap<String,Object> parameters, TestScriptInterpret interpret)
          Get the list of visual parameters for construction of a dynamic command editor window.
protected  int handleReportEvent(ScriptingContext ctx, Map params)
          Execute the report command.
 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)
          Validate if the command complies with the command syntax.The command is already pre-parsed to a list of parameter names and a map of [name, value] pairs.
 
Methods inherited from class com.tplan.robot.scripting.commands.AbstractCommandHandler
addCommandListener, checkDependencies, checkPauseAndStop, compileParameters, createConfigureAction, executeFallBackCodeOrProcedure, fireCommandEvent, getBooleanSafely, getCode, getDate, getDescription, getDisplayName, getImplementedInterface, getIntegerSafely, getLowestSupportedVersion, getMessageAfterInstall, getMessageBeforeInstall, getStablePopupMenuItems, getSupportContact, getUniqueId, 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.scripting.commands.CommandHandler
addCommandListener, getStablePopupMenuItems, isGlobalPrerequisity, removeCommandListener
 

Field Detail

PARAM_DESC

public static final String PARAM_DESC
See Also:
Constant Field Values

PARAM_SCOPE

public static final String PARAM_SCOPE
See Also:
Constant Field Values

PARAM_ZIP

public static final String PARAM_ZIP
See Also:
Constant Field Values

PARAM_FILENAME

public static final String PARAM_FILENAME
See Also:
Constant Field Values

PARAM_PROVIDER

public static final String PARAM_PROVIDER
See Also:
Constant Field Values

SCOPE_FILE

public static final String SCOPE_FILE
See Also:
Constant Field Values

SCOPE_COMBINED

public static final String SCOPE_COMBINED
See Also:
Constant Field Values

SCOPE_ALL

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

ReportCommand

public ReportCommand()
Method Detail

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.

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..

getContextArgument

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

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

validate

public void validate(List args,
                     Map values,
                     Map variableContainer,
                     ScriptingContext ctx)
              throws SyntaxErrorException
Description copied from interface: CommandHandler
Validate if the command complies with the command syntax.The command is already pre-parsed to a list of parameter names and a map of [name, value] pairs.

Specified by:
validate in interface CommandHandler
Parameters:
args - a list of parameters.
values - a map of [param, value] pairs resulted from parsing of the command.
variableContainer - output map for values.
ctx - execution context.
Throws:
SyntaxErrorException - when the command doesn't meet the required syntax.

getCommandNames

public String[] getCommandNames()
Description copied from interface: CommandHandler

Get command names. A command name is the first word in a script line, e.g. "Type" or "Press". Though most commands have just one name, you may use this method to define any number of command aliases. You may even use one class to implement more commands if you want. In such a case you need to define more command names and implement a different behavior for each command.

Please note that command name parsing is NOT case sensitive. You don't have to define the names as e.g. { "MyCommand", "mycommand" }. Script parser will always parse the command name in a script and convert it to upper case using the String.toUpperCase(). Such a command name will be then used to look for a command implementation in the command table.

Specified by:
getCommandNames in interface CommandHandler
Returns:
array of command names.

execute

public int execute(List args,
                   Map values,
                   ScriptingContext ctx)
            throws SyntaxErrorException
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.

handleReportEvent

protected int handleReportEvent(ScriptingContext ctx,
                                Map params)
Execute the report command. Please refer to the ReportProvider documentation as most functionality is implemented there.

Parameters:
ctx - repository with the execution context.
params - command parameters which were parsed from the command text.
Returns:
exit code - 0 on success or error code otherwise.

canRunWithoutConnection

public boolean canRunWithoutConnection()
This method should return true if it can be executed even when the tool is not connected to a desktop.

Specified by:
canRunWithoutConnection in interface CommandHandler
Overrides:
canRunWithoutConnection in class AbstractCommandHandler
Returns:
this implementation always returns false.

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.

getFormatToProviderMap

public static Map<String,List<ReportProvider>> getFormatToProviderMap()

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.

getReportFileChooser

public static JFileChooser getReportFileChooser(String file,
                                                ScriptingContext context,
                                                File folder)

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.

configurationChanged

public void configurationChanged(ConfigurationChangeEvent evt)
Description copied from interface: ConfigurationChangeListener
This method gets called when a configuration parameter is changed.

Specified by:
configurationChanged in interface ConfigurationChangeListener
Parameters:
evt - A ConfigurationChangeEvent object describing the event source and the parameter that has changed.

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