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.core.runtime.CoreException; 19 import org.eclipse.jface.viewers.ISelection; 20 import org.eclipse.ui.ISources; 21 import org.eclipse.ui.IWorkbenchWindow; 22 import org.eclipse.ui.SelectionEnabler; 23 24 36 public final class LegacySelectionEnablerWrapper extends 37 WorkbenchWindowExpression { 38 39 42 private static final int HASH_INITIAL = LegacySelectionEnablerWrapper.class 43 .getName().hashCode(); 44 45 48 private final SelectionEnabler enabler; 49 50 60 public LegacySelectionEnablerWrapper(final SelectionEnabler enabler, 61 final IWorkbenchWindow window) { 62 super(window); 63 64 if (enabler == null) { 65 throw new NullPointerException ("There is no enabler"); } 67 this.enabler = enabler; 68 } 69 70 public final void collectExpressionInfo(final ExpressionInfo info) { 71 super.collectExpressionInfo(info); 72 info.markDefaultVariableAccessed(); 73 } 74 75 protected final int computeHashCode() { 76 int hashCode = HASH_INITIAL * HASH_FACTOR + hashCode(getWindow()); 77 hashCode = hashCode * HASH_FACTOR + hashCode(enabler); 78 return hashCode; 79 } 80 81 public final boolean equals(final Object object) { 82 if (object instanceof LegacySelectionEnablerWrapper) { 83 final LegacySelectionEnablerWrapper that = (LegacySelectionEnablerWrapper) object; 84 return equals(this.enabler, that.enabler) 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 defaultVariable = context 99 .getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME); 100 if (defaultVariable instanceof ISelection) { 101 final ISelection selection = (ISelection) defaultVariable; 102 if (enabler.isEnabledForSelection(selection)) { 103 return EvaluationResult.TRUE; 104 } 105 } 106 107 return EvaluationResult.FALSE; 108 } 109 110 public final String toString() { 111 final StringBuffer buffer = new StringBuffer (); 112 buffer.append("LegacySelectionEnablerWrapper("); buffer.append(enabler); 114 buffer.append(','); 115 buffer.append(getWindow()); 116 buffer.append(')'); 117 return buffer.toString(); 118 } 119 } 120 | Popular Tags |