01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.quickaccess;
11:
12: import java.util.ArrayList;
13: import java.util.Arrays;
14: import java.util.HashMap;
15: import java.util.List;
16: import java.util.Map;
17:
18: import org.eclipse.jface.resource.ImageDescriptor;
19: import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
20: import org.eclipse.ui.internal.WorkbenchImages;
21: import org.eclipse.ui.internal.WorkbenchPlugin;
22: import org.eclipse.ui.wizards.IWizardCategory;
23: import org.eclipse.ui.wizards.IWizardDescriptor;
24:
25: /**
26: * @since 3.3
27: *
28: */
29: public class WizardProvider extends QuickAccessProvider {
30:
31: private QuickAccessElement[] cachedElements;
32: private Map idToElement = new HashMap();
33:
34: public QuickAccessElement getElementForId(String id) {
35: getElements();
36: return (WizardElement) idToElement.get(id);
37: }
38:
39: public QuickAccessElement[] getElements() {
40: if (cachedElements == null) {
41: IWizardCategory rootCategory = WorkbenchPlugin.getDefault()
42: .getNewWizardRegistry().getRootCategory();
43: List result = new ArrayList();
44: collectWizards(rootCategory, result);
45: IWizardDescriptor[] wizards = (IWizardDescriptor[]) result
46: .toArray(new IWizardDescriptor[result.size()]);
47: cachedElements = new QuickAccessElement[wizards.length];
48: for (int i = 0; i < wizards.length; i++) {
49: WizardElement wizardElement = new WizardElement(
50: wizards[i], this );
51: cachedElements[i] = wizardElement;
52: idToElement.put(wizardElement.getId(), wizardElement);
53: }
54: }
55: return cachedElements;
56: }
57:
58: private void collectWizards(IWizardCategory category, List result) {
59: result.addAll(Arrays.asList(category.getWizards()));
60: IWizardCategory[] childCategories = category.getCategories();
61: for (int i = 0; i < childCategories.length; i++) {
62: collectWizards(childCategories[i], result);
63: }
64: }
65:
66: public String getId() {
67: return "org.eclipse.ui.wizards"; //$NON-NLS-1$
68: }
69:
70: public ImageDescriptor getImageDescriptor() {
71: return WorkbenchImages
72: .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE);
73: }
74:
75: public String getName() {
76: return QuickAccessMessages.QuickAccess_New;
77: }
78: }
|