Getting parameter of parameterized command in Eclipse RCP 4.2

若如初见. 提交于 2020-01-05 02:02:45

问题


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);
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/9852088/getting-parameter-of-parameterized-command-in-eclipse-rcp-4-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!