Aggavara

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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

解决方法:

 

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

//获取ICommandService

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

//调用Command并传递对象

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

 

二 取值部分

//handler的执行代码

public Object execute(ExecutionEvent event) throws ExecutionException {

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

 

posted on 2013-06-24 15:24  Aggavara  阅读(1780)  评论(0编辑  收藏  举报