Differences
This shows you the differences between two versions of the page.
parameterized_command [2014/06/23 11:21] |
parameterized_command [2021/04/05 11:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Parameterized Commands ====== | ||
+ | Most of the time commands are called from the framework and not directly. But sometimes it is necessary to call a command by hand. The Eclipse framework offers ready to use services for this, HandlerService and CommandService. Both can be injected with e4 dependency injection. | ||
+ | |||
+ | <sxh java> | ||
+ | @Inject EHandlerService handlerService; | ||
+ | @Inject ECommandService commandService; | ||
+ | </ | ||
+ | |||
+ | The command can be called by its specified id. | ||
+ | |||
+ | <sxh java> | ||
+ | Command command = commandService.getCommand(commandId); | ||
+ | |||
+ | if (command.isDefined()) { | ||
+ | |||
+ | // Activate Handler | ||
+ | handlerService.activateHandler(OpenConnectionHandler.ID, | ||
+ | |||
+ | ParameterizedCommand cmd = commandService.createCommand(command, | ||
+ | |||
+ | // Check if the command can get executed | ||
+ | if (handlerService.canExecute(cmd)) { | ||
+ | // Execute the command | ||
+ | handlerService.executeHandler(cmd); | ||
+ | } | ||
+ | else { | ||
+ | logger.log(LogService.LOG_ERROR, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | From time to time a parameter needs to be passed to the handler. There are at least three positions which need to be adjusted. | ||
+ | |||
+ | * Application Model - Command Definition | ||
+ | * ParameterizedCommand Call | ||
+ | * Handler | ||
+ | |||
+ | Parameters are passed within a Map which takes String for keys and values, '' | ||
+ | |||
+ | <sxh java> | ||
+ | Map< | ||
+ | parameters.put(" | ||
+ | ParameterizedCommand cmd = commandService.createCommand(commandId, | ||
+ | </ | ||
+ | |||
+ | With the Eclipse 3.x framework the handlers needed to implement '' | ||
+ | |||
+ | But with the e4 framework there is no event. The parameters must be declared in the commands in the Application Model and in the handler '' | ||
+ | |||
+ | Parameters can be declared as '' | ||
+ | |||
+ | <sxh java> | ||
+ | @Execute | ||
+ | public void execute(@Optional @Named(" | ||
+ | if (connection != null) { | ||
+ | ... | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | |||
+ | <note tip> | ||
+ | |||
+ | {{tag> |