Package org.eclipse.core.commands.contexts

Examples of org.eclipse.core.commands.contexts.Context


        if (contextTree.containsKey(childContextId)) {
          break;
        }

        // Retrieve the context.
        final Context childContext = contextManager
            .getContext(childContextId);

        // Add the child-parent pair to the tree.
        try {
          final String parentContextId = childContext.getParentId();
          contextTree.put(childContextId, parentContextId);
          childContextId = parentContextId;
        } catch (final NotDefinedException e) {
          break; // stop ascending
        }
View Full Code Here


     * active.
     */
    contextIdItr = contextIds.iterator();
    while (contextIdItr.hasNext()) {
      String contextId = (String) contextIdItr.next();
      Context context = contextManager.getContext(contextId);
      try {
        String parentId = context.getParentId();
        while (parentId != null) {
          if (IContextIds.CONTEXT_ID_DIALOG.equals(parentId)) {
            if (!dialog) {
              contextIdItr.remove();
            }
            break;
          }
          if (IContextIds.CONTEXT_ID_WINDOW.equals(parentId)) {
            if (!window) {
              contextIdItr.remove();
            }
            break;
          }
          if (IContextIds.CONTEXT_ID_DIALOG_AND_WINDOW
              .equals(parentId)) {
            if ((!window) && (!dialog)) {
              contextIdItr.remove();
            }
            break;
          }

          context = contextManager.getContext(parentId);
          parentId = context.getParentId();
        }
      } catch (NotDefinedException e) {
        // since this context was part of an undefined hierarchy,
        // I'm going to yank it out as a bad bet
        contextIdItr.remove();

        // This is a logging optimization, only log the error once.
        if (context == null || !bindingErrors.contains(context.getId())) {
          if (context != null) {
            bindingErrors.add(context.getId());
          }

          // now log like you've never logged before!
          Policy
              .getLog()
View Full Code Here

    if (visible == true) {
      Map contextsByName = new HashMap();

      for (Iterator iterator = contextService.getDefinedContextIds()
          .iterator(); iterator.hasNext();) {
        Context context = contextService.getContext((String) iterator
            .next());
        try {
          String name = context.getName();
          Collection contexts = (Collection) contextsByName.get(name);

          if (contexts == null) {
            contexts = new HashSet();
            contextsByName.put(name, contexts);
          }

          contexts.add(context);
        } catch (final NotDefinedException e) {
          // Do nothing.
        }
      }
     
      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
        }
      }

      Map categoriesByName = new HashMap();

      for (Iterator iterator = commandService.getDefinedCategoryIds()
          .iterator(); iterator.hasNext();) {
        Category category = commandService
            .getCategory((String) iterator.next());

        try {
          if (commandIdsByCategoryId.containsKey(category.getId())) {
            String name = category.getName();
            Collection categories = (Collection) categoriesByName
                .get(name);

            if (categories == null) {
              categories = new HashSet();
              categoriesByName.put(name, categories);
            }

            categories.add(category);
          }
        } catch (NotDefinedException eNotDefined) {
          // Do nothing
        }
      }

      Map schemesByName = new HashMap();

      final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
      for (int i = 0; i < definedSchemes.length; i++) {
        final Scheme scheme = definedSchemes[i];
        try {
          String name = scheme.getName();
          Collection schemes = (Collection) schemesByName.get(name);

          if (schemes == null) {
            schemes = new HashSet();
            schemesByName.put(name, schemes);
          }

          schemes.add(scheme);
        } catch (final NotDefinedException e) {
          // Do nothing.
        }
      }

      contextIdsByUniqueName = new HashMap();
      contextUniqueNamesById = new HashMap();

      for (Iterator iterator = contextsByName.entrySet().iterator(); iterator
          .hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();
        String name = (String) entry.getKey();
        Set contexts = (Set) entry.getValue();
        Iterator iterator2 = contexts.iterator();

        if (contexts.size() == 1) {
          Context context = (Context) iterator2.next();
          contextIdsByUniqueName.put(name, context.getId());
          contextUniqueNamesById.put(context.getId(), name);
        } else {
          while (iterator2.hasNext()) {
            Context context = (Context) iterator2.next();
            String uniqueName = MessageFormat.format(
                Util.translateString(RESOURCE_BUNDLE,
                    "uniqueName"), new Object[] { name, //$NON-NLS-1$
                    context.getId() });
            contextIdsByUniqueName.put(uniqueName, context.getId());
            contextUniqueNamesById.put(context.getId(), uniqueName);
          }
        }
      }

      categoryIdsByUniqueName = new HashMap();
View Full Code Here

   */
  private final void updateLabelContextExtends() {
    final String contextId = getContextId();

    if (contextId != null) {
      final Context context = contextService.getContext(getContextId());
      if (context.isDefined()) {
        try {
          final String parentId = context.getParentId();
          if (parentId != null) {
            final String name = (String) contextUniqueNamesById
                .get(parentId);
            if (name != null) {
              labelContextExtends.setText(MessageFormat.format(
View Full Code Here

    // Add each of the bindings.
    final Iterator bindingItr = bindings.iterator();
    while (bindingItr.hasNext()) {
      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);
      tableItem.setData(ITEM_DATA_KEY, binding);

      /*
       * Set the associated image based on the type of binding. Either it
       * is a user binding or a system binding.
       *
       * TODO Identify more image types.
       */
      if (binding.getType() == Binding.SYSTEM) {
        tableItem.setImage(0, IMAGE_BLANK);
      } else {
        tableItem.setImage(0, IMAGE_CHANGE);
      }

      try {
        tableItem.setText(1, context.getName());
        tableItem.setText(2, parameterizedCommand.getName());
      } catch (final NotDefinedException e) {
        throw new Error(
            "Context or command became undefined on a non-UI thread while the UI thread was processing."); //$NON-NLS-1$
      }
View Full Code Here

        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();
        final String contextId2 = binding2.getContextId();
        String contextName2 = Util.ZERO_LENGTH_STRING;
        if (contextId2 != null) {
          final Context context = contextService
              .getContext(contextId2);
          try {
            contextName2 = context.getName();
          } catch (final org.eclipse.core.commands.common.NotDefinedException e) {
            // Just use the zero-length string.
          }
        }

        // Compare the items in the current sort order.
        int compare = 0;
        for (int i = 0; i < sortOrder.length; i++) {
          switch (sortOrder[i]) {
          case VIEW_CATEGORY_COLUMN_INDEX:
            compare = Util.compare(categoryName1, categoryName2);
            if (compare != 0) {
              return compare;
            }
            break;
          case VIEW_COMMAND_COLUMN_INDEX:
            compare = Util.compare(commandName1, commandName2);
            if (compare != 0) {
              return compare;
            }
            break;
          case VIEW_KEY_SEQUENCE_COLUMN_INDEX:
            compare = Util.compare(triggerSequence1, keySequence2);
            if (compare != 0) {
              return compare;
            }
            break;
          case VIEW_CONTEXT_COLUMN_INDEX:
            compare = Util.compare(contextName1, contextName2);
            if (compare != 0) {
              return compare;
            }
            break;
          default:
            throw new Error(
                "Programmer error: added another sort column without modifying the comparator."); //$NON-NLS-1$
          }
        }

        return compare;
      }

      /**
       * @see Object#equals(java.lang.Object)
       */
      public final boolean equals(final Object object) {
        return super.equals(object);
      }
    });

    // Add a table item for each item in the list.
    final Iterator keyBindingItr = bindings.iterator();
    while (keyBindingItr.hasNext()) {
      final Binding binding = (Binding) keyBindingItr.next();

      // Get the command and category name.
      final ParameterizedCommand command = binding
          .getParameterizedCommand();
      String commandName = Util.ZERO_LENGTH_STRING;
      String categoryName = Util.ZERO_LENGTH_STRING;
      try {
        commandName = command.getName();
        categoryName = command.getCommand().getCategory().getName();
      } catch (final org.eclipse.core.commands.common.NotDefinedException e) {
        // Just use the zero-length string.
      }

      // Ignore items with a meaningless command name.
      if ((commandName == null) || (commandName.length() == 0)) {
        continue;
      }

      // Get the context name.
      final String contextId = binding.getContextId();
      String contextName = Util.ZERO_LENGTH_STRING;
      if (contextId != null) {
        final Context context = contextService.getContext(contextId);
        try {
          contextName = context.getName();
        } catch (final org.eclipse.core.commands.common.NotDefinedException e) {
          // Just use the zero-length string.
        }
      }

View Full Code Here

     * Adds an action set.
     * @param desc
     */
    private void addActionSet(ActionSetDescriptor desc) {
    children.add(desc);
    Context actionSetContext = contextService.getContext(desc.getId());
    if (!actionSetContext.isDefined()) {
      actionSetContext.define(desc.getLabel(), desc.getDescription(),
          "org.eclipse.ui.contexts.actionSet"); //$NON-NLS-1$
    }
  }
View Full Code Here

   * Remove the action set.
   *
   * @param desc
   */
  private void removeActionSet(IActionSetDescriptor desc) {
    Context actionSetContext = contextService.getContext(desc.getId());
    if (actionSetContext.isDefined()) {
      actionSetContext.undefine();
    }
    children.remove(desc);
  }
View Full Code Here

      }
      if ((parentId != null) && (parentId.length() == 0)) {
        parentId = null;
      }

      final Context context = contextManager.getContext(contextId);
      context.define(name, description, parentId);
    }

    logWarnings(
        warningsToLog,
        "Warnings while parsing the contexts from the 'org.eclipse.ui.contexts', 'org.eclipse.ui.commands' and 'org.eclipse.ui.acceleratorScopes' extension points."); //$NON-NLS-1$
View Full Code Here

     * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
     */
    public final int compare(final Object object1, final Object object2) {
      final String contextId1 = (String) object1;
      final String contextId2 = (String) object2;
      Context context;
      String parentId;

      // Get the depth of the first context.
      int depth1 = 0;
      context = contextManager.getContext(contextId1);
      try {
        parentId = context.getParentId();
        while (parentId != null) {
          depth1++;
          context = contextManager.getContext(parentId);
          parentId = context.getParentId();
        }
      } catch (final NotDefinedException e) {
        // Do nothing. Stop ascending the ancestry.
      }

      // Get the depth of the second context.
      int depth2 = 0;
      context = contextManager.getContext(contextId2);
      try {
        parentId = context.getParentId();
        while (parentId != null) {
          depth2++;
          context = contextManager.getContext(parentId);
          parentId = context.getParentId();
        }
      } catch (final NotDefinedException e) {
        // Do nothing. Stop ascending the ancestry.
      }

View Full Code Here

TOP

Related Classes of org.eclipse.core.commands.contexts.Context

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.