在Eclipse 3.7中,我们可以这样做:
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;
}
}
在Eclipse 4.2中,我创建了这个处理程序,我希望findPart()的part id作为参数给出,但是从哪里可以得到参数?
public class FocusHandler {
@Execute
public void execute(EPartService partService) {
MPart part = partService.findPart("nl.rh.parts.inbox");
partService.activate(part, true);
}
}
答案 0 :(得分:4)
我找到了自己问题的答案。关键是要使用带有依赖注入的@Named注释。
@Execute
public void execute(EPartService partService, @Optional @Named("nl.rh.focusCommand.part") String partName) {
MPart part = partService.findPart(partName);
partService.activate(part, true);
}
必须为@Named注释指定命令参数的id。