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.ui.ISources; 20 import org.eclipse.ui.IWorkbenchWindow; 21 22 30 public class WorkbenchWindowExpression extends Expression { 31 32 35 private static final int HASH_INITIAL = WorkbenchWindowExpression.class 36 .getName().hashCode(); 37 38 43 private final IWorkbenchWindow window; 44 45 53 public WorkbenchWindowExpression(final IWorkbenchWindow window) { 54 this.window = window; 55 } 56 57 public void collectExpressionInfo(final ExpressionInfo info) { 58 if (window != null) { 59 info.addVariableNameAccess(ISources.ACTIVE_WORKBENCH_WINDOW_NAME); 60 } 61 } 62 63 protected int computeHashCode() { 64 return HASH_INITIAL * HASH_FACTOR + hashCode(window); 65 } 66 67 public boolean equals(final Object object) { 68 if (object instanceof WorkbenchWindowExpression) { 69 final WorkbenchWindowExpression that = (WorkbenchWindowExpression) object; 70 return equals(this.window, that.window); 71 } 72 73 return false; 74 } 75 76 public EvaluationResult evaluate(final IEvaluationContext context) 77 throws CoreException { 78 if (window != null) { 79 Object value = context 80 .getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME); 81 if (window.equals(value)) { 82 return EvaluationResult.TRUE; 83 } 84 } 85 86 return EvaluationResult.FALSE; 87 } 88 89 95 protected final IWorkbenchWindow getWindow() { 96 return window; 97 } 98 99 public String toString() { 100 final StringBuffer buffer = new StringBuffer (); 101 buffer.append("WorkbenchWindowExpression("); buffer.append(window); 103 buffer.append(')'); 104 return buffer.toString(); 105 } 106 } 107 | Popular Tags |