我在Part的工具栏中添加了一个工具栏处理项。零件堆栈的一部分包含类DataBaseConnectPart
。当我注入commandService
和IHandlerService
时。零件工具栏中的按钮消失。我完全混淆了如何在选择树项时触发命令。
public class DatabaseExplorerPart {
@Inject
private IEventBroker eventBroker;
@Inject
private EPartService partService;
@Inject private ICommandService commandService;
@Inject private IHandlerService service;
@Inject private IEvaluationService evaluationService;
@PostConstruct
public void createControls(Composite parent, EMenuService menuService, EclipseContext context ) {
createImages();
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent arg0) {
TreeSelection ts = (TreeSelection)arg0.getSelection();
Object o = ts.getFirstElement();
if (o instanceof Query){
context.set(Constants.KEY_SELECTED_OBJECT_TYPE, "query");
context.set(Constants.KEY_SELECTED_OBJECT, o);
String name = ((Query)o).getName();
if(name.equalsIgnoreCase("New Query")){
executeCommand();
}
}
}
}
});
viewer.setLabelProvider(new ViewLabelProvider());
}
private void executeCommand(){
try {
Command theCommand = commandService.getCommand("com.db.connect.command");
theCommand.executeWithChecks(new ExecutionEvent(theCommand, new HashMap(), null, evaluationService.getCurrentState()));
} catch (Exception exception) {
logger.error(exception.getMessage(), exception);
}
}