/** * 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 ParameterizedCommand generateParameterizedCommand( final MHandledItem item, final IEclipseContext lclContext) { ECommandService cmdService = (ECommandService) lclContext .get(ECommandService.class.getName()); Map<String, Object> parameters = null; List<MParameter> modelParms = item.getParameters(); if (modelParms != null && !modelParms.isEmpty()) { parameters = new HashMap<String, Object>(); for (MParameter mParm : modelParms) { parameters.put(mParm.getName(), mParm.getValue()); } } ParameterizedCommand cmd = cmdService.createCommand(item.getCommand() .getElementId(), parameters); item.setWbCommand(cmd); return cmd; }
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 unhookCheckListener() { if (model.getType() != ItemType.CHECK) { return; } final Object obj = model.getTransientData().remove(DISPOSABLE_CHECK); if (obj == null) { return; } ((Runnable) obj).run(); }
public void setModel(MHandledItem item) { model = item; setId(model.getElementId()); generateCommand(); if (model.getCommand() == null) { if (logger != null) { logger.error("Element " + model.getElementId() + " invalid, no command defined."); //$NON-NLS-1$ //$NON-NLS-2$ } } updateVisible(); }
if (model.getCommand() != null && model.getWbCommand() == null) { String cmdId = model.getCommand().getElementId(); List<MParameter> modelParms = model.getParameters(); Map<String, String> parameters = new HashMap<String, String>(4); for (MParameter mParm : modelParms) { model.setWbCommand(parmCmd);
@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); item.setText(""); //$NON-NLS-1$ final String tooltip = getModel().getLocalizedTooltip(); item.setToolTipText(tooltip); item.setSelection(getModel().isSelected()); item.setEnabled(getModel().isEnabled());
private void updateToolItem() { ToolItem item = (ToolItem) widget; final String text = model.getLocalizedLabel(); Image icon = item.getImage(); boolean mode = model.getTags().contains(FORCE_TEXT); if ((icon == null || mode) && text != null) { item.setText(text); } else { item.setText(""); //$NON-NLS-1$ } final String tooltip = getToolTipText(); item.setToolTipText(tooltip); item.setSelection(model.isSelected()); item.setEnabled(model.isEnabled()); }
MHandledItem handledItem = (MHandledItem) item; EHandlerService service = (EHandlerService) context.get(EHandlerService.class.getName()); ParameterizedCommand cmd = handledItem.getWbCommand(); if (cmd == null) { cmd = generateParameterizedCommand(handledItem, context); handledItem.setWbCommand(cmd); getLogger().error("Failed to execute: " + handledItem.getCommand()); //$NON-NLS-1$ return;
private void updateMenuItem() { MenuItem item = (MenuItem) widget; String text = model.getLocalizedLabel(); ParameterizedCommand parmCmd = model.getWbCommand(); String keyBindingText = null; if (parmCmd != null) { item.setText(""); //$NON-NLS-1$ item.setSelection(model.isSelected()); item.setEnabled(model.isEnabled());
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); } }
if (model.getType() == ItemType.PUSH) style = SWT.PUSH; else if (model.getType() == ItemType.CHECK) style = SWT.CHECK; else if (model.getType() == ItemType.RADIO) style = SWT.RADIO; MenuItem item = null; model.setWidget(widget); widget.setData(AbstractPartRenderer.OWNING_ME, model); model.getWbCommand(), model);
ParameterizedCommand cmd = handledItem.getWbCommand(); if (cmd == null) { cmd = generateParameterizedCommand(handledItem, context); handledItem.setWbCommand(cmd);
if (item.getCommand() == null) { getLogger().error("No command assigned to " + item); //$NON-NLS-1$ return null; if (Strings.isNullOrEmpty(item.getCommand().getElementId())) { getLogger().error("No command id assigned to " //$NON-NLS-1$ + item.getCommand().getElementId()); return null; List<MParameter> modelParms = item.getParameters(); if (modelParms != null && !modelParms.isEmpty()) { parameters = new HashMap<String, Object>(); ParameterizedCommand cmd = cmdService.createCommand(item.getCommand().getElementId(), parameters); return cmd;
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; }
@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); } }
private void handleWidgetSelection(Event event) { if (widget != null && !widget.isDisposed()) { if (dropdownEvent(event)) { return; } if (model.getType() == ItemType.CHECK || model.getType() == ItemType.RADIO) { boolean selection = false; if (widget instanceof MenuItem) { selection = ((MenuItem) widget).getSelection(); } else if (widget instanceof ToolItem) { selection = ((ToolItem) widget).getSelection(); } model.setSelected(selection); } if (canExecuteItem(event)) { executeItem(event); } } }
@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); } }
@Override public Object compute(IEclipseContext context, String contextKey) { final MHandledItem model = context.get(MHandledItem.class); if (model == null) { return null; } ActionDescriptor desc = getDescriptor(context); final IAction action = desc.getAction(); final IPropertyChangeListener propListener = event -> { if (IAction.CHECKED.equals(event.getProperty())) { boolean checked = false; if (event.getNewValue() instanceof Boolean) { checked = ((Boolean) event.getNewValue()).booleanValue(); } model.setSelected(checked); } }; action.addPropertyChangeListener(propListener); Runnable obj = () -> action.removePropertyChangeListener(propListener); model.setSelected(action.isChecked()); return obj; } };
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$ return; List<MParameter> modelParms = getModel().getParameters(); Map<String, Object> parameters = new HashMap<>(4); for (MParameter mParm : modelParms) { getModel().setWbCommand(parmCmd);