1 11 package org.eclipse.ui.internal.menus; 12 13 import org.eclipse.core.commands.Command; 14 import org.eclipse.core.commands.ParameterizedCommand; 15 import org.eclipse.core.commands.common.NotDefinedException; 16 import org.eclipse.jface.util.PropertyChangeEvent; 17 import org.eclipse.jface.util.Util; 18 19 40 public final class SItem extends MenuElement { 41 42 46 public static final String PROPERTY_COMMAND = "COMMAND"; 48 52 public static final String PROPERTY_MENU_ID = "MENU_ID"; 54 58 private ParameterizedCommand command; 59 60 65 private String menuId; 66 67 74 SItem(final String id) { 75 super(id); 76 } 77 78 91 public final void define(final Command command, final SLocation location) { 92 final ParameterizedCommand parameterizedCommand = new ParameterizedCommand( 93 command, null); 94 define(parameterizedCommand, null, location); 95 } 96 97 111 public final void define(final ParameterizedCommand command, 112 final SLocation location) { 113 define(command, null, location); 114 } 115 116 133 public final void define(final ParameterizedCommand command, 134 final String menuId, final SLocation location) { 135 final SLocation[] locations; 136 if (location == null) { 137 locations = null; 138 } else { 139 locations = new SLocation[] { location }; 140 } 141 define(command, menuId, locations); 142 } 143 144 161 public final void define(final ParameterizedCommand command, 162 final String menuId, final SLocation[] locations) { 163 if (command == null) { 164 throw new NullPointerException ("An item needs a command"); } 166 167 setCommand(command); 168 setMenuId(menuId); 169 setLocations(locations); 170 setDefined(true); 171 } 172 173 180 public final ParameterizedCommand getCommand() throws NotDefinedException { 181 if (!isDefined()) { 182 throw new NotDefinedException( 183 "Cannot get the command from an undefined item"); } 185 186 return command; 187 } 188 189 196 public final String getMenuId() throws NotDefinedException { 197 if (!isDefined()) { 198 throw new NotDefinedException( 199 "Cannot get the menu from an undefined item"); } 201 202 return menuId; 203 } 204 205 212 protected final void setCommand(final ParameterizedCommand command) { 213 if (!Util.equals(this.command, command)) { 214 PropertyChangeEvent event = null; 215 if (isListenerAttached()) { 216 event = new PropertyChangeEvent(this, PROPERTY_COMMAND, 217 this.command, command); 218 } 219 this.command = command; 220 firePropertyChangeEvent(event); 221 } 222 } 223 224 231 protected final void setMenuId(final String menuId) { 232 if (!Util.equals(this.menuId, menuId)) { 233 PropertyChangeEvent event = null; 234 if (isListenerAttached()) { 235 event = new PropertyChangeEvent(this, PROPERTY_MENU_ID, 236 this.menuId, menuId); 237 } 238 this.menuId = menuId; 239 firePropertyChangeEvent(event); 240 } 241 } 242 243 249 public final String toString() { 250 if (string == null) { 251 final StringBuffer stringBuffer = new StringBuffer (); 252 stringBuffer.append("SItem("); stringBuffer.append(id); 254 stringBuffer.append(','); 255 stringBuffer.append(command); 256 stringBuffer.append(','); 257 stringBuffer.append(menuId); 258 stringBuffer.append(','); 259 stringBuffer.append(locations); 260 stringBuffer.append(','); 261 stringBuffer.append(defined); 262 stringBuffer.append(')'); 263 string = stringBuffer.toString(); 264 } 265 return string; 266 } 267 268 273 public final void undefine() { 274 string = null; 275 276 setCommand(null); 277 setMenuId(null); 278 setLocations(null); 279 setDefined(false); 280 } 281 282 } 283 | Popular Tags |