1 11 12 package org.eclipse.ui.internal.expressions; 13 14 import org.eclipse.core.expressions.EvaluationResult; 15 import org.eclipse.core.expressions.ExpressionInfo; 16 import org.eclipse.core.expressions.IEvaluationContext; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.ui.ISources; 19 import org.eclipse.ui.IWorkbenchWindow; 20 21 33 public final class LegacyViewContributionExpression extends 34 WorkbenchWindowExpression { 35 36 39 private static final int HASH_INITIAL = LegacyViewContributionExpression.class 40 .getName().hashCode(); 41 42 46 private final String activePartId; 47 48 59 public LegacyViewContributionExpression(final String activePartId, 60 final IWorkbenchWindow window) { 61 super(window); 62 63 if (activePartId == null) { 64 throw new NullPointerException ( 65 "The targetId for a view contribution must not be null"); } 67 this.activePartId = activePartId; 68 } 69 70 public final void collectExpressionInfo(final ExpressionInfo info) { 71 super.collectExpressionInfo(info); 72 info.addVariableNameAccess(ISources.ACTIVE_PART_ID_NAME); 73 } 74 75 protected final int computeHashCode() { 76 int hashCode = HASH_INITIAL * HASH_FACTOR + hashCode(getWindow()); 77 hashCode = hashCode * HASH_FACTOR + hashCode(activePartId); 78 return hashCode; 79 } 80 81 public final boolean equals(final Object object) { 82 if (object instanceof LegacyViewContributionExpression) { 83 final LegacyViewContributionExpression that = (LegacyViewContributionExpression) object; 84 return equals(this.activePartId, that.activePartId) 85 && equals(this.getWindow(), that.getWindow()); 86 } 87 88 return false; 89 } 90 91 public final EvaluationResult evaluate(final IEvaluationContext context) 92 throws CoreException { 93 final EvaluationResult result = super.evaluate(context); 94 if (result == EvaluationResult.FALSE) { 95 return result; 96 } 97 98 final Object variable = context 99 .getVariable(ISources.ACTIVE_PART_ID_NAME); 100 if (equals(activePartId, variable)) { 101 return EvaluationResult.TRUE; 102 } 103 return EvaluationResult.FALSE; 104 } 105 106 public final String toString() { 107 final StringBuffer buffer = new StringBuffer (); 108 buffer.append("LegacyViewContributionExpression("); buffer.append(activePartId); 110 buffer.append(','); 111 buffer.append(getWindow()); 112 buffer.append(')'); 113 return buffer.toString(); 114 } 115 116 } 117 | Popular Tags |