在Eclipse中,您可以使用菜单贡献来添加工具栏按钮和将调用命令的菜单。除了以编程方式调用命令onclick之外,还有什么方法可以对普通swt按钮执行此操作?
最佳答案
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");
}
}
});