Retrieving a Parameterized Command Parameter in Eclipse RCP 4.2

In Eclipse 3.7 we could do this:

public class HelloName extends AbstractHandler {

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        String name = event
                .getParameter("de.vogella.rcp.commands.parameterfirst.commandParameter1");
        MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
                "Hello", "Hello " + name);
        return null;
    }
}

In Eclipse 4.2, I made this handler, and I want the part id for findPart () to be set as a parameter, but where can I get the parameter?

public class FocusHandler {

    @Execute
    public void execute(EPartService partService) {
        MPart part = partService.findPart("nl.rh.parts.inbox");
        partService.activate(part, true);
    }
}
+2
source share
1 answer

I found the answer to my question. The key is to use the @Named annotation with dependency injection.

@Execute
public void execute(EPartService partService, @Optional @Named("nl.rh.focusCommand.part") String partName) {
    MPart part = partService.findPart(partName);
    partService.activate(part, true);
}

The @Named annotation must include the command parameter identifier.

+4
source

All Articles