@Override public Map getAttributeValuesByName() { final Map attributeValues = new HashMap(); // avoid using Boolean.valueOf to allow compilation against JCL // Foundation (bug 80053) attributeValues.put(ILegacyAttributeNames.ENABLED, command.isEnabled() ? Boolean.TRUE : Boolean.FALSE); attributeValues.put(ILegacyAttributeNames.HANDLED, command.isHandled() ? Boolean.TRUE : Boolean.FALSE); return attributeValues; }
public class HandlerEnabledTester extends PropertyTester { private static final String PROPERTY_HANDLER_ENABLED = "handlerEnabled"; @Override public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) { if (PROPERTY_HANDLER_ENABLED.equals(property)) { return isHandlerEnabled((String) expectedValue); } return false; } private static boolean isHandlerEnabled(String commandId) { ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); Command command = commandService.getCommand(commandId); return command.isEnabled(); } }
@Override public boolean isEnabled() { if (command != null) { command.getCommand().setEnabled(menuService.getCurrentState()); return command.getCommand().isEnabled(); } return false; }
public void showDetailsFor(Object object) { if (object instanceof ParameterizedCommand) object = (fPreSel = (ParameterizedCommand) object).getCommand(); if (!(object instanceof Command)) { resetAllFields(); return; } fSelectedCommand = (Command) object; fComIDT.setText(fSelectedCommand.getId()); fParameterToValue.clear(); fObjectParamList.clear(); fValueParamList.clear(); fExecLink.setVisible(fSelectedCommand.isEnabled()); fCopyLink.setVisible(true); try { populateParams(fSelectedCommand, object); } catch (NotDefinedException e) { createNoParamComp(); } updatePreviewText(); }
protected ICommandListener getCommandListener() { if (commandListener == null) { commandListener = commandEvent -> { if (commandEvent.isHandledChanged() || commandEvent.isEnabledChanged()) { if (commandEvent.getCommand().isDefined()) { setEnabled(commandEvent.getCommand().isEnabled()); } } }; } return commandListener; }
@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); } }
@Override protected void handleDoubleClick(DoubleClickEvent anEvent) { ICommandService commandService = getViewSite().getService(ICommandService.class); Command openProjectCommand = commandService.getCommand(IWorkbenchCommandConstants.PROJECT_OPEN_PROJECT); if (openProjectCommand != null && openProjectCommand.isHandled() && openProjectCommand.isEnabled()) { IStructuredSelection selection = (IStructuredSelection) anEvent .getSelection(); Object element = selection.getFirstElement(); if (element instanceof IProject && !((IProject) element).isOpen()) { try { openProjectCommand.executeWithChecks(new ExecutionEvent()); } catch (CommandException ex) { IStatus status = WorkbenchNavigatorPlugin.createErrorStatus("'Open Project' failed", ex); //$NON-NLS-1$ WorkbenchNavigatorPlugin.getDefault().getLog().log(status); } return; } } super.handleDoubleClick(anEvent); }
if (!isEnabled()) { final NotEnabledException exception = new NotEnabledException( "Trying to execute the disabled command " + getId()); //$NON-NLS-1$
if (!isEnabled()) { final NotEnabledException exception = new NotEnabledException( "Trying to execute the disabled command " + getId()); //$NON-NLS-1$
if (!isEnabled()) { final NotEnabledException exception = new NotEnabledException( "Trying to execute the disabled command " + getId()); //$NON-NLS-1$
boolean enabledChanged = isEnabled();
boolean enabledChanged = isEnabled();
boolean enabledChanged = isEnabled();
parameterizedCommand.getCommand().setEnabled( handlerService.getCurrentState()); setEnabled(parameterizedCommand.getCommand().isEnabled()); setImageDescriptor(commandImageService.getImageDescriptor( commandIdIn, ICommandImageService.TYPE_DEFAULT));