Examples of IHandlerActivation


Examples of org.eclipse.ui.handlers.IHandlerActivation

        if (handlerActivations.isEmpty()) {
          handlerActivationsByCommandId.remove(commandId);
          updateCommand(commandId, null);

        } else if (handlerActivations.size() == 1) {
          final IHandlerActivation remainingActivation = (IHandlerActivation) handlerActivations
              .iterator().next();
          handlerActivationsByCommandId.put(commandId,
              remainingActivation);
          updateCommand(
              commandId,
View Full Code Here

Examples of org.eclipse.ui.handlers.IHandlerActivation

      return null;
    }

    // Cycle over the activations, remembered the current best.
    final Iterator activationItr = activations.iterator();
    IHandlerActivation bestActivation = null;
    IHandlerActivation currentActivation = null;
    boolean conflict = false;
    while (activationItr.hasNext()) {
      currentActivation = (IHandlerActivation) activationItr.next();
      if (!evaluate(currentActivation)) {
        continue; // only consider potentially active handlers
      }

      // Check to see if we haven't found a potentially active handler yet
      if ((DEBUG_VERBOSE)
          && ((DEBUG_VERBOSE_COMMAND_ID == null) || (DEBUG_VERBOSE_COMMAND_ID
              .equals(commandId)))) {
        Tracing.printTrace(TRACING_COMPONENT,
            "    resolveConflicts: eval: " + currentActivation); //$NON-NLS-1$
      }
      if (bestActivation == null) {
        bestActivation = currentActivation;
        conflict = false;
        continue;
      }

      // Compare the two handlers.
      final int comparison = bestActivation.compareTo(currentActivation);
      if (comparison < 0) {
        bestActivation = currentActivation;
        conflict = false;

      } else if (comparison == 0) {
        if (currentActivation.getHandler() != bestActivation
            .getHandler()) {
          conflict = true;
          break;
        }

      } else {
        break;
      }
    }

    // If we are logging information, now is the time to do it.
    if (DEBUG) {
      if (conflict) {
        Tracing.printTrace(TRACING_COMPONENT,
            "Unresolved conflict detected for '" //$NON-NLS-1$
                + commandId + '\'');
      } else if ((bestActivation != null)
          && (DEBUG_VERBOSE)
          && ((DEBUG_VERBOSE_COMMAND_ID == null) || (DEBUG_VERBOSE_COMMAND_ID
              .equals(commandId)))) {
        Tracing
            .printTrace(TRACING_COMPONENT,
                "Resolved conflict detected.  The following activation won: "); //$NON-NLS-1$
        Tracing.printTrace(TRACING_COMPONENT, "    " + bestActivation); //$NON-NLS-1$
      }
    }

    // Return the current best.
    if (conflict) {
      if (previousLogs.add(commandId)) {
        final StringWriter sw = new StringWriter();
        final BufferedWriter buffer = new BufferedWriter(sw);
        try {
          buffer.write("Conflict for \'"); //$NON-NLS-1$
          buffer.write(commandId);
          buffer.write("\':"); //$NON-NLS-1$
          buffer.newLine();
          buffer.write(bestActivation.toString());
          buffer.newLine();
          buffer.write(currentActivation.toString());
          buffer.flush();
        } catch (IOException e) {
          //should never get this.
        }
View Full Code Here

Examples of org.eclipse.ui.handlers.IHandlerActivation

                .next();
            final Iterator activationItr = activations.iterator();

            // Check the first activation to see if it has changed.
            if (activationItr.hasNext()) {
              IHandlerActivation activation = (IHandlerActivation) activationItr
                  .next();
              final boolean currentActive = evaluate(activation);
              activation.clearResult();
              final boolean newActive = evaluate(activation);
              if (newActive != currentActive) {
                changedCommandIds
                    .add(activation.getCommandId());

                // Then add every other activation as well.
                while (activationItr.hasNext()) {
                  activation = (IHandlerActivation) activationItr
                      .next();
                  activation.setResult(newActive);

                  changedCommandIds.add(activation
                      .getCommandId());
                }
              } else {
                while (activationItr.hasNext()) {
                  activation = (IHandlerActivation) activationItr
                      .next();
                  // if for some reason another activation
                  // doesn't match the new result, update and
                  // mark as changed. It's not as expensive
                  // as it looks :-)
                  if (newActive != evaluate(activation)) {
                    activation.setResult(newActive);
                    changedCommandIds.add(activation
                        .getCommandId());
                  }
                }
              }
            }
          }
        }
      }
    }

    MultiStatus conflicts = new MultiStatus("org.eclipse.ui.workbench", 0//$NON-NLS-1$
        "A handler conflict occurred.  This may disable some commands.", //$NON-NLS-1$
        null);
   
    /*
     * For every command identifier with a changed activation, we resolve
     * conflicts and trigger an update.
     */
    final Iterator changedCommandIdItr = changedCommandIds.iterator();
    while (changedCommandIdItr.hasNext()) {
      final String commandId = (String) changedCommandIdItr.next();
      final Object value = handlerActivationsByCommandId.get(commandId);
      if (value instanceof IHandlerActivation) {
        final IHandlerActivation activation = (IHandlerActivation) value;
        updateCommand(commandId, (evaluate(activation) ? activation
            : null));
      } else if (value instanceof SortedSet) {
        final IHandlerActivation activation = resolveConflicts(
            commandId, (SortedSet) value, conflicts);
        updateCommand(commandId, activation);
      } else {
        updateCommand(commandId, null);
      }
View Full Code Here

Examples of org.eclipse.ui.handlers.IHandlerActivation

   */
  public final IHandler findHandler(String commandId,
      IEvaluationContext context) {
    Object o = handlerActivationsByCommandId.get(commandId);
    if (o instanceof IHandlerActivation) {
      IHandlerActivation activation = (IHandlerActivation) o;
      try {
        if (eval(context, activation)) {
          return activation.getHandler();
        }
      } catch (CoreException e) {
        // the evalution failed
      }
    } else if (o instanceof SortedSet) {
      SortedSet activations = (SortedSet) o;
      IHandlerActivation lastActivation = null;
      IHandlerActivation currentActivation = null;
      Iterator i = activations.iterator();
      while (i.hasNext() && lastActivation==null) {
        IHandlerActivation activation = (IHandlerActivation) i.next();
        try {
          if (eval(context, activation)) {
            lastActivation = currentActivation;
            currentActivation = activation;
          }
View Full Code Here

Examples of org.eclipse.ui.handlers.IHandlerActivation

   * <b>Note:</b> this class has a natural ordering that is inconsistent with
   * equals.
   * </p>
   */
  public final int compareTo(final Object object) {
    final IHandlerActivation activation = (IHandlerActivation) object;
    int difference;

    // Check the priorities
    int thisPriority = this.getSourcePriority();
    int thatPriority = activation.getSourcePriority();
   
    // rogue bit problem - ISources.ACTIVE_MENU
    int thisLsb = 0;
    int thatLsb = 0;
   
    if (((thisPriority & ISources.ACTIVE_MENU) | (thatPriority & ISources.ACTIVE_MENU)) != 0) {
      thisLsb = thisPriority & 1;
      thisPriority = (thisPriority >> 1) & 0x7fffffff;
      thatLsb = thatPriority & 1;
      thatPriority = (thatPriority  >> 1) & 0x7fffffff;
    }
   
    difference = thisPriority - thatPriority;
    if (difference != 0) {
      return difference;
    }
   
    // if all of the higher bits are the same, check the
    // difference of the LSB
    difference = thisLsb - thatLsb;
    if (difference != 0) {
      return difference;
    }

    // Check depth
    final int thisDepth = this.getDepth();
    final int thatDepth = activation.getDepth();
    difference = thisDepth - thatDepth;
    return difference;
  }
View Full Code Here

Examples of org.eclipse.ui.handlers.IHandlerActivation

    final Iterator localActivationItr = localActivationsToParentActivations
        .keySet().iterator();
    while (localActivationItr.hasNext()) {
      final Object object = localActivationItr.next();
      if (object instanceof IHandlerActivation) {
        final IHandlerActivation localActivation = (IHandlerActivation) object;
        final String commandId = localActivation.getCommandId();
        final IHandler handler = localActivation.getHandler();
        final IHandlerActivation parentActivation = parent
            .activateHandler(commandId, handler, defaultExpression);
        parentActivations.add(parentActivation);
        localActivationsToParentActivations.put(localActivation,
            parentActivation);
      }
View Full Code Here

Examples of org.eclipse.ui.handlers.IHandlerActivation

    active = true;
  }

  protected final IHandlerActivation doActivation(
      final IHandlerActivation localActivation) {
    final IHandlerActivation parentActivation;
    if (active) {
      parentActivation = parent.activateHandler(localActivation);
      parentActivations.add(parentActivation);
    } else {
      parentActivation = null;
View Full Code Here

Examples of org.eclipse.ui.handlers.IHandlerActivation

    }
    if (defaultExpression != null) {
      expression.add(defaultExpression);
    }
    final int depth = childActivation.getDepth() + 1;
    final IHandlerActivation localActivation = new HandlerActivation(
        commandId, handler, expression, depth, this);

    return doActivation(localActivation);
  }
View Full Code Here

Examples of org.eclipse.ui.handlers.IHandlerActivation

    return doActivation(localActivation);
  }

  public final IHandlerActivation activateHandler(final String commandId,
      final IHandler handler) {
    final IHandlerActivation localActivation = new HandlerActivation(
        commandId, handler, defaultExpression,
        IHandlerActivation.ROOT_DEPTH, this);
    return doActivation(localActivation);
  }
View Full Code Here

Examples of org.eclipse.ui.handlers.IHandlerActivation

  public final IHandlerActivation activateHandler(final String commandId,
      final IHandler handler, final Expression expression,
      final boolean global) {
    if (global) {
      final IHandlerActivation activation = parent.activateHandler(
          commandId, handler, expression, global);
      parentActivations.add(activation);
      return activation;
    }

    final AndExpression andExpression;
    if (expression instanceof AndExpression) {
      andExpression = (AndExpression) expression;
    } else {
      andExpression = new AndExpression();
      if (expression != null) {
        andExpression.add(expression);
      }
    }
    if (defaultExpression != null) {
      andExpression.add(defaultExpression);
    }
    final IHandlerActivation localActivation = new HandlerActivation(
        commandId, handler, andExpression,
        IHandlerActivation.ROOT_DEPTH, this);
    return doActivation(localActivation);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.