@Override public String getDescription() { try { return command.getCommand().getDescription(); } catch (final NotDefinedException e) { return null; } }
@Override public boolean isHandled() { final Command baseCommand = command.getCommand(); return baseCommand.isHandled(); }
/** * Performs the actual retrieval. * * @param item * the handled contribution item to retrieve command from. * @return the command stored in the handled contribution item. Can be * <code>null</code> if the command can't be found. */ public Command get(final HandledContributionItem item) { final ParameterizedCommand parCommand = getItemParCommand(item); return parCommand == null ? null : parCommand.getCommand(); }
@Override public int getStyle() { // TODO Pulldown. This does not currently support the pulldown style. final State state = command.getCommand().getState(IMenuStateIds.STYLE); if (state instanceof RadioState) { return IAction.AS_RADIO_BUTTON; } else if (state instanceof ToggleState) { return IAction.AS_CHECK_BOX; } return IAction.AS_PUSH_BUTTON; }
public void dispose() { // not important for command ID, maybe for command though. handlerService = null; if (commandListener != null) { parameterizedCommand.getCommand().removeCommandListener( commandListener); commandListener = null; } parameterizedCommand = null; }
/** * Performs the actual retrieval. * @param item the command contribution item to retrieve command from. * @return the command stored in the command contribution item. * Can be <code>null</code> if the command can't be found. */ public Command get(final CommandContributionItem item) { final ParameterizedCommand parCommand = getItemParCommand(item); return parCommand == null ? null : parCommand.getCommand(); }
@Override public boolean isEnabled() { if (command != null) { command.getCommand().setEnabled(menuService.getCurrentState()); return command.getCommand().isEnabled(); } return false; }
@Override public boolean isChecked() { final State state = command.getCommand().getState(IMenuStateIds.STYLE); if (state instanceof ToggleState) { final Boolean currentValue = (Boolean) state.getValue(); return currentValue.booleanValue(); } return false; }
@Override public void setDescription(final String text) { final State state = command.getCommand().getState( INamedHandleStateIds.DESCRIPTION); if (state instanceof TextState) { final String currentValue = (String) state.getValue(); if (!Objects.equals(text, currentValue)) { state.setValue(text); } } }
@Override public void setText(final String text) { final State state = command.getCommand().getState( INamedHandleStateIds.NAME); if (state instanceof TextState) { final String currentValue = (String) state.getValue(); if (!Objects.equals(text, currentValue)) { state.setValue(text); } } }
/** * Fill in a temporary static context for execution. * * @param command */ @SuppressWarnings("rawtypes") private void addParms(ParameterizedCommand command, IEclipseContext staticContext) { final Map parms = command.getParameterMap(); Iterator i = parms.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); String parameterId = (String) entry.getKey(); staticContext.set( parameterId, convertParameterValue(command.getCommand(), parameterId, (String) entry.getValue())); } staticContext.set(PARM_MAP, parms); staticContext.set(ParameterizedCommand.class, command); }
@Override public void setChecked(final boolean checked) { final State state = command.getCommand().getState(IMenuStateIds.STYLE); if (state instanceof ToggleState) { final Boolean currentValue = (Boolean) state.getValue(); if (checked != currentValue.booleanValue()) { if (checked) { state.setValue(Boolean.TRUE); } else { state.setValue(Boolean.FALSE); } } } }
private void disconnectReferences() { if (elementRef != null) { commandService.unregisterElement(elementRef); elementRef = null; } if (commandListener != null) { command.getCommand().removeCommandListener(commandListener); commandListener = null; } if (bindingService != null) { bindingService.removeBindingManagerListener(bindingManagerListener); } }
@Override protected boolean isLeafMatch(Viewer viewer, Object element) { if (filterCategories) { final ParameterizedCommand cmd = getCommand(element); try { if (cmd != null && cmd.getCommand().getCategory() == uncategorized) { return false; } } catch (NotDefinedException e) { return false; } } return super.isLeafMatch(viewer, element); }
@Override public void runWithEvent(final Event event) { final Command baseCommand = command.getCommand(); final ExecutionEvent executionEvent = new ExecutionEvent(command .getCommand(), command.getParameterMap(), event, null); try { baseCommand.execute(executionEvent); firePropertyChange(IAction.RESULT, null, Boolean.TRUE); } catch (final NotHandledException e) { firePropertyChange(IAction.RESULT, null, Boolean.FALSE); } catch (final ExecutionException e) { firePropertyChange(IAction.RESULT, null, Boolean.FALSE); // TODO Should this be logged? } }
@Override public IElementReference registerElementForCommand( ParameterizedCommand command, UIElement element) throws NotDefinedException { if (!command.getCommand().isDefined()) { throw new NotDefinedException( "Cannot define a callback for undefined command " //$NON-NLS-1$ + command.getCommand().getId()); } if (element == null) { throw new NotDefinedException("No callback defined for command " //$NON-NLS-1$ + command.getCommand().getId()); } ElementReference ref = new ElementReference(command.getId(), element, command.getParameterMap()); registerElement(ref); return ref; }
@Override public IElementReference registerElementForCommand( ParameterizedCommand command, UIElement element) throws NotDefinedException { if (!command.getCommand().isDefined()) { throw new NotDefinedException( "Cannot define a callback for undefined command " //$NON-NLS-1$ + command.getCommand().getId()); } if (element == null) { throw new NotDefinedException("No callback defined for command " //$NON-NLS-1$ + command.getCommand().getId()); } ElementReference ref = new ElementReference(command.getId(), element, command.getParameterMap()); registerElement(ref); return ref; }
@Override public ExecutionEvent createExecutionEvent(ParameterizedCommand command, Event event) { EvaluationContext legacy = new EvaluationContext(evalContext, evalContext.getDefaultVariable()); ExecutionEvent e = new ExecutionEvent(command.getCommand(), command.getParameterMap(), event, legacy); return e; }
/** * @param bindingCommand */ private void setCommandInfo(ParameterizedCommand bindingCommand) { setId(bindingCommand.getId()); try { setName(bindingCommand.getName()); } catch (NotDefinedException e) { setName(NewKeysPreferenceMessages.Undefined_Command); } try { setDescription(bindingCommand.getCommand().getDescription()); } catch (NotDefinedException e) { setDescription(Util.ZERO_LENGTH_STRING); } try { setCategory(bindingCommand.getCommand().getCategory().getName()); } catch (NotDefinedException e) { setCategory(NewKeysPreferenceMessages.Unavailable_Category); } setConflict(Boolean.FALSE); }
@Override public boolean canExecute(ParameterizedCommand command, IEclipseContext staticContext) { final IEclipseContext executionContext = getExecutionContext(); addParms(command, staticContext); // executionContext.set(STATIC_CONTEXT, staticContext); push(executionContext, staticContext); try { Command cmd = command.getCommand(); cmd.setEnabled(new ExpressionContext(peek().context)); return cmd.isEnabled(); } finally { pop(); // executionContext.remove(STATIC_CONTEXT); } }