In Eclipse you can use menu contributions to add toolbar buttons and menus that will call a command. Is there any way to do this to normal swt buttons, apart from programmatically calling the command onclick?
Asked
Active
Viewed 1,875 times
3 Answers
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");
}
}
});

Alex_M
- 1,824
- 1
- 14
- 26
-
Other way to get the handle service. IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); – Kondal Kolipaka Jun 08 '17 at 07:33
2
No. You have to listen for the button event and the invoke the command programmatically.

Konstantin Komissarchik
- 28,879
- 6
- 61
- 61
0
You can use CommandContributionItems in a View or Wizard like that:
CommandContributionItemParameter param = new CommandContributionItemParameter(getSite(),
"myCommand", "com.voo.myCommand", CommandContributionItem.STYLE_PUSH);
param.label = "My Label";
CommandContributionItem item = new CommandContributionItem(param);
item.fill(parent);

Calon
- 4,174
- 1
- 19
- 30