KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > palette > AddToPaletteWizard


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.form.palette;
21
22 import java.io.File JavaDoc;
23 import java.util.Map JavaDoc;
24 import javax.swing.event.ChangeListener JavaDoc;
25
26 import org.openide.*;
27
28 import org.netbeans.modules.form.project.ClassSource;
29
30 /**
31  * A wizard allowing the user to add components to palette from a JAR file,
32  * library, or a project. This class manages the whole wizard depending on the
33  * type of source the user wants to choose from. There are three steps in the
34  * wizard - selecting source, selecting components, and selecting palette
35  * category.
36  *
37  * @author Tomas Pavek
38  */

39
40 class AddToPaletteWizard extends WizardDescriptor {
41
42     ATPWizardIterator wizardIterator;
43
44     private File JavaDoc[] selectedFiles;
45     private BeanInstaller.ItemInfo[] selectedBeans;
46     private String JavaDoc selectedCategory;
47     private String JavaDoc sourceType;
48
49     Map JavaDoc libraryNameMap; // map from root file (JAR) names to libraries they belong to
50
// created by ChooseLibraryWizardPanel.storeSettings
51

52     private java.awt.Dialog JavaDoc dialog;
53
54     // ---------
55

56     public AddToPaletteWizard() {
57         this(new ATPWizardIterator());
58     }
59
60     private AddToPaletteWizard(ATPWizardIterator iterator) {
61         super(iterator);
62         wizardIterator = iterator;
63
64         putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
65
putProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
66
putProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
67

68         setTitle(PaletteUtils.getBundleString("CTL_AddToPaletteWizard_Title")); // NOI18N
69
setTitleFormat(new java.text.MessageFormat JavaDoc("{0}")); // NOI18N
70
}
71
72     public boolean show(String JavaDoc sourceType) {
73         String JavaDoc firstStep_key;
74         this.sourceType = sourceType;
75         if (ClassSource.JAR_SOURCE.equals(sourceType))
76             firstStep_key = "CTL_SelectJAR_Step"; // NOI18N
77
else if (ClassSource.LIBRARY_SOURCE.equals(sourceType))
78             firstStep_key = "CTL_SelectLibrary_Step"; // NOI18N
79
else if (ClassSource.PROJECT_SOURCE.equals(sourceType))
80             firstStep_key = "CTL_SelectProject_Step"; // NOI18N
81
else
82             throw new IllegalArgumentException JavaDoc();
83
84         putProperty("WizardPanel_contentData", // NOI18N
85
new String JavaDoc[] { PaletteUtils.getBundleString(firstStep_key),
86                                    PaletteUtils.getBundleString("CTL_SelectBeans_Step"), // NOI18N
87
PaletteUtils.getBundleString("CTL_SelectCategory_Step") }); // NOI18N
88

89         libraryNameMap = null;
90         wizardIterator.setSourceType(sourceType);
91         updateState();
92
93         if (dialog == null)
94             dialog = DialogDisplayer.getDefault().createDialog(this);
95         dialog.setVisible(true);
96         dialog.dispose();
97
98         return getValue() == FINISH_OPTION;
99     }
100
101     // -------
102

103     void stepToNext() {
104         if (wizardIterator.hasNext()) {
105             wizardIterator.nextPanel();
106             updateState();
107         }
108     }
109
110     void setJARFiles(File JavaDoc[] files) {
111         selectedFiles = files;
112     }
113
114     /** @return the JAR files representing the selected source in the first
115      * step of the wizard (i.e. a JAR file directly, library, or project) */

116     File JavaDoc[] getJARFiles() {
117         return selectedFiles;
118     }
119
120     void setSelectedBeans(BeanInstaller.ItemInfo[] beans) {
121         selectedBeans = beans;
122     }
123
124     BeanInstaller.ItemInfo[] getSelectedBeans() {
125         return selectedBeans;
126     }
127
128     void setSelectedCategory(String JavaDoc name) {
129         selectedCategory = name;
130     }
131
132     String JavaDoc getSelectedCategory() {
133         return selectedCategory;
134     }
135     
136     String JavaDoc getSourceType() {
137         return sourceType;
138     }
139
140     // -------
141

142     /** Wizard iterator implementation for Add to Palette wizard */
143     static class ATPWizardIterator implements WizardDescriptor.Iterator {
144
145         WizardDescriptor.Panel[] panels = new WizardDescriptor.Panel[getPanelsCount()];
146         int stage;
147
148         void setSourceType(String JavaDoc sourceType) {
149             if (ClassSource.JAR_SOURCE.equals(sourceType))
150                 panels[0] = new ChooseJARWizardPanel();
151             else if (ClassSource.LIBRARY_SOURCE.equals(sourceType))
152                 panels[0] = new ChooseLibraryWizardPanel();
153             else if (ClassSource.PROJECT_SOURCE.equals(sourceType))
154                 panels[0] = new ChooseProjectWizardPanel();
155             else
156                 throw new IllegalArgumentException JavaDoc();
157
158             panels[1] = new ChooseBeansWizardPanel();
159             panels[2] = new ChooseCategoryWizardPanel();
160
161             stage = 1;
162         }
163
164         static int getPanelsCount() {
165             return 3;
166         }
167
168         // ------
169
// WizardDescriptor.Iterator implementation
170

171         public WizardDescriptor.Panel current() {
172             return panels[stage-1];
173         }
174
175         public boolean hasNext() {
176             return stage < getPanelsCount();
177         }
178
179         public boolean hasPrevious() {
180             return stage > 1;
181         }
182
183         public java.lang.String JavaDoc name() {
184             return ""; // NOI18N
185
}
186
187         public void nextPanel() {
188             if (stage < getPanelsCount())
189                 stage++;
190         }
191
192         public void previousPanel() {
193             if (stage > 1)
194                 stage--;
195         }
196
197         public void addChangeListener(ChangeListener JavaDoc listener) {
198         }
199
200         public void removeChangeListener(ChangeListener JavaDoc listener) {
201         }
202     }
203 }
204
Popular Tags