How to enter a parameter with a parameterized command in Eclipse 4.3?

I am currently implementing an Eclipse 4.3 application and am facing a problem. I am trying to parameterize a command to delete specific files. My approach is consistent with Obtaining a parameterized command parameter in Eclipse RCP 4.2 , but somehow I didn’t work correctly.

In my Application.e4xmi application, I added a command with a parameter:

<commands xmi:id="_K1MVgDGKEeOO8o2ChqdHMA" elementId="first.application.command.deleteproject" commandName="deleteProjectCommand">
<parameters xmi:id="_Hr4FEDGTEeOO8o2ChqdHMA" elementId="cmd0" name="cmd0" typeId="" optional="false"/>
</commands>

At some point in my code, I create a command, set a parameter, and execute it:

Map<String, String> parameters = new HashMap<String, String>();
parameters.put("cmd0", "test");
final Command command =commandService.getCommand("first.application.command.deleteproject");
final ParameterizedCommand pcmd = ParameterizedCommand.generateCommand(command, parameters);
pcmd.executeWithChecks(null, null);

I have a handler associated with a command that has the following execution method:

@Execute
public void execute(@Optional @Named("cmd0") String file) {
  System.out.println("delete project " + file);
}

, file , null. pcmd , , {cmd0=test} ( System.out.println(pcmd.getParameterMap());). @Optional, execute .

- cmd0. ?

!

+4
1

. pcmd.executeWithChecks(null, null); . EHandlerService:

@Inject
private EHandlerService handlerService;

, :

handlerService.executeHandler(pcmd);

Voila!

, -.

+5

All Articles