1 11 12 package org.eclipse.ui.internal.quickaccess; 13 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.HashMap ; 17 import java.util.List ; 18 import java.util.Map ; 19 20 import org.eclipse.jface.resource.ImageDescriptor; 21 import org.eclipse.ui.internal.IWorkbenchGraphicConstants; 22 import org.eclipse.ui.internal.WorkbenchImages; 23 import org.eclipse.ui.internal.WorkbenchPlugin; 24 import org.eclipse.ui.wizards.IWizardCategory; 25 import org.eclipse.ui.wizards.IWizardDescriptor; 26 27 31 public class WizardProvider extends QuickAccessProvider { 32 33 private QuickAccessElement[] cachedElements; 34 private Map idToElement = new HashMap (); 35 36 public QuickAccessElement getElementForId(String id) { 37 getElements(); 38 return (WizardElement) idToElement.get(id); 39 } 40 41 public QuickAccessElement[] getElements() { 42 if (cachedElements == null) { 43 IWizardCategory rootCategory = WorkbenchPlugin.getDefault() 44 .getNewWizardRegistry().getRootCategory(); 45 List result = new ArrayList (); 46 collectWizards(rootCategory, result); 47 IWizardDescriptor[] wizards = (IWizardDescriptor[]) result 48 .toArray(new IWizardDescriptor[result.size()]); 49 cachedElements = new QuickAccessElement[wizards.length]; 50 for (int i = 0; i < wizards.length; i++) { 51 WizardElement wizardElement = new WizardElement(wizards[i], this); 52 cachedElements[i] = wizardElement; 53 idToElement.put(wizardElement.getId(), wizardElement); 54 } 55 } 56 return cachedElements; 57 } 58 59 private void collectWizards(IWizardCategory category, List result) { 60 result.addAll(Arrays.asList(category.getWizards())); 61 IWizardCategory[] childCategories = category.getCategories(); 62 for (int i = 0; i < childCategories.length; i++) { 63 collectWizards(childCategories[i], result); 64 } 65 } 66 67 public String getId() { 68 return "org.eclipse.ui.wizards"; } 70 71 public ImageDescriptor getImageDescriptor() { 72 return WorkbenchImages 73 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE); 74 } 75 76 public String getName() { 77 return QuickAccessMessages.QuickAccess_New; 78 } 79 } 80 | Popular Tags |