2011-01-19 98 views

回答

5
button.addSelectionListener(new SelectionAdapter() { 

    @Override 
    public void widgetSelected(SelectionEvent e) { 
     IHandlerService handlerService = (IHandlerService) getSite() 
       .getService(IHandlerService.class); 
     try { 
      handlerService.executeCommand("my command id", null); 
     } catch (Exception ex) { 
      throw new RuntimeException("command with id \"my command id\" not found"); 
     } 

    } 
}); 
+0

其他方式來獲得處理服務。 IHandlerService handlerService =(IHandlerService)PlatformUI.getWorkbench()。getService(IHandlerService.class); – 2017-06-08 07:33:45

2

不需要。您必須偵聽按鈕事件並以編程方式調用該命令。

0

您可以在視圖或嚮導一樣,使用CommandContributionItems:

CommandContributionItemParameter param = new CommandContributionItemParameter(getSite(), 
      "myCommand", "com.voo.myCommand", CommandContributionItem.STYLE_PUSH); 
param.label = "My Label"; 
CommandContributionItem item = new CommandContributionItem(param); 
item.fill(parent);