Class ParameterizedCommand
- All Implemented Interfaces:
Comparable
A command that has had one or more of its parameters specified. This class serves as a utility class for developers that need to manipulate commands with parameters. It handles the behaviour of generating a parameter map and a human-readable name.
- Since:
- 3.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDeprecated.no longer usedstatic final intDeprecated.no longer usedstatic final intDeprecated.no longer usedstatic final intDeprecated.no longer used -
Constructor Summary
ConstructorsConstructorDescriptionParameterizedCommand(Command command, Parameterization[] parameterizations) Constructs a new instance ofParameterizedCommandwith specific values for zero or more of its parameters. -
Method Summary
Modifier and TypeMethodDescriptionintbooleanDeprecated.Please useexecuteWithChecks(Object, Object)instead.executeWithChecks(Object trigger, Object applicationContext) Executes this command with its parameters.static CollectiongenerateCombinations(Command command) Generates all the possible combinations of command parameterizations for the given command.static ParameterizedCommandgenerateCommand(Command command, Map parameters) Take a command and a map of parameter IDs to values, and generate the appropriate parameterized command.Returns the base command.getId()Returns the command's base identifier.getName()Returns a human-readable representation of this command with all of its parameterizations.Returns a human-readable representation of this command with all of its parameterizations.Returns the parameter map, as can be used to construct anExecutionEvent.inthashCode()Returns aStringcontaining the command id, parameter ids and parameter values for thisParameterizedCommand.toString()
-
Field Details
-
INDEX_PARAMETER_ID
Deprecated.no longer usedThe index of the parameter id in the parameter values.- See Also:
-
INDEX_PARAMETER_NAME
Deprecated.no longer usedThe index of the human-readable name of the parameter itself, in the parameter values.- See Also:
-
INDEX_PARAMETER_VALUE_NAME
Deprecated.no longer usedThe index of the human-readable name of the value of the parameter for this command.- See Also:
-
INDEX_PARAMETER_VALUE_VALUE
Deprecated.no longer usedThe index of the value of the parameter that the command can understand.- See Also:
-
-
Constructor Details
-
ParameterizedCommand
Constructs a new instance ofParameterizedCommandwith specific values for zero or more of its parameters.- Parameters:
command- The command that is parameterized; must not benull.parameterizations- An array of parameterizations binding parameters to values for the command. This value may benull.
-
-
Method Details
-
generateCombinations
Generates all the possible combinations of command parameterizations for the given command. If the command has no parameters, then this is simply a parameterized version of that command. If a parameter is optional, both the included and not included cases are considered.
If one of the parameters cannot be loaded due to a
ParameterValuesException, then it is simply ignored.- Parameters:
command- The command for which the parameter combinations should be generated; must not benull.- Returns:
- A collection of
ParameterizedCommandinstances representing all of the possible combinations. This value is never empty and it is nevernull. - Throws:
NotDefinedException- If the command is not defined.
-
generateCommand
Take a command and a map of parameter IDs to values, and generate the appropriate parameterized command.- Parameters:
command- The command object. Must not benull.parameters- A map of String parameter ids to objects. May benull.- Returns:
- the parameterized command, or
nullif it could not be generated - Since:
- 3.4
-
compareTo
- Specified by:
compareToin interfaceComparable
-
equals
-
execute
@Deprecated public Object execute(Object trigger, Object applicationContext) throws ExecutionException, NotHandledException Deprecated.Please useexecuteWithChecks(Object, Object)instead.Executes this command with its parameters. This method will succeed regardless of whether the command is enabled or defined. It is preferrable to useexecuteWithChecks(Object, Object).- Parameters:
trigger- The object that triggered the execution; may benull.applicationContext- The state of the application at the time the execution was triggered; may benull.- Returns:
- The result of the execution; may be
null. - Throws:
ExecutionException- If the handler has problems executing this command.NotHandledException- If there is no handler.
-
executeWithChecks
public Object executeWithChecks(Object trigger, Object applicationContext) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException Executes this command with its parameters. This does extra checking to see if the command is enabled and defined. If it is not both enabled and defined, then the execution listeners will be notified and an exception thrown.- Parameters:
trigger- The object that triggered the execution; may benull.applicationContext- The state of the application at the time the execution was triggered; may benull.- Returns:
- The result of the execution; may be
null. - Throws:
ExecutionException- If the handler has problems executing this command.NotDefinedException- If the command you are trying to execute is not defined.NotEnabledException- If the command you are trying to execute is not enabled.NotHandledException- If there is no handler.- Since:
- 3.2
-
getCommand
Returns the base command. It is possible for more than one parameterized command to have the same identifier.- Returns:
- The command; never
null, but may be undefined.
-
getId
Returns the command's base identifier. It is possible for more than one parameterized command to have the same identifier.- Returns:
- The command id; never
null.
-
getName
Returns a human-readable representation of this command with all of its parameterizations.- Returns:
- The human-readable representation of this parameterized command;
never
null. - Throws:
NotDefinedException- If the underlying command is not defined.
-
getName
Returns a human-readable representation of this command with all of its parameterizations.- Parameters:
baseName- The base name of the command that should be used to create the parameterized command representation.- Returns:
- The human-readable representation of this parameterized command;
never
null. - Throws:
NotDefinedException- If the underlying command is not defined.- Since:
- 3.8
-
getParameterMap
Returns the parameter map, as can be used to construct anExecutionEvent.- Returns:
- The map of parameter ids (
String) to parameter values (String). This map is nevernull, but may be empty.
-
hashCode
public int hashCode() -
serialize
Returns aStringcontaining the command id, parameter ids and parameter values for thisParameterizedCommand. The returnedStringcan be stored by a client and later used to reconstruct an equivalentParameterizedCommandusing theCommandManager.deserialize(String)method.The syntax of the returned
Stringis as follows:serialization = commandId [ '(' parameters ')' ]
parameters = parameter [ ',' parameters ]
parameter = parameterId [ '=' parameterValue ]In the syntax above, sections inside square-brackets are optional. The characters in single quotes (
(,),,and=) indicate literal characters.commandIdrepresents the command id encoded with separator characters escaped.parameterIdandparameterValuerepresent the parameter ids and values encoded with separator characters escaped. The separator characters(,),,and=are escaped by prepending a%. This requires%to be escaped, which is also done by prepending a%.The order of the parameters is not defined (and not important). A missing
parameterValueindicates that the value of the parameter isnull.For example, the string shown below represents a serialized parameterized command that can be used to show the Resource perspective:
org.eclipse.ui.perspectives.showPerspective(org.eclipse.ui.perspectives.showPerspective.perspectiveId=org.eclipse.ui.resourcePerspective)This example shows the more general form with multiple parameters,
nullvalue parameters, and escaped=in the third parameter value.command.id(param1.id=value1,param2.id,param3.id=esc%=val3)- Returns:
- A string containing the escaped command id, parameter ids and
parameter values; never
null. - Since:
- 3.2
- See Also:
-
toString
-