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)); } }
private IEclipseContext getStaticContext(Event event) { if (infoContext == null) { infoContext = EclipseContextFactory.create(HCI_STATIC_CONTEXT); ContributionsAnalyzer.populateModelInterfaces(getModel(), infoContext, getModel().getClass().getInterfaces()); } if (event == null) { infoContext.remove(Event.class); } else { infoContext.set(Event.class, event); } return infoContext; }
@Override public void setModel(MItem item) { if (!(item instanceof MHandledItem)) { throw new IllegalArgumentException("Only instances of MHandledItem are allowed"); //$NON-NLS-1$ } super.setModel(item); generateCommand(); if (getModel().getCommand() == null) { if (logger != null) { logger.error("Element " + getModel().getElementId() + " invalid, no command defined."); //$NON-NLS-1$ //$NON-NLS-2$ } } }
@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 @SuppressWarnings("restriction") protected void handleHelpRequest() { if(helpService==null) return; String helpContextId = getModel().getPersistedState().get(EHelpService.HELP_CONTEXT_ID); if (helpContextId != null) { helpService.displayHelp(helpContextId); return; } MCommand command = getModel().getCommand(); if (command == null || commandHelpService == null) { return; } String contextHelpId = commandHelpService.getHelpContextId(command.getElementId(), getContext(getModel())); if (contextHelpId != null) { helpService.displayHelp(contextHelpId); } }
private void hookCheckListener() { if (getModel().getType() != ItemType.CHECK) { return; } Object obj = getModel().getTransientData().get(ItemType.CHECK.toString()); if (obj instanceof IContextFunction) { IEclipseContext context = getContext(getModel()); IEclipseContext staticContext = getStaticContext(null); staticContext.set(MPart.class, context.get(MPart.class)); staticContext.set(WW_SUPPORT, context.get(WW_SUPPORT)); IContextFunction func = (IContextFunction) obj; obj = func.compute(staticContext, null); if (obj != null) { getModel().getTransientData().put(DISPOSABLE, obj); } } }
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 protected void updateToolItem() { ToolItem item = (ToolItem) widget; if (item.getImage() == null || getModel().getTags().contains(FORCE_TEXT)) { final String text = getModel().getLocalizedLabel(); if (text == null || text.length() == 0) { final MCommand command = getModel().getCommand(); if (command == null) { // Set some text so that the item stays visible in the menu item.setText("UnLabled"); //$NON-NLS-1$ } else { item.setText(command.getLocalizedCommandName()); } } else { item.setText(text); } } else { item.setText(""); //$NON-NLS-1$ } final String tooltip = getToolTipText(true); item.setToolTipText(tooltip); item.setSelection(getModel().isSelected()); item.setEnabled(getModel().isEnabled()); }
@Override protected void updateMenuItem() { MenuItem item = (MenuItem) widget; String text = getModel().getLocalizedLabel(); ParameterizedCommand parmCmd = getModel().getWbCommand(); String keyBindingText = null; if (parmCmd != null) { if (text == null || text.isEmpty()) { try { text = parmCmd.getName(getModel().getCommand().getLocalizedCommandName()); } catch (NotDefinedException e) { Activator.log(LogService.LOG_DEBUG, e.getMessage(), e); if (getModel() instanceof MMenuElement) { String mnemonics = ((MMenuElement) getModel()).getMnemonics(); if (mnemonics != null && !mnemonics.isEmpty()) { int idx = text.indexOf(mnemonics); item.setText(""); //$NON-NLS-1$ final String tooltip = getModel().getLocalizedTooltip(); item.setToolTipText(tooltip); item.setSelection(getModel().isSelected()); item.setEnabled(getModel().isEnabled());
@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); } }
@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$ } } }
if (getModel().getCommand() != null && getModel().getWbCommand() == null) { String cmdId = getModel().getCommand().getElementId(); if (cmdId == null) { logger.error("Unable to generate parameterized command for " + getModel() //$NON-NLS-1$ + ". ElementId is not allowed to be null."); //$NON-NLS-1$ return; List<MParameter> modelParms = getModel().getParameters(); Map<String, Object> parameters = new HashMap<>(4); for (MParameter mParm : modelParms) { "Unable to generate the parameterized " + "command with the id \"" + cmdId + "\" with the " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + parameters + " parameter(s). Model details: " + getModel());//$NON-NLS-1$ return; getModel().setWbCommand(parmCmd);
@Override protected void handleWidgetDispose(Event event) { if (event.widget == widget) { if (unreferenceRunnable != null) { unreferenceRunnable.run(); unreferenceRunnable = null; } unhookCheckListener(); ToolItemUpdater updater = getUpdater(); if (updater != null) { updater.removeItem(this); } if (infoContext != null) { infoContext.dispose(); infoContext = null; } widget.removeListener(SWT.Selection, getItemListener()); widget.removeListener(SWT.Dispose, getItemListener()); widget.removeListener(SWT.DefaultSelection, getItemListener()); widget.removeListener(SWT.Help, getItemListener()); widget = null; getModel().setWidget(null); disposeOldImages(); } }