Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting parameter of parameterized command in Eclipse RCP 4.2

Tags:

eclipse-rcp

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 given as a parameter, but where can I get the parameter from?

public class FocusHandler {

    @Execute
    public void execute(EPartService partService) {
        MPart part = partService.findPart("nl.rh.parts.inbox");
        partService.activate(part, true);
    }
}
like image 465
Remy Honig Avatar asked Sep 02 '25 17:09

Remy Honig


1 Answers

I found the answer to my own question. The key is to make use of a @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 be given the id of the command parameter.

like image 180
Remy Honig Avatar answered Sep 07 '25 12:09

Remy Honig