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 import org.eclipse.ui.internal.registry.IActionSetDescriptor; 21 22 33 public final class LegacyActionSetExpression extends WorkbenchWindowExpression { 34 35 38 private static final int HASH_INITIAL = LegacyActionSetExpression.class 39 .getName().hashCode(); 40 41 46 private final String actionSetId; 47 48 60 public LegacyActionSetExpression(final String actionSetId, 61 final IWorkbenchWindow window) { 62 super(window); 63 if (actionSetId == null) { 64 throw new NullPointerException ( 65 "The action set identifier cannot be null"); } 67 this.actionSetId = actionSetId; 68 } 69 70 public final void collectExpressionInfo(final ExpressionInfo info) { 71 super.collectExpressionInfo(info); 72 info.addVariableNameAccess(ISources.ACTIVE_ACTION_SETS_NAME); 73 } 74 75 protected final int computeHhashCode() { 76 int hashCode = HASH_INITIAL * HASH_FACTOR + hashCode(getWindow()); 77 hashCode = hashCode * HASH_FACTOR + hashCode(actionSetId); 78 return hashCode; 79 } 80 81 public final boolean equals(final Object object) { 82 if (object instanceof LegacyActionSetExpression) { 83 final LegacyActionSetExpression that = (LegacyActionSetExpression) object; 84 return equals(this.actionSetId, that.actionSetId) 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 100 .getVariable(ISources.ACTIVE_ACTION_SETS_NAME); 101 if (variable instanceof IActionSetDescriptor[]) { 102 final IActionSetDescriptor[] descriptors = (IActionSetDescriptor[]) variable; 103 for (int i = 0; i < descriptors.length; i++) { 104 final IActionSetDescriptor descriptor = descriptors[i]; 105 final String currentId = descriptor.getId(); 106 if (actionSetId.equals(currentId)) { 107 return EvaluationResult.TRUE; 108 } 109 } 110 } 111 112 return EvaluationResult.FALSE; 113 } 114 115 public final String toString() { 116 final StringBuffer buffer = new StringBuffer (); 117 buffer.append("ActionSetExpression("); buffer.append(actionSetId); 119 buffer.append(','); 120 buffer.append(getWindow()); 121 buffer.append(')'); 122 return buffer.toString(); 123 } 124 } 125 | Popular Tags |