1 11 12 package org.eclipse.ui.internal.expressions; 13 14 import org.eclipse.core.expressions.EvaluationResult; 15 import org.eclipse.core.expressions.Expression; 16 import org.eclipse.core.expressions.ExpressionInfo; 17 import org.eclipse.core.expressions.IEvaluationContext; 18 import org.eclipse.ui.ISources; 19 import org.eclipse.ui.IWorkbenchPart; 20 21 32 public final class ActivePartExpression extends Expression { 33 34 37 private static final int HASH_INITIAL = ActivePartExpression.class 38 .getName().hashCode(); 39 40 44 private final IWorkbenchPart activePart; 45 46 53 public ActivePartExpression(final IWorkbenchPart activePart) { 54 if (activePart == null) { 55 throw new NullPointerException ("The active part must not be null"); } 57 this.activePart = activePart; 58 } 59 60 public final void collectExpressionInfo(final ExpressionInfo info) { 61 info.addVariableNameAccess(ISources.ACTIVE_PART_NAME); 62 } 63 64 protected final int computeHashCode() { 65 return HASH_INITIAL * HASH_FACTOR + hashCode(activePart); 66 } 67 68 public final boolean equals(final Object object) { 69 if (object instanceof ActivePartExpression) { 70 final ActivePartExpression that = (ActivePartExpression) object; 71 return equals(this.activePart, that.activePart); 72 } 73 74 return false; 75 } 76 77 public final EvaluationResult evaluate(final IEvaluationContext context) { 78 final Object variable = context.getVariable(ISources.ACTIVE_PART_NAME); 79 if (equals(activePart, variable)) { 80 return EvaluationResult.TRUE; 81 } 82 return EvaluationResult.FALSE; 83 } 84 85 public final String toString() { 86 final StringBuffer buffer = new StringBuffer (); 87 buffer.append("ActivePartExpression("); buffer.append(activePart); 89 buffer.append(')'); 90 return buffer.toString(); 91 } 92 } 93 | Popular Tags |