Package org.eclipse.core.commands

Examples of org.eclipse.core.commands.Command


   * Listens to changes to one or more commands, and forwards them out through
   * the property change event mechanism.
   */
  private final class CommandListener implements ICommandListener {
    public final void commandChanged(final CommandEvent commandEvent) {
      final Command baseCommand = commandEvent.getCommand();

      // Check if the name changed.
      if (commandEvent.isNameChanged()) {
        String newName = null;
        if (baseCommand.isDefined()) {
          try {
            newName = baseCommand.getName();
          } catch (final NotDefinedException e) {
            // Not defined, so leave as null.
          }
        }
        firePropertyChange(IAction.TEXT, null, newName);
      }

      // Check if the description changed.
      if (commandEvent.isDescriptionChanged()) {
        String newDescription = null;
        if (baseCommand.isDefined()) {
          try {
            newDescription = baseCommand.getDescription();
          } catch (final NotDefinedException e) {
            // Not defined, so leave as null.
          }
        }
        firePropertyChange(IAction.DESCRIPTION, null, newDescription);
        firePropertyChange(IAction.TOOL_TIP_TEXT, null, newDescription);
      }

      // Check if the handled property changed.
      if (commandEvent.isHandledChanged()) {
        if (baseCommand.isHandled()) {
          firePropertyChange(IAction.HANDLED, Boolean.FALSE,
              Boolean.TRUE);
        } else {
          firePropertyChange(IAction.HANDLED, Boolean.TRUE,
              Boolean.FALSE);
View Full Code Here


     
      Map commandsByName = new HashMap();

      for (Iterator iterator = commandService.getDefinedCommandIds()
          .iterator(); iterator.hasNext();) {
        Command command = commandService.getCommand((String) iterator
            .next());
        if (!isActive(command)) {
          continue;
        }

        try {
          String name = command.getName();
          Collection commands = (Collection) commandsByName.get(name);

          if (commands == null) {
            commands = new HashSet();
            commandsByName.put(name, commands);
          }

          commands.add(command);
        } catch (NotDefinedException eNotDefined) {
          // Do nothing
        }
      }
     
      // moved here to allow us to remove any empty categories
      commandIdsByCategoryId = new HashMap();

      for (Iterator iterator = commandService.getDefinedCommandIds()
          .iterator(); iterator.hasNext();) {
        final Command command = commandService
            .getCommand((String) iterator.next());
        if (!isActive(command)) {
          continue;
        }

        try {
          String categoryId = command.getCategory().getId();
          Collection commandIds = (Collection) commandIdsByCategoryId
              .get(categoryId);

          if (commandIds == null) {
            commandIds = new HashSet();
            commandIdsByCategoryId.put(categoryId, commandIds);
          }

          commandIds.add(command.getId());
        } catch (NotDefinedException eNotDefined) {
          // Do nothing
        }
      }
View Full Code Here

     */
    List commands = new ArrayList();
    final Iterator commandIdItr = commandIds.iterator();
    while (commandIdItr.hasNext()) {
      final String currentCommandId = (String) commandIdItr.next();
      final Command currentCommand = commandService
          .getCommand(currentCommandId);
      try {
        commands.addAll(ParameterizedCommand
            .generateCombinations(currentCommand));
      } catch (final NotDefinedException e) {
View Full Code Here

      final Binding binding = (Binding) bindingItr.next();
      final Context context = contextService.getContext(binding
          .getContextId());
      final ParameterizedCommand parameterizedCommand = binding
          .getParameterizedCommand();
      final Command command = parameterizedCommand.getCommand();
      if ((!context.isDefined()) && (!command.isDefined())) {
        continue;
      }

      final TableItem tableItem = new TableItem(
          tableBindingsForTriggerSequence, SWT.NULL);
View Full Code Here

        /*
         * Get the category name, command name, formatted key sequence
         * and context name for the first binding.
         */
        final Command command1 = binding1.getParameterizedCommand()
            .getCommand();
        String categoryName1 = Util.ZERO_LENGTH_STRING;
        String commandName1 = Util.ZERO_LENGTH_STRING;
        try {
          commandName1 = command1.getName();
          categoryName1 = command1.getCategory().getName();
        } catch (final NotDefinedException e) {
          // Just use the zero-length string.
        }
        final String triggerSequence1 = binding1.getTriggerSequence()
            .format();
        final String contextId1 = binding1.getContextId();
        String contextName1 = Util.ZERO_LENGTH_STRING;
        if (contextId1 != null) {
          final Context context = contextService
              .getContext(contextId1);
          try {
            contextName1 = context.getName();
          } catch (final org.eclipse.core.commands.common.NotDefinedException e) {
            // Just use the zero-length string.
          }
        }

        /*
         * Get the category name, command name, formatted key sequence
         * and context name for the first binding.
         */
        final Command command2 = binding2.getParameterizedCommand()
            .getCommand();
        String categoryName2 = Util.ZERO_LENGTH_STRING;
        String commandName2 = Util.ZERO_LENGTH_STRING;
        try {
          commandName2 = command2.getName();
          categoryName2 = command2.getCategory().getName();
        } catch (final org.eclipse.core.commands.common.NotDefinedException e) {
          // Just use the zero-length string.
        }
        final String keySequence2 = binding2.getTriggerSequence()
            .format();
View Full Code Here

        // Read out the command id.
        String commandId = readOptional(memento, ATT_COMMAND_ID);
        if (commandId == null) {
          commandId = readOptional(memento, ATT_COMMAND);
        }
        final Command command;
        if (commandId != null) {
          command = commandService.getCommand(commandId);
        } else {
          command = null;
        }
View Full Code Here

        commandId = configurationElement.getAttribute(ATT_COMMAND);
      }
      if ((commandId != null) && (commandId.length() == 0)) {
        commandId = null;
      }
      final Command command;
      if (commandId != null) {
        command = commandService.getCommand(commandId);
        if (!command.isDefined()) {
          // Reference to an undefined command. This is invalid.
          addWarning(warningsToLog,
              "Cannot bind to an undefined command", //$NON-NLS-1$
              configurationElement, commandId);
          continue;
View Full Code Here

  }

  public final Object executeCommand(final String commandId,
      final Event trigger) throws ExecutionException,
      NotDefinedException, NotEnabledException, NotHandledException {
    final Command command = commandService.getCommand(commandId);
    final ExecutionEvent event = new ExecutionEvent(command,
        Collections.EMPTY_MAP, trigger, getCurrentState());
    return command.executeWithChecks(event);
  }
View Full Code Here

    if (commandId == null) {
      WorkbenchPlugin.log("Unable to create menu item \"" + getId() //$NON-NLS-1$
          + "\", no command id"); //$NON-NLS-1$
      return;
    }
    Command cmd = commandService.getCommand(commandId);
    if (!cmd.isDefined()) {
      WorkbenchPlugin.log("Unable to create menu item \"" + getId() //$NON-NLS-1$
          + "\", command \"" + commandId + "\" not defined"); //$NON-NLS-1$ //$NON-NLS-2$
      return;
    }

    if (parameters == null || parameters.size() == 0) {
      command = new ParameterizedCommand(cmd, null);
      return;
    }

    try {
      ArrayList parmList = new ArrayList();
      Iterator i = parameters.entrySet().iterator();
      while (i.hasNext()) {
        Map.Entry entry = (Map.Entry) i.next();
        String parmName = (String) entry.getKey();
        IParameter parm;
        parm = cmd.getParameter(parmName);
        if (parm == null) {
          WorkbenchPlugin
              .log("Unable to create menu item \"" + getId() //$NON-NLS-1$
                  + "\", parameter \"" + parmName + "\" for command \"" //$NON-NLS-1$ //$NON-NLS-2$
                  + commandId + "\" is not defined"); //$NON-NLS-1$
View Full Code Here

      final Collection commandIds = commandService.getDefinedCommandIds();
      final Collection commands = new HashSet();
      final Iterator commandIdItr = commandIds.iterator();
      while (commandIdItr.hasNext()) {
        final String currentCommandId = (String) commandIdItr.next();
        final Command currentCommand = commandService
            .getCommand(currentCommandId);
        try {
          commands.addAll(ParameterizedCommand
              .generateCombinations(currentCommand));
        } catch (final NotDefinedException e) {
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.