Package org.eclipse.core.commands

Examples of org.eclipse.core.commands.Command


    tracker.setEnabled(true);

    String name = "cmdName";
    String description = "cmdDescription";
    String id = System.currentTimeMillis() + "." + System.nanoTime();
    Command command = getCommandService().getCommand(id);
    command.define(name, description,
        getCommandService().getDefinedCategories()[0]);

    long start = System.currentTimeMillis();
    getHandlerService().activateHandler(command.getId(), createHandler());
    getHandlerService().executeCommand(command.getId(), null);
    long end = System.currentTimeMillis();

    assertEquals(1, tracker.getData().size());
    CommandEvent e = tracker.getData().iterator().next();
    assertEquals(command, e.getExecutionEvent().getCommand());
View Full Code Here


    // Reset the key binding state (close window, clear status line, etc.)
    resetState(false);

    // Dispatch to the handler.
    final Command command = parameterizedCommand.getCommand();
    final boolean commandDefined = command.isDefined();
    final boolean commandHandled = command.isHandled();
    final boolean commandEnabled = command.isEnabled();

    if (DEBUG && DEBUG_VERBOSE) {
      if (!commandDefined) {
        Tracing.printTrace("KEYS", "    not defined"); //$NON-NLS-1$ //$NON-NLS-2$
      } else if (!commandHandled) {
View Full Code Here

   *
   * @return the string describing the key sequence, or <code>null</code> if
   *         it cannot be determined.
   */
  private String getKeySequenceString() {
    final Command command = commandService
        .getCommand("org.eclipse.ui.window.showKeyAssist"); //$NON-NLS-1$
    final TriggerSequence[] keyBindings = bindingService
        .getActiveBindingsFor(new ParameterizedCommand(command, null));
    final int keyBindingsCount = keyBindings.length;
    final KeySequence currentState = keyBindingState.getCurrentSequence();
View Full Code Here

     */
    final Iterator partialMatchItr = partialMatches.entrySet().iterator();
    while (partialMatchItr.hasNext()) {
      final Map.Entry entry = (Map.Entry) partialMatchItr.next();
      final Binding binding = (Binding) entry.getValue();
      final Command command = binding.getParameterizedCommand()
          .getCommand();
      if (command.isDefined()
          && activityManager.getIdentifier(command.getId())
              .isEnabled()) {
        sortedMatches.put(binding, entry.getKey());
      }
    }

View Full Code Here

   *            The activation to use; may be <code>null</code> if the
   *            command should have a <code>null</code> handler.
   */
  private final void updateCommand(final String commandId,
      final IHandlerActivation activation) {
    final Command command = commandService.getCommand(commandId);
    if (activation == null) {
      command.setHandler(null);
    } else {
      command.setHandler(activation.getHandler());
      commandService.refreshElements(commandId, null);
    }
  }
View Full Code Here

   */
  private final ParameterizedCommand convertActionToCommand(
      final IConfigurationElement element, final String primaryId,
      final String secondaryId, final List warningsToLog) {
    String commandId = readOptional(element, ATT_DEFINITION_ID);
    Command command = null;
    if (commandId != null) {
      command = commandService.getCommand(commandId);
    }

    final IActionCommandMappingService mappingService = (IActionCommandMappingService) window
        .getService(IActionCommandMappingService.class);
   
    String label = null;
    if ((commandId == null) || (!command.isDefined())) {
      // Add a mapping from this action id to the command id.
      if (commandId == null && mappingService != null) {
        commandId = mappingService.getGeneratedCommandId(primaryId,
            secondaryId);
      }
      if (commandId == null) {
        WorkbenchPlugin.log("MappingService unavailable"); //$NON-NLS-1$
        return null;
      }

      // Read the label attribute.
      label = readRequired(element, ATT_LABEL, warningsToLog,
          "Actions require a non-empty label or definitionId", //$NON-NLS-1$
          commandId);
      if (label == null) {
        label = WorkbenchMessages.LegacyActionPersistence_AutogeneratedCommandName;
      }

      /*
       * Read the tooltip attribute. The tooltip is really the description
       * of the command.
       */
      final String tooltip = readOptional(element, ATT_TOOLTIP);

      // Define the command.
      command = commandService.getCommand(commandId);
      final Category category = commandService.getCategory(null);
      final String name = LegacyActionTools.removeAcceleratorText(Action
          .removeMnemonics(label));
      command.define(name, tooltip, category, null);

      // TODO Decide the command state.
      final String style = readOptional(element, ATT_STYLE);
      if (STYLE_RADIO.equals(style)) {
        final State state = new RadioState();
        // TODO How to set the id?
        final boolean checked = readBoolean(element, ATT_STATE, false);
        state.setValue((checked) ? Boolean.TRUE : Boolean.FALSE);
        command.addState(IMenuStateIds.STYLE, state);

      } else if (STYLE_TOGGLE.equals(style)) {
        final State state = new ToggleState();
        final boolean checked = readBoolean(element, ATT_STATE, false);
        state.setValue((checked) ? Boolean.TRUE : Boolean.FALSE);
        command.addState(IMenuStateIds.STYLE, state);
      }
    }
    // this allows us to look up a "commandId" give the contributionId
    // and the actionId
    if (mappingService != null && commandId != null) {
View Full Code Here

    return false;
  }

  public final boolean isEnabled() {
    final Command baseCommand = command.getCommand();
    return baseCommand.isEnabled() && enabled;
  }
View Full Code Here

  public final boolean isEnabledDisregardingCommand() {
    return enabled;
  }

  public final boolean isHandled() {
    final Command baseCommand = command.getCommand();
    return baseCommand.isHandled();
  }
View Full Code Here

  public final void run() {
    runWithEvent(null);
  }

  public final 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);
View Full Code Here

    final ImageDescriptor oldDisabledImage = getDisabledImageDescriptor();
    final ImageDescriptor oldHoverImage = getHoverImageDescriptor();
    final String oldText = getText();

    // Update the command.
    final Command oldBaseCommand = command.getCommand();
    oldBaseCommand.removeCommandListener(commandListener);
    final ICommandService commandService = (ICommandService) serviceLocator
        .getService(ICommandService.class);
    final Command newBaseCommand = commandService.getCommand(id);
    command = new ParameterizedCommand(newBaseCommand, null);
    newBaseCommand.addCommandListener(commandListener);

    // Get the new values.
    final boolean newChecked = isChecked();
    final String newDescription = getDescription();
    final boolean newEnabled = isEnabled();
View Full Code Here

TOP

Related Classes of org.eclipse.core.commands.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.