1 11 12 package org.eclipse.ui; 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.swt.widgets.Shell; 19 20 31 public final class ActiveShellExpression extends Expression { 32 33 36 private static final int HASH_INITIAL = ActiveShellExpression.class 37 .getName().hashCode(); 38 39 42 public static final int SOURCES = ISources.ACTIVE_SHELL 43 | ISources.ACTIVE_WORKBENCH_WINDOW; 44 45 50 private final Shell activeShell; 51 52 59 public ActiveShellExpression(final Shell activeShell) { 60 this.activeShell = activeShell; 61 } 62 63 69 public final void collectExpressionInfo(final ExpressionInfo info) { 70 info.addVariableNameAccess(ISources.ACTIVE_SHELL_NAME); 71 info.addVariableNameAccess(ISources.ACTIVE_WORKBENCH_WINDOW_NAME); 72 } 73 74 protected final int computeHashCode() { 75 return HASH_INITIAL * HASH_FACTOR + hashCode(activeShell); 76 } 77 78 public final boolean equals(final Object object) { 79 if (object instanceof ActiveShellExpression) { 80 final ActiveShellExpression that = (ActiveShellExpression) object; 81 return equals(this.activeShell, that.activeShell); 82 } 83 84 return false; 85 } 86 87 100 public final EvaluationResult evaluate(final IEvaluationContext context) { 101 if (activeShell != null) { 102 Object value = context.getVariable(ISources.ACTIVE_SHELL_NAME); 103 if (!activeShell.equals(value)) { 104 value = context 105 .getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME); 106 if (!activeShell.equals(value)) { 107 return EvaluationResult.FALSE; 108 } 109 } 110 } 111 112 return EvaluationResult.TRUE; 113 } 114 115 public final String toString() { 116 final StringBuffer buffer = new StringBuffer (); 117 buffer.append("ActiveShellExpression("); buffer.append(activeShell); 119 buffer.append(')'); 120 return buffer.toString(); 121 } 122 } 123 | Popular Tags |