1 11 package org.eclipse.ui.internal.dialogs; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.core.runtime.IAdaptable; 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IPath; 18 import org.eclipse.core.runtime.Path; 19 import org.eclipse.core.runtime.Platform; 20 import org.eclipse.jface.resource.ImageDescriptor; 21 import org.eclipse.ui.IPluginContribution; 22 import org.eclipse.ui.ISharedImages; 23 import org.eclipse.ui.internal.WorkbenchImages; 24 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 25 import org.eclipse.ui.model.AdaptableList; 26 import org.eclipse.ui.model.IWorkbenchAdapter; 27 import org.eclipse.ui.wizards.IWizardCategory; 28 import org.eclipse.ui.wizards.IWizardDescriptor; 29 30 35 public class WizardCollectionElement extends AdaptableList implements 36 IPluginContribution, IWizardCategory { 37 private String id; 38 39 private String pluginId; 40 41 private String name; 42 43 private WizardCollectionElement parent; 44 45 private AdaptableList wizards = new AdaptableList(); 46 47 private IConfigurationElement configElement; 48 49 57 public WizardCollectionElement(String id, String pluginId, String name, 58 WizardCollectionElement parent) { 59 this.name = name; 60 this.id = id; 61 this.pluginId = pluginId; 62 this.parent = parent; 63 } 64 65 73 public WizardCollectionElement(IConfigurationElement element, WizardCollectionElement parent) { 74 configElement = element; 75 id = configElement.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 76 this.parent = parent; 77 } 78 79 82 public AdaptableList add(IAdaptable a) { 83 if (a instanceof WorkbenchWizardElement) { 84 wizards.add(a); 85 } else { 86 super.add(a); 87 } 88 return this; 89 } 90 91 92 95 public void remove(IAdaptable a) { 96 if (a instanceof WorkbenchWizardElement) { 97 wizards.remove(a); 98 } else { 99 super.remove(a); 100 } 101 } 102 103 112 public WizardCollectionElement findChildCollection(IPath searchPath) { 113 Object [] children = getChildren(null); 114 String searchString = searchPath.segment(0); 115 for (int i = 0; i < children.length; ++i) { 116 WizardCollectionElement currentCategory = (WizardCollectionElement) children[i]; 117 if (currentCategory.getId().equals(searchString)) { 118 if (searchPath.segmentCount() == 1) { 119 return currentCategory; 120 } 121 122 return currentCategory.findChildCollection(searchPath 123 .removeFirstSegments(1)); 124 } 125 } 126 127 return null; 128 } 129 130 139 public WizardCollectionElement findCategory(String id) { 140 Object [] children = getChildren(null); 141 for (int i = 0; i < children.length; ++i) { 142 WizardCollectionElement currentCategory = (WizardCollectionElement) children[i]; 143 if (id.equals(currentCategory.getId())) { 144 return currentCategory; 145 } 146 WizardCollectionElement childCategory = currentCategory.findCategory(id); 147 if (childCategory != null) { 148 return childCategory; 149 } 150 } 151 return null; 152 } 153 154 162 public WorkbenchWizardElement findWizard(String searchId, boolean recursive) { 163 Object [] wizards = getWizards(); 164 for (int i = 0; i < wizards.length; ++i) { 165 WorkbenchWizardElement currentWizard = (WorkbenchWizardElement) wizards[i]; 166 if (currentWizard.getId().equals(searchId)) { 167 return currentWizard; 168 } 169 } 170 if (!recursive) { 171 return null; 172 } 173 for (Iterator iterator = children.iterator(); iterator.hasNext();) { 174 WizardCollectionElement child = (WizardCollectionElement) iterator 175 .next(); 176 WorkbenchWizardElement result = child.findWizard(searchId, true); 177 if (result != null) { 178 return result; 179 } 180 } 181 return null; 182 } 183 184 189 public Object getAdapter(Class adapter) { 190 if (adapter == IWorkbenchAdapter.class) { 191 return this; 192 } 193 return Platform.getAdapterManager().getAdapter(this, adapter); 194 } 195 196 199 public String getId() { 200 return id; 201 } 202 203 206 public String getLabel(Object o) { 207 return configElement != null ? configElement 208 .getAttribute(IWorkbenchRegistryConstants.ATT_NAME) : name; 209 } 210 211 214 public Object getParent(Object o) { 215 return parent; 216 } 217 218 221 public IPath getPath() { 222 if (parent == null) { 223 return new Path(""); } 225 226 return parent.getPath().append(getId()); 227 } 228 229 230 233 public IWizardDescriptor [] getWizards() { 234 return (IWizardDescriptor[]) wizards 235 .getTypedChildren(IWizardDescriptor.class); 236 } 237 238 244 public WorkbenchWizardElement [] getWorkbenchWizardElements() { 245 return (WorkbenchWizardElement[]) wizards 246 .getTypedChildren(WorkbenchWizardElement.class); 247 } 248 249 254 public boolean isEmpty() { 255 return size() == 0 && wizards.size() == 0; 256 } 257 258 261 public String toString() { 262 StringBuffer buf = new StringBuffer ("WizardCollection, "); buf.append(children.size()); 264 buf.append(" children, "); buf.append(wizards.size()); 266 buf.append(" wizards"); return buf.toString(); 268 } 269 270 275 public ImageDescriptor getImageDescriptor(Object object) { 276 return WorkbenchImages.getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER); 277 } 278 279 284 public String getLocalId() { 285 return getId(); 286 } 287 288 293 public String getPluginId() { 294 return configElement != null ? configElement.getNamespace() : pluginId; 295 } 296 297 298 301 public IWizardCategory getParent() { 302 return parent; 303 } 304 305 308 public IWizardCategory[] getCategories() { 309 return (IWizardCategory []) getTypedChildren(IWizardCategory.class); 310 } 311 312 318 public WizardCollectionElement [] getCollectionElements() { 319 return (WizardCollectionElement[]) getTypedChildren(WizardCollectionElement.class); 320 } 321 322 328 public AdaptableList getWizardAdaptableList() { 329 return wizards; 330 } 331 332 335 public String getLabel() { 336 return getLabel(this); 337 } 338 339 345 public IConfigurationElement getConfigurationElement() { 346 return configElement; 347 } 348 349 355 public WizardCollectionElement getParentCollection() { 356 return parent; 357 } 358 359 362 public IWizardDescriptor findWizard(String id) { 363 return findWizard(id, true); 364 } 365 366 369 public IWizardCategory findCategory(IPath path) { 370 return findChildCollection(path); 371 } 372 } 373 | Popular Tags |