Interface IHandlerService
- All Superinterfaces:
IDisposable
,IServiceWithSources
Provides services related to activating and deactivating handlers within the workbench.
This service can be acquired from your service locator:
IHandlerService service = (IHandlerService) getSite().getService(IHandlerService.class);
- This service is available globally.
- Since:
- 3.1
- Restriction:
- This interface is not intended to be implemented by clients.
- Restriction:
- This interface is not intended to be extended by clients.
-
Method Summary
Modifier and TypeMethodDescriptionactivateHandler
(String commandId, IHandler handler) Activates the given handler within the context of this service.activateHandler
(String commandId, IHandler handler, Expression expression) Activates the given handler within the context of this service.activateHandler
(String commandId, IHandler handler, Expression expression, boolean global) Activates the given handler within the context of this service.activateHandler
(String commandId, IHandler handler, Expression expression, int sourcePriorities) Deprecated.activateHandler
(IHandlerActivation activation) Activates the given handler from a child service.createContextSnapshot
(boolean includeSelection) This method creates a copy of the application context returned bygetCurrentState()
.createExecutionEvent
(Command command, Event event) Creates an execution event based on an SWT event.createExecutionEvent
(ParameterizedCommand command, Event event) Creates a parameterized execution event based on an SWT event and a parameterized command.void
deactivateHandler
(IHandlerActivation activation) Deactivates the given handler within the context of this service.void
deactivateHandlers
(Collection activations) Deactivates the given handlers within the context of this service.executeCommand
(String commandId, Event event) Executes the command with the given identifier and no parameters.executeCommand
(ParameterizedCommand command, Event event) Executes the given parameterized command.executeCommandInContext
(ParameterizedCommand command, Event event, IEvaluationContext context) Executes the given parameterized command in the provided context.Returns an evaluation context representing the current state of the world.void
Reads the handler information from the registry.void
setHelpContextId
(IHandler handler, String helpContextId) Sets the help context identifier to associate with a particular handler.Methods inherited from interface org.eclipse.ui.services.IDisposable
dispose
Methods inherited from interface org.eclipse.ui.services.IServiceWithSources
addSourceProvider, removeSourceProvider
-
Method Details
-
activateHandler
Activates the given handler from a child service. This is used by slave and nested services to promote handler activations up to the root. By using this method, it is possible for handlers coming from a more nested component to override the nested component.
- Parameters:
activation
- The activation that is local to the child service; must not benull
.- Returns:
- A token which can be used to later cancel the activation. Only someone with access to this token can cancel the activation. The activation will automatically be cancelled if the service locator context from which this service was retrieved is destroyed. This activation is local to this service (i.e., it is not the activation that is passed as a parameter).
- Since:
- 3.2
-
activateHandler
Activates the given handler within the context of this service. If this service was retrieved from the workbench, then this handler will be active globally. If the service was retrieved from a nested component, then the handler will only be active within that component.
Also, it is guaranteed that the handlers submitted through a particular service will be cleaned up when that services is destroyed. So, for example, a service retrieved from a
IWorkbenchPartSite
would deactivate all of its handlers when the site is destroyed.- Parameters:
commandId
- The identifier for the command which this handler handles; must not benull
.handler
- The handler to activate; must not benull
.- Returns:
- A token which can be used to later cancel the activation. Only someone with access to this token can cancel the activation. The activation will automatically be cancelled if the context from which this service was retrieved is destroyed.
-
activateHandler
Activates the given handler within the context of this service. The handler becomes active when
expression
evaluates totrue
. This is the same as callingactivateHandler(String, IHandler, Expression, boolean)
with global==false.Also, it is guaranteed that the handlers submitted through a particular service will be cleaned up when that service is destroyed. So, for example, a service retrieved from a
IWorkbenchPartSite
would deactivate all of its handlers when the site is destroyed.- Parameters:
commandId
- The identifier for the command which this handler handles; must not benull
.handler
- The handler to activate; must not benull
.expression
- This expression must evaluate totrue
before this handler will really become active. The expression may benull
if the handler should always be active.- Returns:
- A token which can be used to later cancel the activation. Only someone with access to this token can cancel the activation. The activation will automatically be cancelled if the context from which this service was retrieved is destroyed.
- Since:
- 3.2
- See Also:
-
activateHandler
IHandlerActivation activateHandler(String commandId, IHandler handler, Expression expression, boolean global) Activates the given handler within the context of this service. The handler becomes active when
expression
evaluates totrue
. if global==false
, then this handler service must also be the active service to active the handler. For example, the handler service on a part is active when that part is active.Also, it is guaranteed that the handlers submitted through a particular service will be cleaned up when that services is destroyed. So, for example, a service retrieved from a
IWorkbenchPartSite
would deactivate all of its handlers when the site is destroyed.- Parameters:
commandId
- The identifier for the command which this handler handles; must not benull
.handler
- The handler to activate; must not benull
.expression
- This expression must evaluate totrue
before this handler will really become active. The expression may benull
if the handler should always be active.global
- Indicates that the handler should be activated irrespectively of whether the corresponding workbench component (e.g., window, part, etc.) is active.- Returns:
- A token which can be used to later cancel the activation. Only someone with access to this token can cancel the activation. The activation will automatically be cancelled if the context from which this service was retrieved is destroyed.
- Since:
- 3.2
- See Also:
-
activateHandler
@Deprecated IHandlerActivation activateHandler(String commandId, IHandler handler, Expression expression, int sourcePriorities) Deprecated.UseactivateHandler(String, IHandler, Expression)
instead.Activates the given handler within the context of this service. The handler becomes active when
expression
evaluates totrue
.Also, it is guaranteed that the handlers submitted through a particular service will be cleaned up when that services is destroyed. So, for example, a service retrieved from a
IWorkbenchPartSite
would deactivate all of its handlers when the site is destroyed.- Parameters:
commandId
- The identifier for the command which this handler handles; must not benull
.handler
- The handler to activate; must not benull
.expression
- This expression must evaluate totrue
before this handler will really become active. The expression may benull
if the handler should always be active.sourcePriorities
- The source priorities for the expression.- Returns:
- A token which can be used to later cancel the activation. Only someone with access to this token can cancel the activation. The activation will automatically be cancelled if the context from which this service was retrieved is destroyed.
- See Also:
-
createExecutionEvent
Creates an execution event based on an SWT event. This execution event can then be passed to a command for execution.- Parameters:
command
- The command for which an execution event should be created; must not benull
.event
- The SWT event triggering the command execution; may benull
.- Returns:
- An execution event suitable for calling
Command.executeWithChecks(ExecutionEvent)
. - Since:
- 3.2
- See Also:
-
createExecutionEvent
Creates a parameterized execution event based on an SWT event and a parameterized command. This execution event can then be passed to a command for execution.- Parameters:
command
- The parameterized command for which an execution event should be created; must not benull
.event
- The SWT event triggering the command execution; may benull
.- Returns:
- An execution event suitable for calling
Command.executeWithChecks(ExecutionEvent)
. - Since:
- 3.2
- See Also:
-
deactivateHandler
Deactivates the given handler within the context of this service. If the handler was activated with a different service, then it must be deactivated from that service instead. It is only possible to retract a handler activation with this method. That is, you must have the sameIHandlerActivation
used to activate the handler.- Parameters:
activation
- The token that was returned from a call toactivateHandler
; must not benull
.
-
deactivateHandlers
Deactivates the given handlers within the context of this service. If the handler was activated with a different service, then it must be deactivated from that service instead. It is only possible to retract a handler activation with this method. That is, you must have the sameIHandlerActivation
used to activate the handler.- Parameters:
activations
- The tokens that were returned from a call toactivateHandler
. This collection must only contain instances ofIHandlerActivation
. The collection must not benull
.
-
executeCommand
Object executeCommand(String commandId, Event event) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException Executes the command with the given identifier and no parameters.- Parameters:
commandId
- The identifier of the command to execute; must not benull
.event
- The SWT event triggering the command execution; may benull
.- Returns:
- The return value from 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
- See Also:
-
executeCommand
Object executeCommand(ParameterizedCommand command, Event event) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException Executes the given parameterized command.- Parameters:
command
- The parameterized command to be executed; must not benull
.event
- The SWT event triggering the command execution; may benull
.- Returns:
- The return value from 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
- See Also:
-
executeCommandInContext
Object executeCommandInContext(ParameterizedCommand command, Event event, IEvaluationContext context) throws ExecutionException, NotDefinedException, NotEnabledException, NotHandledException Executes the given parameterized command in the provided context. It takes care of finding the correct active handler given the context, callsIHandler2.setEnabled(Object)
to update the enabled state if supported, and executes with that handler.- Parameters:
command
- The parameterized command to be executed; must not benull
.event
- The SWT event triggering the command execution; may benull
.context
- the evaluation context to run against. Must not benull
- Returns:
- The return value from 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.4
- See Also:
-
createContextSnapshot
This method creates a copy of the application context returned bygetCurrentState()
.- Parameters:
includeSelection
- iftrue
, include the default variable and selection variables- Returns:
- an context filled with the current set of variables. If selection is not included, the default variable is an empty collection
- Since:
- 3.4
-
getCurrentState
IEvaluationContext getCurrentState()Returns an evaluation context representing the current state of the world. This is equivalent to the application context required byExecutionEvent
.- Returns:
- the current state of the application; never
null
. - See Also:
-
readRegistry
void readRegistry()Reads the handler information from the registry. This will overwrite any of the existing information in the handler service. This method is intended to be called during start-up. When this method completes, this handler service will reflect the current state of the registry.
-
setHelpContextId
Sets the help context identifier to associate with a particular handler.- Parameters:
handler
- The handler with which to register a help context identifier; must not benull
.helpContextId
- The help context identifier to register; may benull
if the help context identifier should be removed.- Since:
- 3.2
-
activateHandler(String, IHandler, Expression)
instead.