public interface ICommandService extends IDisposable
Provides services related to the command architecture within the workbench. This service can be used to access the set of commands and command categories.
This service can be acquired from your service locator:
ICommandService service = (ICommandService) getSite().getService(ICommandService.class);
Modifier and Type | Field and Description |
---|---|
static String |
AUTOGENERATED_CATEGORY_ID
The identifier of the category in which all auto-generated commands will
appear.
|
Modifier and Type | Method and Description |
---|---|
void |
addExecutionListener(IExecutionListener listener)
Adds an execution listener to the command service.
|
void |
defineUncategorizedCategory(String name,
String description)
Sets the name and description of the category for uncategorized commands.
|
ParameterizedCommand |
deserialize(String serializedParameterizedCommand)
Returns a
ParameterizedCommand with a command and
parameterizations as specified in the provided
serializedParameterizedCommand string. |
Category |
getCategory(String categoryId)
Retrieves the category with the given identifier.
|
Command |
getCommand(String commandId)
Retrieves the command with the given identifier.
|
Category[] |
getDefinedCategories()
Returns the collection of all of the defined categories in the workbench.
|
Collection |
getDefinedCategoryIds()
Returns the collection of the identifiers for all of the defined
categories in the workbench.
|
Collection |
getDefinedCommandIds()
Returns the collection of the identifiers for all of the defined commands
in the workbench.
|
Command[] |
getDefinedCommands()
Returns the collection of all of the defined commands in the workbench.
|
Collection |
getDefinedParameterTypeIds()
Returns the collection of the identifiers for all of the defined command
parameter types in the workbench.
|
ParameterType[] |
getDefinedParameterTypes()
Returns the collection of all of the defined command parameter types in
the workbench.
|
String |
getHelpContextId(Command command)
Gets the help context identifier for a particular command.
|
String |
getHelpContextId(String commandId)
Gets the help context identifier for a particular command.
|
ParameterType |
getParameterType(String parameterTypeId)
Retrieves the command parameter type with the given identifier.
|
void |
readRegistry()
Reads the command information from the registry and the preferences.
|
void |
refreshElements(String commandId,
Map filter)
Refresh any elements registered against the command with the given id.
|
void |
registerElement(IElementReference elementReference)
Re-register a callback element provided by the ICommandService.
|
IElementReference |
registerElementForCommand(ParameterizedCommand command,
UIElement element)
Register that this element accepts callbacks for this parameterized
command.
|
void |
removeExecutionListener(IExecutionListener listener)
Removes an execution listener from the command service.
|
void |
setHelpContextId(IHandler handler,
String helpContextId)
Sets the help context identifier to associate with a particular handler.
|
void |
unregisterElement(IElementReference elementReference)
Unregister an element callback.
|
dispose
static final String AUTOGENERATED_CATEGORY_ID
null
.void addExecutionListener(IExecutionListener listener)
Note: listeners should be removed when no longer necessary. If not, they will be removed when the IServiceLocator used to acquire this service is disposed.
listener
- The listener to add; must not be null
.removeExecutionListener(IExecutionListener)
void defineUncategorizedCategory(String name, String description)
getCategory(String)
is called with null
.name
- The name of the category for uncategorized commands; must not
be null
.description
- The description of the category for uncategorized commands;
may be null
.ParameterizedCommand deserialize(String serializedParameterizedCommand) throws NotDefinedException, SerializationException
Returns a ParameterizedCommand
with a command and
parameterizations as specified in the provided
serializedParameterizedCommand
string. The
serializedParameterizedCommand
must use the format
returned by ParameterizedCommand.serialize()
and described in the
Javadoc for that method.
If a parameter id encoded in the
serializedParameterizedCommand
does not exist in the
encoded command, that parameter id and value are ignored. A given
parameter id should not be used more than once in
serializedParameterizedCommand
. This will not result in
an exception, but the value of the parameter when the command is executed
cannot be specified here.
This method will never return null
, however it may throw
an exception if there is a problem processing the serialization string or
the encoded command is undefined.
serializedParameterizedCommand
- a String
representing a command id and
parameter ids and valuesParameterizedCommand
with the command and
parameterizations encoded in the
serializedParameterizedCommand
NotDefinedException
- if the command indicated in
serializedParameterizedCommand
is not definedSerializationException
- if there is an error deserializing
serializedParameterizedCommand
NotDefinedException
ParameterizedCommand.serialize()
,
CommandManager.deserialize(String)
Category getCategory(String categoryId)
categoryId
- The identifier to find. If the category is null
,
then a category suitable for uncategorized items is defined
and returned.Command getCommand(String commandId)
commandId
- The identifier to find; must not be null
.Category[] getDefinedCategories()
Category
) that are
defined; never null
, but may be empty.Collection getDefinedCategoryIds()
String
)
that are defined; never null
, but may be empty.Collection getDefinedCommandIds()
String
)
that are defined; never null
, but may be empty.Command[] getDefinedCommands()
Command
) that are
defined; never null
, but may be empty.Collection getDefinedParameterTypeIds()
String
)
that are defined; never null
, but may be empty.ParameterType[] getDefinedParameterTypes()
ParameterType
)
that are defined; never null
, but may be empty.String getHelpContextId(Command command) throws NotDefinedException
null
is returned.command
- The command for which the help context should be retrieved;
must not be null
.null
.NotDefinedException
- If the given command is not defined.NotDefinedException
String getHelpContextId(String commandId) throws NotDefinedException
null
is returned.commandId
- The identifier of the command for which the help context
should be retrieved; must not be null
.null
.NotDefinedException
- If the command with the given identifier is not defined.NotDefinedException
ParameterType getParameterType(String parameterTypeId)
parameterTypeId
- The identifier to find; must not be null
.void readRegistry()
Reads the command information from the registry and the preferences. This will overwrite any of the existing information in the command service. This method is intended to be called during start-up. When this method completes, this command service will reflect the current state of the registry and preference store.
void removeExecutionListener(IExecutionListener listener)
listener
- The listener to remove; must not be null
.void setHelpContextId(IHandler handler, String helpContextId)
handler
- The handler with which to register a help context identifier;
must not be null
.helpContextId
- The help context identifier to register; may be
null
if the help context identifier should be
removed.IElementReference registerElementForCommand(ParameterizedCommand command, UIElement element) throws NotDefinedException
Note: elements should be removed when no longer necessary. If not, they will be removed when the IServiceLocator used to acquire this service is disposed.
command
- The parameterized command that is already specialized. Must
not be null
.element
- The callback to register for this specialized command
instance. Must not be null
.NotDefinedException
- If the command included in the ParameterizedCommand is not
defined, or the element is null
.NotDefinedException
unregisterElement(IElementReference)
void registerElement(IElementReference elementReference)
unregisterElement(IElementReference)
.
Note: elements should be removed when no longer necessary. If not, they will be removed when the IServiceLocator used to acquire this service is disposed.
elementReference
- The reference to re-register. Must not be null
.unregisterElement(IElementReference)
void unregisterElement(IElementReference elementReference)
elementReference
- The callback reference that was provided by the command
service on registration. Must not be null
.void refreshElements(String commandId, Map filter)
The service locator used in registering the element can also be used to scope the search. For example: if you wanted all elements for your command but only within the part's workbench window, you could use:
Map filter = new HashMap(); filter.put(IServiceScopes.WINDOW_SCOPE, getSite().getPage() .getWorkbenchWindow()); commandService.refreshElements(commandId, filter);
commandId
- The command id to refresh if it has registered eleemnts.filter
- key-value pairs that can narrow down the callbacks to return.
The parameters are ANDed together. This may be
null
.
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.