1 11 package org.eclipse.ui.internal.menus; 12 13 import org.eclipse.core.commands.common.NotDefinedException; 14 import org.eclipse.jface.util.PropertyChangeEvent; 15 import org.eclipse.jface.util.Util; 16 17 37 public final class SMenu extends MenuContainer { 38 39 43 public static final String PROPERTY_LABEL = "LABEL"; 45 49 private String label; 50 51 58 SMenu(final String id) { 59 super(id); 60 } 61 62 74 public final void define(final String label, SLocation location) { 75 define(label, location, null); 76 } 77 78 94 public final void define(final String label, SLocation location, 95 final IDynamicMenu dynamic) { 96 final SLocation[] locations; 97 if (location == null) { 98 locations = null; 99 } else { 100 locations = new SLocation[] { location }; 101 } 102 define(label, locations, dynamic); 103 } 104 105 121 public final void define(final String label, SLocation[] locations, 122 final IDynamicMenu dynamic) { 123 if ((locations != null) && (locations.length == 0)) { 124 locations = null; 125 } 126 127 setDefined(true); 128 setLocations(locations); 129 setDynamic(dynamic); 130 setLabel(label); 131 } 132 133 141 public final String getLabel() throws NotDefinedException { 142 if (!isDefined()) { 143 throw new NotDefinedException( 144 "Cannot get the label from an undefined menu"); } 146 147 return label; 148 } 149 150 157 protected final void setLabel(final String label) { 158 if (!Util.equals(this.label, label)) { 159 PropertyChangeEvent event = null; 160 if (isListenerAttached()) { 161 event = new PropertyChangeEvent(this, PROPERTY_LABEL, 162 this.label, label); 163 } 164 this.label = label; 165 firePropertyChangeEvent(event); 166 } 167 } 168 169 175 public final String toString() { 176 if (string == null) { 177 final StringBuffer stringBuffer = new StringBuffer (); 178 stringBuffer.append("SMenu("); stringBuffer.append(id); 180 stringBuffer.append(','); 181 stringBuffer.append(label); 182 stringBuffer.append(','); 183 try { 184 stringBuffer.append(dynamic); 185 } catch (final Exception e) { 186 stringBuffer.append(e.getClass().getName()); 188 } 189 stringBuffer.append(','); 190 stringBuffer.append(defined); 191 stringBuffer.append(')'); 192 string = stringBuffer.toString(); 193 } 194 return string; 195 } 196 197 202 public final void undefine() { 203 string = null; 204 205 setLabel(null); 206 setDynamic(null); 207 setLocations(null); 208 setDefined(false); 209 } 210 } 211 | Popular Tags |