1 11 12 package org.eclipse.ui.internal.handlers; 13 14 import java.io.BufferedWriter ; 15 import java.io.IOException ; 16 import java.io.StringWriter ; 17 18 import org.eclipse.core.commands.IHandler; 19 import org.eclipse.core.expressions.Expression; 20 import org.eclipse.core.expressions.IEvaluationContext; 21 import org.eclipse.ui.ISources; 22 import org.eclipse.ui.handlers.IHandlerActivation; 23 import org.eclipse.ui.handlers.IHandlerService; 24 import org.eclipse.ui.internal.services.EvaluationResultCache; 25 26 44 final class HandlerActivation extends EvaluationResultCache implements 45 IHandlerActivation { 46 47 51 private final String commandId; 52 53 57 private final int depth; 58 59 62 private final IHandler handler; 63 64 68 private final IHandlerService handlerService; 69 70 93 HandlerActivation(final String commandId, final IHandler handler, 94 final Expression expression, final int depth, 95 final IHandlerService handlerService) { 96 super(expression); 97 98 if (commandId == null) { 99 throw new NullPointerException ( 100 "The command identifier for a handler activation cannot be null"); } 102 103 if (handlerService == null) { 104 throw new NullPointerException ( 105 "The handler service for an activation cannot be null"); } 107 108 this.commandId = commandId; 109 this.depth = depth; 110 this.handler = handler; 111 this.handlerService = handlerService; 112 } 113 114 public final void clearActive() { 115 clearResult(); 116 } 117 118 125 public final int compareTo(final Object object) { 126 final IHandlerActivation activation = (IHandlerActivation) object; 127 int difference; 128 129 int thisPriority = this.getSourcePriority(); 131 int thatPriority = activation.getSourcePriority(); 132 133 int thisLsb = 0; 135 int thatLsb = 0; 136 137 if (((thisPriority & ISources.ACTIVE_MENU) | (thatPriority & ISources.ACTIVE_MENU)) != 0) { 138 thisLsb = thisPriority & 1; 139 thisPriority = (thisPriority >> 1) & 0x7fffffff; 140 thatLsb = thatPriority & 1; 141 thatPriority = (thatPriority >> 1) & 0x7fffffff; 142 } 143 144 difference = thisPriority - thatPriority; 145 if (difference != 0) { 146 return difference; 147 } 148 149 difference = thisLsb - thatLsb; 152 if (difference != 0) { 153 return difference; 154 } 155 156 final int thisDepth = this.getDepth(); 158 final int thatDepth = activation.getDepth(); 159 difference = thisDepth - thatDepth; 160 return difference; 161 } 162 163 public final String getCommandId() { 164 return commandId; 165 } 166 167 public final int getDepth() { 168 return depth; 169 } 170 171 public final IHandler getHandler() { 172 return handler; 173 } 174 175 public final IHandlerService getHandlerService() { 176 return handlerService; 177 } 178 179 public final boolean isActive(final IEvaluationContext context) { 180 return evaluate(context); 181 } 182 183 public final String toString() { 184 final StringWriter sw = new StringWriter (); 185 final BufferedWriter buffer = new BufferedWriter (sw); 186 187 try { 188 buffer.write("HandlerActivation(commandId="); buffer.write(commandId); 190 buffer.write(','); 191 buffer.newLine(); 192 buffer.write("\thandler="); buffer.write(handler==null?"":handler.toString()); buffer.write(','); 195 buffer.newLine(); 196 buffer.write("\texpression="); Expression exp = getExpression(); 198 buffer.write(exp==null?"":exp.toString()); buffer.write(",sourcePriority="); buffer.write(Integer.toString(getSourcePriority())); 201 buffer.write(')'); 202 buffer.flush(); 203 } catch (IOException e) { 204 } 206 return sw.toString(); 207 } 208 } 209 | Popular Tags |