KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > quickaccess > WizardProvider


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.quickaccess;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Arrays JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Map JavaDoc;
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 /**
28  * @since 3.3
29  *
30  */

31 public class WizardProvider extends QuickAccessProvider {
32
33     private QuickAccessElement[] cachedElements;
34     private Map JavaDoc idToElement = new HashMap JavaDoc();
35
36     public QuickAccessElement getElementForId(String JavaDoc 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 JavaDoc result = new ArrayList JavaDoc();
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 JavaDoc 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 JavaDoc getId() {
68         return "org.eclipse.ui.wizards"; //$NON-NLS-1$
69
}
70
71     public ImageDescriptor getImageDescriptor() {
72         return WorkbenchImages
73                 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE);
74     }
75
76     public String JavaDoc getName() {
77         return QuickAccessMessages.QuickAccess_New;
78     }
79 }
80
Popular Tags