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 28 public final class LegacyHandlerSubmissionExpression extends Expression { 29 30 33 private static final int HASH_INITIAL = LegacyHandlerSubmissionExpression.class 34 .getName().hashCode(); 35 36 41 private final String activePartId; 42 43 48 private final Shell activeShell; 49 50 55 private final IWorkbenchPartSite activeSite; 56 57 71 public LegacyHandlerSubmissionExpression(final String activePartId, 72 final Shell activeShell, final IWorkbenchPartSite activeSite) { 73 74 this.activePartId = activePartId; 75 this.activeShell = activeShell; 76 this.activeSite = activeSite; 77 } 78 79 86 public final void collectExpressionInfo(final ExpressionInfo info) { 87 if (activePartId != null) { 88 info.addVariableNameAccess(ISources.ACTIVE_PART_ID_NAME); 89 } 90 if (activeShell != null) { 91 info.addVariableNameAccess(ISources.ACTIVE_SHELL_NAME); 92 info 93 .addVariableNameAccess(ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME); 94 } 95 if (activeSite != null) { 96 info.addVariableNameAccess(ISources.ACTIVE_SITE_NAME); 97 } 98 } 99 100 protected final int computeHashCode() { 101 int hashCode = HASH_INITIAL * HASH_FACTOR + hashCode(activePartId); 102 hashCode = hashCode * HASH_FACTOR + hashCode(activeShell); 103 hashCode = hashCode * HASH_FACTOR + hashCode(activeSite); 104 return hashCode; 105 } 106 107 public final boolean equals(final Object object) { 108 if (object instanceof LegacyHandlerSubmissionExpression) { 109 final LegacyHandlerSubmissionExpression that = (LegacyHandlerSubmissionExpression) object; 110 return equals(this.activePartId, that.activePartId) 111 && equals(this.activeShell, that.activeShell) 112 && equals(this.activeSite, that.activeSite); 113 } 114 115 return false; 116 } 117 118 130 public final EvaluationResult evaluate(final IEvaluationContext context) { 131 if (activePartId != null) { 132 final Object value = context 133 .getVariable(ISources.ACTIVE_PART_ID_NAME); 134 if (!activePartId.equals(value)) { 135 return EvaluationResult.FALSE; 136 } 137 } 138 139 if (activeShell != null) { 140 Object value = context.getVariable(ISources.ACTIVE_SHELL_NAME); 141 if (!activeShell.equals(value)) { 142 value = context 143 .getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME); 144 if (!activeShell.equals(value)) { 145 return EvaluationResult.FALSE; 146 } 147 } 148 } 149 150 if (activeSite != null) { 151 final Object value = context.getVariable(ISources.ACTIVE_SITE_NAME); 152 if (!activeSite.equals(value)) { 153 return EvaluationResult.FALSE; 154 } 155 } 156 157 return EvaluationResult.TRUE; 158 } 159 160 public final String toString() { 161 final StringBuffer buffer = new StringBuffer (); 162 buffer.append("LegacyHandlerSubmission("); buffer.append(activeShell); 164 buffer.append(','); 165 buffer.append(activePartId); 166 buffer.append(','); 167 buffer.append(activeSite); 168 buffer.append(')'); 169 return buffer.toString(); 170 } 171 } 172 | Popular Tags |