Interface EHandlerService
- All Known Implementing Classes:
HandlerServiceImpl
@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:
- 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 TypeMethodDescriptionvoidactivateHandler(String commandId, Object handler) Makes the passedhandleractive for the command with the passedcommandId.booleancanExecute(ParameterizedCommand command) Tests if the active handler associated with the passedcommandcan be executed.booleancanExecute(ParameterizedCommand command, IEclipseContext staticContext) Check if a command can be executed.voiddeactivateHandler(String commandId, Object handler) Deactivates the passedhandlerfrom the command with the passed id.executeHandler(ParameterizedCommand command) Executes the active handler of the passedcommand.executeHandler(ParameterizedCommand command, IEclipseContext staticContext) Execute a handler for the command.
-
Method Details
-
activateHandler
Makes the passedhandleractive for the command with the passedcommandId.- Parameters:
commandId- Must not benullhandler- Must not benull
-
deactivateHandler
Deactivates the passedhandlerfrom the command with the passed id.- Parameters:
commandId- Must not benullhandler- Must not benull
-
executeHandler
Executes the active handler of the passedcommand.- Parameters:
command- Must not benull- Returns:
- the return value of the handler, could be null
-
canExecute
Tests if the active handler associated with the passedcommandcan be executed.- Parameters:
command- Must not benull- 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
Execute a handler for the command.- Parameters:
command- Must not benullstaticContext- Must not benull. You must dispose your context when you are done.- Returns:
- the command return value.
-
canExecute
Check if a command can be executed.- Parameters:
command- Must not benull.staticContext- Must not benull. You must dispose your context when you are done.- Returns:
- true if the command can be executed.
-