KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > registry > WizardParameterValues


1 /*******************************************************************************
2  * Copyright (c) 2006 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 package org.eclipse.ui.internal.registry;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.core.commands.IParameterValues;
17 import org.eclipse.ui.PlatformUI;
18 import org.eclipse.ui.wizards.IWizardCategory;
19 import org.eclipse.ui.wizards.IWizardDescriptor;
20 import org.eclipse.ui.wizards.IWizardRegistry;
21
22 /**
23  * Provides the parameter values for a show wizard command.
24  * <p>
25  * This class is only intended to be extended by the three inner classes (<code>Export</code>,
26  * <code>Import</code> and <code>New</code>) defined here.
27  * </p>
28  *
29  * @since 3.2
30  */

31 public abstract class WizardParameterValues implements IParameterValues {
32
33     /**
34      * Provides the parameter values for export wizards.
35      */

36     public static final class Export extends WizardParameterValues {
37         protected IWizardRegistry getWizardRegistry() {
38             return PlatformUI.getWorkbench().getExportWizardRegistry();
39         }
40     }
41
42     /**
43      * Provides the parameter values for import wizards.
44      */

45     public static final class Import extends WizardParameterValues {
46         protected IWizardRegistry getWizardRegistry() {
47             return PlatformUI.getWorkbench().getImportWizardRegistry();
48         }
49     }
50
51     /**
52      * Provides the parameter values for new wizards.
53      */

54     public static final class New extends WizardParameterValues {
55         protected IWizardRegistry getWizardRegistry() {
56             return PlatformUI.getWorkbench().getNewWizardRegistry();
57         }
58     }
59
60     private void addParameterValues(Map JavaDoc values, IWizardCategory wizardCategory) {
61
62         final IWizardDescriptor[] wizardDescriptors = wizardCategory
63                 .getWizards();
64         for (int i = 0; i < wizardDescriptors.length; i++) {
65             final IWizardDescriptor wizardDescriptor = wizardDescriptors[i];
66
67             // Note: using description instead of label for the name
68
// to reduce possibilities of key collision in the map
69
// final String name = wizardDescriptor.getDescription();
70

71             // by request
72
String JavaDoc name = wizardDescriptor.getLabel();
73             final String JavaDoc id = wizardDescriptor.getId();
74             final String JavaDoc value = (String JavaDoc) values.get(name);
75             if (value!=null && !value.equals(id)) {
76                 name = name + " (" + id + ")"; //$NON-NLS-1$//$NON-NLS-2$
77
}
78             values.put(name, id);
79         }
80
81         final IWizardCategory[] childCategories = wizardCategory
82                 .getCategories();
83         for (int i = 0; i < childCategories.length; i++) {
84             final IWizardCategory childCategory = childCategories[i];
85             addParameterValues(values, childCategory);
86         }
87     }
88
89     public Map JavaDoc getParameterValues() {
90         final Map JavaDoc values = new HashMap JavaDoc();
91
92         final IWizardRegistry wizardRegistry = getWizardRegistry();
93         addParameterValues(values, wizardRegistry.getRootCategory());
94
95         return values;
96     }
97
98     /**
99      * Returns the wizard registry for the concrete
100      * <code>WizardParameterValues</code> implementation class.
101      *
102      * @return The wizard registry for the concrete
103      * <code>WizardParameterValues</code> implementation class.
104      */

105     protected abstract IWizardRegistry getWizardRegistry();
106
107 }
108
Popular Tags