1 11 12 package org.eclipse.ui.internal.menus; 13 14 import org.eclipse.core.commands.common.NotDefinedException; 15 import org.eclipse.jface.util.PropertyChangeEvent; 16 import org.eclipse.jface.util.Util; 17 18 38 public final class SGroup extends MenuContainer { 39 40 44 public static final String PROPERTY_SEPARATORS_VISIBLE = "SEPARATORS_VISIBLE"; 46 50 public boolean separatorsVisible = true; 51 52 59 SGroup(final String id) { 60 super(id); 61 } 62 63 77 public final void define(final boolean separatorsVisible, 78 final SLocation location) { 79 define(separatorsVisible, location, null); 80 } 81 82 99 public final void define(final boolean separatorsVisible, 100 final SLocation location, final IDynamicMenu dynamic) { 101 final SLocation[] locations; 102 if (location == null) { 103 locations = null; 104 } else { 105 locations = new SLocation[] { location }; 106 } 107 define(separatorsVisible, locations, dynamic); 108 } 109 110 127 public final void define(final boolean separatorsVisible, 128 SLocation[] locations, final IDynamicMenu dynamic) { 129 if ((locations != null) && (locations.length == 0)) { 130 locations = null; 131 } 132 133 setDefined(true); 134 setDynamic(dynamic); 135 setLocations(locations); 136 setSeparatorsVisible(separatorsVisible); 137 } 138 139 146 protected final void setSeparatorsVisible(final boolean separatorsVisible) { 147 if (this.defined != defined) { 148 PropertyChangeEvent event = null; 149 if (isListenerAttached()) { 150 event = new PropertyChangeEvent(this, 151 PROPERTY_SEPARATORS_VISIBLE, 152 (this.separatorsVisible ? Boolean.TRUE : Boolean.FALSE), 153 (separatorsVisible ? Boolean.TRUE : Boolean.FALSE)); 154 } 155 this.separatorsVisible = separatorsVisible; 156 firePropertyChangeEvent(event); 157 } 158 } 159 160 171 public final void define(final SLocation location) { 172 define(true, location, null); 173 } 174 175 183 public final boolean isSeparatorsVisible() throws NotDefinedException { 184 if (!isDefined()) { 185 throw new NotDefinedException( 186 "Cannot get whether the separators are visible from an undefined group"); } 188 189 return separatorsVisible; 190 } 191 192 198 public final String toString() { 199 if (string == null) { 200 final StringBuffer stringBuffer = new StringBuffer (); 201 stringBuffer.append("SGroup("); stringBuffer.append(id); 203 stringBuffer.append(','); 204 stringBuffer.append(separatorsVisible); 205 stringBuffer.append(','); 206 stringBuffer.append(Util.toString(locations)); 207 stringBuffer.append(','); 208 try { 209 stringBuffer.append(dynamic); 210 } catch (final Exception e) { 211 stringBuffer.append(e.getClass().getName()); 213 } 214 stringBuffer.append(','); 215 stringBuffer.append(defined); 216 stringBuffer.append(')'); 217 string = stringBuffer.toString(); 218 } 219 return string; 220 } 221 222 227 public final void undefine() { 228 string = null; 229 230 setSeparatorsVisible(false); 231 setDynamic(null); 232 setLocations(null); 233 setDefined(false); 234 } 235 } 236 | Popular Tags |