/** * Parameterized command of the handled contribution item. * * @param item * the item to extract the command from. * @return the command or <code>null</code> if can't be found. */ private ParameterizedCommand getItemParCommand( final HandledContributionItem item) { // the ParameterizedCommand is stored in the field // HandledContributionItem.model.wbCommand final Field modelField = getModelField(item); try { modelField.setAccessible(true); final MHandledItem mItem = (MHandledItem) modelField.get(item); return mItem.getWbCommand(); } catch (final SecurityException e) { throw new RuntimeException(e); } catch (final IllegalArgumentException e) { throw new RuntimeException(e); } catch (final IllegalAccessException e) { throw new RuntimeException(e); } }
private void updateState() { if (styleState != null) { model.setSelected(((Boolean) styleState.getValue()).booleanValue()); } else if (toggleState != null) { model.setSelected(((Boolean) toggleState.getValue()).booleanValue()); } else if (radioState != null && model.getWbCommand() != null) { ParameterizedCommand c = model.getWbCommand(); Object parameter = c.getParameterMap().get( ORG_ECLIPSE_UI_COMMANDS_RADIO_STATE_PARAMETER); String value = (String) radioState.getValue(); model.setSelected(value != null && value.equals(parameter)); } }
private void executeItem(Event trigger) { ParameterizedCommand cmd = model.getWbCommand(); if (cmd == null) { return; } final IEclipseContext lclContext = getContext(model); EHandlerService service = (EHandlerService) lclContext .get(EHandlerService.class.getName()); final IEclipseContext staticContext = getStaticContext(trigger); service.executeHandler(cmd, staticContext); }
@Override protected void postMenuFill() { if (updateService != null) { ParameterizedCommand wbCommand = getModel().getWbCommand(); if (wbCommand != null) { unreferenceRunnable = updateService.registerElementForUpdate(wbCommand, getModel()); } } }
private String getToolTipText() { String text = model.getLocalizedTooltip(); ParameterizedCommand parmCmd = model.getWbCommand(); if (parmCmd == null) { generateCommand(); parmCmd = model.getWbCommand(); } if (parmCmd != null && text == null) { try { text = parmCmd.getName(); } catch (NotDefinedException e) { return null; } } TriggerSequence sequence = bindingService.getBestSequenceFor(parmCmd); if (sequence != null) { text = text + " (" + sequence.format() + ')'; //$NON-NLS-1$ } return text; }
private void updateState() { if (styleState != null) { getModel().setSelected(((Boolean) styleState.getValue()).booleanValue()); } else if (toggleState != null) { getModel().setSelected(((Boolean) toggleState.getValue()).booleanValue()); } else if (radioState != null && getModel().getWbCommand() != null) { ParameterizedCommand c = getModel().getWbCommand(); Object parameter = c.getParameterMap().get(ORG_ECLIPSE_UI_COMMANDS_RADIO_STATE_PARAMETER); String value = (String) radioState.getValue(); getModel().setSelected(value != null && value.equals(parameter)); } }
@Override protected void postToolbarFill() { hookCheckListener(); if (updateService != null) { ParameterizedCommand wbCommand = getModel().getWbCommand(); if (wbCommand != null) { unreferenceRunnable = updateService.registerElementForUpdate(wbCommand, getModel()); } } }
private boolean canExecuteItem(Event trigger) { ParameterizedCommand cmd = model.getWbCommand(); if (cmd == null) { return false; } final IEclipseContext lclContext = getContext(model); EHandlerService service = lclContext.get(EHandlerService.class); if (service == null) { return false; } final IEclipseContext staticContext = getStaticContext(trigger); return service.canExecute(cmd, staticContext); }
public void widgetSelected(SelectionEvent e) { if (e.detail != SWT.ARROW) { EHandlerService service = (EHandlerService) lclContext .get(EHandlerService.class.getName()); ParameterizedCommand cmd = item.getWbCommand(); if (cmd == null) { cmd = generateParameterizedCommand(item, lclContext); } if (cmd == null) { Activator.trace(Policy.DEBUG_MENUS, "Failed to execute: " + item.getCommand(), //$NON-NLS-1$ null); return; } final IEclipseContext staticContext = EclipseContextFactory .create(TIR_STATIC_CONTEXT); ContributionsAnalyzer.populateModelInterfaces(item, staticContext, item.getClass().getInterfaces()); service.executeHandler(cmd, staticContext); } }
public void handleEvent(Event e) { EHandlerService service = (EHandlerService) lclContext .get(EHandlerService.class.getName()); ParameterizedCommand cmd = item.getWbCommand(); if (cmd == null) { return; } final IEclipseContext staticContext = EclipseContextFactory .create(HMI_STATIC_CONTEXT); if (e != null) { staticContext.set(Event.class, e); } ContributionsAnalyzer.populateModelInterfaces(item, staticContext, item.getClass().getInterfaces()); try { service.executeHandler(cmd, staticContext); } finally { staticContext.dispose(); } } });
private String getToolTipText(MItem item) { String text = item.getLocalizedTooltip(); if (item instanceof MHandledItem) { MHandledItem handledItem = (MHandledItem) item; IEclipseContext context = getContext(item); EBindingService bs = (EBindingService) context .get(EBindingService.class.getName()); ParameterizedCommand cmd = handledItem.getWbCommand(); if (cmd == null) { cmd = generateParameterizedCommand(handledItem, context); } TriggerSequence sequence = bs.getBestSequenceFor(handledItem .getWbCommand()); if (sequence != null) { if (text == null) { try { text = cmd.getName(); } catch (NotDefinedException e) { return null; } } text = text + " (" + sequence.format() + ')'; //$NON-NLS-1$ } return text; } return text; }
private String getToolTipText(boolean attachKeybinding) { String text = getModel().getLocalizedTooltip(); ParameterizedCommand parmCmd = getModel().getWbCommand(); if (parmCmd == null) { generateCommand(); parmCmd = getModel().getWbCommand(); } if (parmCmd != null && text == null) { try { text = parmCmd.getName(); } catch (NotDefinedException e) { return null; } } TriggerSequence sequence = bindingService.getBestSequenceFor(parmCmd); if (attachKeybinding && sequence != null) { text = text + " (" + sequence.format() + ')'; //$NON-NLS-1$ } return text; }
@Override public void dispose() { if (widget != null) { if (unreferenceRunnable != null) { unreferenceRunnable.run(); unreferenceRunnable = null; } ParameterizedCommand command = model.getWbCommand(); if (command != null) { if (styleState != null) { styleState.removeListener(stateListener); styleState = null; } if (toggleState != null) { toggleState.removeListener(stateListener); toggleState = null; } if (radioState != null) { radioState.removeListener(stateListener); radioState = null; } } widget.dispose(); widget = null; model.setWidget(null); } }
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); } }
@Override protected boolean canExecuteItem(Event trigger) { ParameterizedCommand cmd = getModel().getWbCommand(); if (cmd == null) { return false; } final IEclipseContext lclContext = getContext(getModel()); EHandlerService service = lclContext.get(EHandlerService.class); if (service == null) { return false; } final IEclipseContext staticContext = getStaticContext(trigger); return service.canExecute(cmd, staticContext); }
@Override public void dispose() { if (widget != null) { if (unreferenceRunnable != null) { unreferenceRunnable.run(); unreferenceRunnable = null; } ParameterizedCommand command = getModel().getWbCommand(); if (command != null) { if (styleState != null) { styleState.removeListener(stateListener); styleState = null; } if (toggleState != null) { toggleState.removeListener(stateListener); toggleState = null; } if (radioState != null) { radioState.removeListener(stateListener); radioState = null; } } widget.dispose(); widget = null; getModel().setWidget(null); } }
private void updateMenuItem() { MenuItem item = (MenuItem) widget; String text = model.getLocalizedLabel(); ParameterizedCommand parmCmd = model.getWbCommand(); String keyBindingText = null; if (parmCmd != null) {
@Override protected void executeItem(Event trigger) { ParameterizedCommand cmd = getModel().getWbCommand(); if (cmd == null) { return; } final IEclipseContext lclContext = getContext(getModel()); EHandlerService service = lclContext.get(EHandlerService.class); final IEclipseContext staticContext = getStaticContext(trigger); service.executeHandler(cmd, staticContext); Object object = staticContext.get(HandlerServiceImpl.HANDLER_EXCEPTION); if (object instanceof ExecutionException) { if (logger != null) { logger.error((Throwable) object, "Command '" + cmd.getId() + "' failed"); //$NON-NLS-1$ //$NON-NLS-2$ } } }
MHandledItem handledItem = (MHandledItem) item; EBindingService bs = context.get(EBindingService.class); ParameterizedCommand cmd = handledItem.getWbCommand(); if (cmd == null) { cmd = generateParameterizedCommand(handledItem, context); TriggerSequence sequence = bs.getBestSequenceFor(handledItem.getWbCommand()); if (sequence != null) { if (text == null) {
model.getWbCommand(), model);