Eclipse RCP难点:给Command传递参数(Object)

这个问题网络上没有答案,国外网站上也没有,本人研究了一天,终于搞明白如何实现,其实是Eclipse RCP的ICommandService自己就已经提供的方法,只是网络上教的都是使用IHandlerService调用Command,而IHandlerService没有提供传递参数或者对象的功能,因此这个问题让不少人很头疼。网络

解决方法:网站

 

一 传值部分(传递的是ExecutionEvent,经过ExecutionEvent携带的ApplicationContext传递对象,还能够传递别的类型如MAP,具体请参考ExecutionEvent的代码)orm

//获取ICommandService对象

ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getService(ICommandService.class);ip

//调用Command并传递对象get

commandService.getCommand("CommandId").executeWithChecks(new ExecutionEvent(null, Collections.EMPTY_MAP, null, sendObject));it

 

二 取值部分io

//handler的执行代码event

public Object execute(ExecutionEvent event) throws ExecutionException {form

  System.out.println(event.getApplicationContext().toString()+":传值成功");  return null; }

相关文章
相关标签/搜索