|
T-Plan Robot Enterprise 3.2 Build No. 3.2-20121217.1 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.tplan.robot.scripting.commands.AbstractCommandHandler
com.tplan.robot.scripting.commands.impl.AbstractFileResourceCommand
com.tplan.robot.scripting.commands.impl.ExcelCommand
public class ExcelCommand
Handler implementing functionality of the Excel command.
T-Plan Robot Enterprise, (C) 2009-2012 T-Plan Limited. All rights reserved.
| Field Summary | |
|---|---|
static String |
ARG_FIND
|
static String |
ARG_SELECT
|
static String |
ARG_SET
|
static int |
ERR_CELL_NOT_FOUND
|
static int |
ERR_FAILED_TO_CREATE
|
static int |
ERR_MAX_EXCEL
|
static int |
ERR_SHEET_NOT_FOUND
|
static String |
PARAM_COLUMN
|
static String |
PARAM_EVALUATE
|
static String |
PARAM_PATTERN
|
static String |
PARAM_REF
|
static String |
PARAM_ROW
|
static String |
PARAM_SHEET
|
static String |
PARAM_TYPE
|
static String |
PARAM_VALUE
|
static String |
VAR_CELL_COLUMN
|
static String |
VAR_CELL_REF
|
static String |
VAR_CELL_ROW
|
static String |
VAR_CELL_TYPE
|
static String |
VAR_CELL_VALUE
|
static String |
VAR_ERROR
|
static String |
VAR_SHEET_COLUMNS
|
static String |
VAR_SHEET_COUNT
|
static String |
VAR_SHEET_NAME
|
static String |
VAR_SHEET_NUMBER
|
static String |
VAR_SHEET_ROWS
|
| Fields inherited from class com.tplan.robot.scripting.commands.impl.AbstractFileResourceCommand |
|---|
ARG_CLOSE, ARG_CREATE, ARG_OPEN, ARGUMENTS, CONTEXT_FILE_MAP, CONTEXT_FILE_RESOURCE_MAP, contextAttributes, contextShortcut, ERR_FAILED_TO_OPEN, ERR_FAILED_TO_SAVE, ERR_MAX, PARAM_ARGUMENT, PARAM_BEAN, PARAM_FILE, PARAM_ID, PARAM_OUTFILE, PARAM_SAVE, PARAMS, VAR_FILE, VAR_FILENAME, VAR_OUTFILE, VAR_OUTFILENAME |
| Fields inherited from class com.tplan.robot.scripting.commands.AbstractCommandHandler |
|---|
ALT, CONTEXT_COMMAND_CALL_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 |
| Constructor Summary | |
|---|---|
ExcelCommand()
|
|
| Method Summary | |
|---|---|
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. |
protected void |
cleanUpAllVars(ScriptingContext ctx)
Clean up all variables created by the command. |
void |
configurationChanged(ConfigurationChangeEvent evt)
This method gets called when a configuration parameter is changed. |
protected void |
create(AbstractFileBean bean,
OutputStream out)
|
protected AbstractFileBean |
createBean()
Create a file bean. |
static Workbook |
createXLSXWorkbook(InputStream in)
|
protected void |
defineFileVariables(AbstractFileBean bean,
ScriptingContext context)
|
static String |
evaluateFormula(Cell cell)
|
int |
execute(List args,
Map values,
ScriptingContext context)
Execute the command. |
int |
getCategory(StringBuilder description)
Get the category the command falls to. |
static List<String> |
getCellTypes()
|
static String |
getCellValue(Cell c,
boolean evaluateFormula)
|
String[] |
getCommandNames()
Get command names. |
List<Action> |
getContextActions(EditorFriendlyInterpret interpret,
int offset)
Get the list of actions available for the specified offset (command line) and script. |
protected JFileChooser |
getFileChooser(String argument,
ScriptingContext context)
|
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. |
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). |
boolean |
isGlobalPrerequisity(String command)
This method should return true if the command needs to be executed prior to running part of a test script. |
protected void |
load(AbstractFileBean bean,
InputStream in)
|
protected void |
save(AbstractFileBean bean,
OutputStream out)
|
void |
validate(List args,
Map values,
Map vt,
ScriptingContext context)
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.impl.AbstractFileResourceCommand |
|---|
addParamToArgumentArray, addSupportedArgsAndParams, canRunWithoutConnection, cleanUpFileVars, closeFileBean, execute, execute, getArguments, getContextArgument, getContextAttributes, getContextShortcut, getParameters, getScriptPath, getUsedFiles, removeVariables, scriptEvent, updateRelativePath |
| 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.ScriptListener |
|---|
scriptEvent |
| Methods inherited from interface com.tplan.robot.scripting.commands.AdvancedCommandHandler |
|---|
getArguments, getParameters |
| Methods inherited from interface com.tplan.robot.scripting.commands.CommandHandler |
|---|
addCommandListener, canRunWithoutConnection, getContextArgument, getContextAttributes, getContextShortcut, getStablePopupMenuItems, removeCommandListener |
| Field Detail |
|---|
public static final String ARG_SELECT
public static final String ARG_SET
public static final String ARG_FIND
public static final String PARAM_SHEET
public static final String PARAM_ROW
public static final String PARAM_COLUMN
public static final String PARAM_VALUE
public static final String PARAM_REF
public static final String PARAM_PATTERN
public static final String PARAM_TYPE
public static final String PARAM_EVALUATE
public static final String VAR_SHEET_COUNT
public static final String VAR_SHEET_NAME
public static final String VAR_SHEET_NUMBER
public static final String VAR_SHEET_ROWS
public static final String VAR_SHEET_COLUMNS
public static final String VAR_CELL_ROW
public static final String VAR_CELL_COLUMN
public static final String VAR_CELL_TYPE
public static final String VAR_CELL_VALUE
public static final String VAR_CELL_REF
public static final String VAR_ERROR
public static final int ERR_FAILED_TO_CREATE
public static final int ERR_SHEET_NOT_FOUND
public static final int ERR_CELL_NOT_FOUND
public static final int ERR_MAX_EXCEL
| Constructor Detail |
|---|
public ExcelCommand()
| Method Detail |
|---|
public String[] getCommandNames()
CommandHandlerGet 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.
getCommandNames in interface CommandHandlergetCommandNames in class AbstractFileResourceCommandpublic boolean isGlobalPrerequisity(String command)
CommandHandlerThis method should return true if the command needs to be executed prior to running part of a test script.
Imagine a following situation. User creates a script:
Var PATH=/usr/java
Type {PATH}/bin/java
Press Enter
User then selects just the last two commands to be executed. It would of course fail because the PATH variable is not defined. If this method returns true, the command will be executed before running selected commands are executed.
isGlobalPrerequisity in interface CommandHandlerisGlobalPrerequisity in class AbstractFileResourceCommandcommand - a command with parameters to be processed.
public void validate(List args,
Map values,
Map vt,
ScriptingContext context)
throws SyntaxErrorException
CommandHandler
validate in interface CommandHandlervalidate in class AbstractFileResourceCommandargs - a list of parameters.values - a map of [param, value] pairs resulted from parsing of the command.vt - output map for values.context - execution context.
SyntaxErrorException - when the command doesn't meet the required syntax.
public int execute(List args,
Map values,
ScriptingContext context)
throws SyntaxErrorException
CommandHandlerExecute 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.
execute in interface CommandHandlerargs - a list of parameters.values - a map of [param, value] pairs resulted from parsing of the command.context - execution context.
SyntaxErrorException - when the command doesn't meet the required syntax.
protected void defineFileVariables(AbstractFileBean bean,
ScriptingContext context)
defineFileVariables in class AbstractFileResourceCommandpublic static String evaluateFormula(Cell cell)
public static String getCellValue(Cell c,
boolean evaluateFormula)
public static List<String> getCellTypes()
public List<Preference> getPreferences()
Configurable
getPreferences in interface ConfigurablegetPreferences in class AbstractCommandHandler
public List getParameterValues(String paramName,
String command,
ScriptingContext context)
AdvancedCommandHandler
getParameterValues in interface AdvancedCommandHandlergetParameterValues in class AbstractFileResourceCommandparamName - parameter name.command - the current conmmand text (complete).context - a context.
protected AbstractFileBean createBean()
AbstractFileResourceCommand
createBean in class AbstractFileResourceCommandprotected void cleanUpAllVars(ScriptingContext ctx)
AbstractFileResourceCommandremoveVariables()
method to remove any variables it produces from the context.
cleanUpAllVars in class AbstractFileResourceCommandctx - a script context.
protected void save(AbstractFileBean bean,
OutputStream out)
throws FileNotFoundException,
IOException
save in class AbstractFileResourceCommandFileNotFoundException
IOException
protected void create(AbstractFileBean bean,
OutputStream out)
throws FileNotFoundException,
IOException
create in class AbstractFileResourceCommandFileNotFoundException
IOException
protected void load(AbstractFileBean bean,
InputStream in)
throws FileNotFoundException,
IOException
load in class AbstractFileResourceCommandFileNotFoundException
IOException
public static Workbook createXLSXWorkbook(InputStream in)
throws IOException
IOException
protected JFileChooser getFileChooser(String argument,
ScriptingContext context)
getFileChooser in class AbstractFileResourceCommandpublic void configurationChanged(ConfigurationChangeEvent evt)
ConfigurationChangeListener
configurationChanged in interface ConfigurationChangeListenerevt - A ConfigurationChangeEvent object describing the event source
and the parameter that has changed.
public String getShortDescription(Map<String,String> parameters,
TestScriptInterpret interpret)
EditorFriendlyCommandHandler
getShortDescription in interface EditorFriendlyCommandHandlerparameters - 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.
public List<Preference> getVisualParameters(LinkedHashMap<String,Object> parameters,
TestScriptInterpret interpret)
EditorFriendlyCommandHandlerGet 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.
getVisualParameters in interface EditorFriendlyCommandHandlerparameters - input parameters parsed from the already existing command
or preselected through the Command Wizard menu.interpret - test script interpret owning the edited script.
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.public boolean hasFixedArgument(List<String> arguments)
EditorFriendlyCommandHandler
hasFixedArgument in interface EditorFriendlyCommandHandlerarguments - optional output list for the argument values.
public int getCategory(StringBuilder description)
EditorFriendlyCommandHandlerEditorFriendlyCommandHandler.CATEGORY_UNKNOWN or a code outside of the recognized constants
and pass the desired category name through the argument string builder instance.
getCategory in interface EditorFriendlyCommandHandlerdescription - string buffer for category name. It is only used
if the returned value is other than the standard ones.
public void checkVisualParameters(Map<String,CharSequence> parameters,
TestScriptInterpret interpret)
throws IllegalArgumentException
EditorFriendlyCommandHandlerCheck (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.
checkVisualParameters in interface EditorFriendlyCommandHandlerparameters - 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.
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.
public boolean hasCustomParameterComponent(LinkedHashMap<String,Object> parameters,
TestScriptInterpret interpret,
PreferencePanel[] panel)
EditorFriendlyCommandHandlerpanel
array with an instance of the panel.
hasCustomParameterComponent in interface EditorFriendlyCommandHandlerparameters - 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.
public boolean hasCustomPropertyDialog(LinkedHashMap<String,Object> parameters,
TestScriptInterpret interpret,
int offset,
Action[] action)
EditorFriendlyCommandHandlerSpecify 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.
hasCustomPropertyDialog in interface EditorFriendlyCommandHandlerparameters - 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.
public List<Action> getContextActions(EditorFriendlyInterpret interpret,
int offset)
ContextActionProvider
getContextActions in interface ContextActionProviderinterpret - the test script interpret.offset - the offset in the document where the declaring command is situated.
|
T-Plan Robot Enterprise 3.2 Build No. 3.2-20121217.1 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||