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 LegacyEditorContributionExpression extends 34 WorkbenchWindowExpression { 35 36 39 private static final int HASH_INITIAL = LegacyEditorContributionExpression.class 40 .getName().hashCode(); 41 42 46 private final String activeEditorId; 47 48 59 public LegacyEditorContributionExpression(final String activeEditorId, 60 final IWorkbenchWindow window) { 61 super(window); 62 63 if (activeEditorId == null) { 64 throw new NullPointerException ( 65 "The targetId for an editor contribution must not be null"); } 67 this.activeEditorId = activeEditorId; 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(activeEditorId); 78 return hashCode; 79 } 80 81 public final boolean equals(final Object object) { 82 if (object instanceof LegacyEditorContributionExpression) { 83 final LegacyEditorContributionExpression that = (LegacyEditorContributionExpression) object; 84 return equals(this.activeEditorId, that.activeEditorId) 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(activeEditorId, 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("LegacyEditorContributionExpression("); buffer.append(activeEditorId); 110 buffer.append(','); 111 buffer.append(getWindow()); 112 buffer.append(')'); 113 return buffer.toString(); 114 } 115 116 } 117 | Popular Tags |