1 11 package org.eclipse.core.commands; 12 13 21 public final class CommandManagerEvent { 22 23 29 private static final int CHANGED_CATEGORY_DEFINED = 1; 30 31 37 private static final int CHANGED_COMMAND_DEFINED = 1 << 1; 38 39 48 private static final int CHANGED_PARAMETER_TYPE_DEFINED = 1 << 2; 49 50 55 private final String categoryId; 56 57 62 private final int changedValues; 63 64 69 private final String commandId; 70 71 79 private final String parameterTypeId; 80 81 84 private final CommandManager commandManager; 85 86 110 public CommandManagerEvent(final CommandManager commandManager, 111 final String commandId, final boolean commandIdAdded, 112 final boolean commandIdChanged, final String categoryId, 113 final boolean categoryIdAdded, final boolean categoryIdChanged) { 114 if (commandManager == null) { 115 throw new NullPointerException ( 116 "An event must refer to its command manager"); } 118 119 if (commandIdChanged && (commandId == null)) { 120 throw new NullPointerException ( 121 "If the list of defined commands changed, then the added/removed command must be mentioned"); } 123 124 if (categoryIdChanged && (categoryId == null)) { 125 throw new NullPointerException ( 126 "If the list of defined categories changed, then the added/removed category must be mentioned"); } 128 129 this.commandManager = commandManager; 130 this.commandId = commandId; 131 this.categoryId = categoryId; 132 133 this.parameterTypeId = null; 135 136 int changedValues = 0; 137 if (categoryIdChanged && categoryIdAdded) { 138 changedValues |= CHANGED_CATEGORY_DEFINED; 139 } 140 if (commandIdChanged && commandIdAdded) { 141 changedValues |= CHANGED_COMMAND_DEFINED; 142 } 143 this.changedValues = changedValues; 144 } 145 146 166 public CommandManagerEvent(final CommandManager commandManager, 167 final String parameterTypeId, final boolean parameterTypeIdAdded, 168 final boolean parameterTypeIdChanged) { 169 170 if (commandManager == null) { 171 throw new NullPointerException ( 172 "An event must refer to its command manager"); } 174 175 if (parameterTypeIdChanged && (parameterTypeId == null)) { 176 throw new NullPointerException ( 177 "If the list of defined command parameter types changed, then the added/removed parameter type must be mentioned"); } 179 180 this.commandManager = commandManager; 181 this.commandId = null; 182 this.categoryId = null; 183 184 this.parameterTypeId = parameterTypeId; 185 186 int changedValues = 0; 187 if (parameterTypeIdChanged && parameterTypeIdAdded) { 188 changedValues |= CHANGED_PARAMETER_TYPE_DEFINED; 189 } 190 191 this.changedValues = changedValues; 192 } 193 194 200 public final String getCategoryId() { 201 return categoryId; 202 } 203 204 210 public final String getCommandId() { 211 return commandId; 212 } 213 214 220 public final CommandManager getCommandManager() { 221 return commandManager; 222 } 223 224 232 public final String getParameterTypeId() { 233 return parameterTypeId; 234 } 235 236 242 public final boolean isCategoryChanged() { 243 return (categoryId != null); 244 } 245 246 253 public final boolean isCategoryDefined() { 254 return (((changedValues & CHANGED_CATEGORY_DEFINED) != 0) && (categoryId != null)); 255 } 256 257 263 public final boolean isCommandChanged() { 264 return (commandId != null); 265 } 266 267 274 public final boolean isCommandDefined() { 275 return (((changedValues & CHANGED_COMMAND_DEFINED) != 0) && (commandId != null)); 276 } 277 278 287 public final boolean isParameterTypeChanged() { 288 return (parameterTypeId != null); 289 } 290 291 301 public final boolean isParameterTypeDefined() { 302 return (((changedValues & CHANGED_PARAMETER_TYPE_DEFINED) != 0) && (parameterTypeId != null)); 303 } 304 } 305 | Popular Tags |