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.internal.services.SourcePriorityNameMapping; 20 21 33 public class LegacyEditorActionBarExpression extends Expression { 34 37 private static final int HASH_INITIAL = LegacyEditorActionBarExpression.class 38 .getName().hashCode(); 39 40 44 private final String activeEditorId; 45 46 53 public LegacyEditorActionBarExpression(final String editorId) { 54 55 if (editorId == null) { 56 throw new IllegalArgumentException ( 57 "The targetId for an editor contribution must not be null"); } 59 activeEditorId = editorId; 60 } 61 62 public final void collectExpressionInfo(final ExpressionInfo info) { 63 info.addVariableNameAccess(ISources.ACTIVE_PART_ID_NAME); 64 info 65 .addVariableNameAccess(SourcePriorityNameMapping.LEGACY_LEGACY_NAME); 66 } 67 68 protected final int computeHashCode() { 69 int hashCode = HASH_INITIAL * HASH_FACTOR + hashCode(activeEditorId); 70 return hashCode; 71 } 72 73 public final boolean equals(final Object object) { 74 if (object instanceof LegacyEditorActionBarExpression) { 75 final LegacyEditorActionBarExpression that = (LegacyEditorActionBarExpression) object; 76 return activeEditorId.equals(that.activeEditorId); 77 } 78 79 return false; 80 } 81 82 87 public final EvaluationResult evaluate(final IEvaluationContext context) { 88 final Object variable = context 89 .getVariable(ISources.ACTIVE_PART_ID_NAME); 90 if (equals(activeEditorId, variable)) { 91 return EvaluationResult.TRUE; 92 } 93 return EvaluationResult.FALSE; 94 } 95 96 public final String toString() { 97 final StringBuffer buffer = new StringBuffer (); 98 buffer.append("LegacyEditorActionBarExpression("); buffer.append(activeEditorId); 100 buffer.append(')'); 101 return buffer.toString(); 102 } 103 } 104 | Popular Tags |