# Interface EHandlerService

All Known Implementing Classes:
  `HandlerServiceImpl`

public interface EHandlerService
This service enables actions on handlers. A handler is an object which has methods that are annotated with `@CanExecute` (optional) and `@Execute`. A handler is associated with a `Command` which is an abstract notion of a user action like "copy" and "paste".

Many handlers may be associated with a command (e.g. "copy") because each handler typically only handles the command when in a specific context.

An example of different contexts, is the use of the "copy" command in a text editor versus in a table. In every case the command is the same, but the code executed is very different.

You should not implement this interface, an implementation is provided by Eclipse.

It is usually not needed to use this service in your programs because handler activation is done by Eclipse using binding contexts that are evaluated when a part is made active. Execution is done by Eclipse when a user presses a button or uses a context menu. However, in some cases it may be needed to programmatically manipulate handler activation, or execute the handler that is active for a give command.

Example usage:

    @inject  ECommandService cs;
    @inject  EHandlerService hs;

    Command command = cs.getCommand(commandId);
    if (command.isDefined()) {
    Map<String Object> parameters = new HashMap<String, Object>();
    parameters.put("parm1", "hello, world");
    ParameterizedCommand parmCmd = cs.createCommand(commandId, parameters);
    if (hs.canExecute(parmCmd)) {
            hs.executeHandler(parmCmd);
    }
    else {logger.error("Cannot execute command");}
    }
    else {logger.error("Command is not defined");}

Since:
  1.0
See Also:
  - `ECommandService`
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 Type
Method
Description
`void`
`activateHandler(String commandId, Object handler)`
Makes the passed `handler` active for the command with the passed `commandId`.
`boolean`
`canExecute(ParameterizedCommand command)`
Tests if the active handler associated with the passed `command` can be executed.
`boolean`
`canExecute(ParameterizedCommand command, IEclipseContext staticContext)`
Check if a command can be executed.
`void`
`deactivateHandler(String commandId, Object handler)`
Deactivates the passed `handler` from the command with the passed id.
`Object`
`executeHandler(ParameterizedCommand command)`
Executes the active handler of the passed `command`.
`Object`
`executeHandler(ParameterizedCommand command, IEclipseContext staticContext)`
Execute a handler for the command.

## Method Details

### activateHandler

void activateHandler(String commandId, Object handler)
Makes the passed `handler` active for the command with the passed `commandId`.

Parameters:
  `commandId` - Must not be `null`
  `handler` - Must not be `null`

### deactivateHandler

void deactivateHandler(String commandId, Object handler)
Deactivates the passed `handler` from the command with the passed id.

Parameters:
  `commandId` - Must not be `null`
  `handler` - Must not be `null`

### executeHandler

Object executeHandler(ParameterizedCommand command)
Executes the active handler of the passed `command`.

Parameters:
  `command` - Must not be `null`
Returns:
  the return value of the handler, could be null

### canExecute

boolean canExecute(ParameterizedCommand command)
Tests if the active handler associated with the passed `command` can be executed.

Parameters:
  `command` - Must not be `null`
Returns:
  true of the handler can be executed, false if it cannot be executed or if no handler is active for the passed command.

### executeHandler

Object executeHandler(ParameterizedCommand command, IEclipseContext staticContext)
Execute a handler for the command.

Parameters:
  `command` - Must not be `null`
  `staticContext` - Must not be `null`. You must dispose your context when you are done.
Returns:
  the command return value.

### canExecute

boolean canExecute(ParameterizedCommand command, IEclipseContext staticContext)
Check if a command can be executed.

Parameters:
  `command` - Must not be `null`.
  `staticContext` - Must not be `null`. You must dispose your context when you are done.
Returns:
  true if the command can be executed.