public static void executeCommand(IViewSite site, String command) { ICommandService cmdService = (ICommandService) site.getService(ICommandService.class); IHandlerService hdlService = (IHandlerService) site.getService(IHandlerService.class); Command cmd = cmdService.getCommand(command); try { hdlService.executeCommand(cmd.getId(), null); } catch (ExecutionException e) { e.printStackTrace(); } catch (NotDefinedException e) { e.printStackTrace(); } catch (NotEnabledException e) { e.printStackTrace(); } catch (NotHandledException e) { e.printStackTrace(); } }
protected void setItemText(MMenuItem model, MenuItem item) { String text = model.getLocalizedLabel(); if (model instanceof MHandledItem) { MHandledItem handledItem = (MHandledItem) model; IEclipseContext context = getContext(model); EBindingService bs = (EBindingService) context.get(EBindingService.class.getName()); ParameterizedCommand cmd = handledItem.getWbCommand(); if (cmd != null && (text == null || text.length() == 0)) { try { text = cmd.getName(); } catch (NotDefinedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } TriggerSequence sequence = bs.getBestSequenceFor(handledItem.getWbCommand()); if (sequence != null) { text = text + '\t' + sequence.format(); } item.setText(text == null ? handledItem.getCommand().getElementId() : text); } else { super.setItemText(model, item); } }