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

相關文章
相關標籤/搜索