001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.form.palette;
043:
044: import java.util.ArrayList;
045: import java.util.List;
046: import javax.swing.event.ChangeListener;
047:
048: import org.openide.*;
049:
050: import org.netbeans.modules.form.project.ClassSource;
051:
052: /**
053: * A wizard allowing the user to add components to palette from a JAR file,
054: * library, or a project. This class manages the whole wizard depending on the
055: * type of source the user wants to choose from. There are three steps in the
056: * wizard - selecting source, selecting components, and selecting palette
057: * category.
058: *
059: * @author Tomas Pavek
060: */
061:
062: class AddToPaletteWizard extends WizardDescriptor {
063:
064: ATPWizardIterator wizardIterator;
065:
066: private List<? extends ClassSource.Entry> selectedFiles;
067: private BeanInstaller.ItemInfo[] selectedBeans;
068: private String selectedCategory;
069: private Class<? extends ClassSource.Entry> sourceType;
070:
071: private java.awt.Dialog dialog;
072:
073: // ---------
074:
075: public AddToPaletteWizard() {
076: this (new ATPWizardIterator());
077: }
078:
079: private AddToPaletteWizard(ATPWizardIterator iterator) {
080: wizardIterator = iterator;
081:
082: putProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
083: putProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
084: putProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
085:
086: setTitle(PaletteUtils
087: .getBundleString("CTL_AddToPaletteWizard_Title")); // NOI18N
088: setTitleFormat(new java.text.MessageFormat("{0}")); // NOI18N
089: }
090:
091: public boolean show(Class<? extends ClassSource.Entry> sourceType) {
092: String firstStep_key;
093: this .sourceType = sourceType;
094: if (sourceType == ClassSource.JarEntry.class)
095: firstStep_key = "CTL_SelectJAR_Step"; // NOI18N
096: else if (sourceType == ClassSource.LibraryEntry.class)
097: firstStep_key = "CTL_SelectLibrary_Step"; // NOI18N
098: else if (sourceType == ClassSource.ProjectEntry.class)
099: firstStep_key = "CTL_SelectProject_Step"; // NOI18N
100: else
101: throw new IllegalArgumentException();
102:
103: putProperty(
104: "WizardPanel_contentData", // NOI18N
105: new String[] {
106: PaletteUtils.getBundleString(firstStep_key),
107: PaletteUtils
108: .getBundleString("CTL_SelectBeans_Step"), // NOI18N
109: PaletteUtils
110: .getBundleString("CTL_SelectCategory_Step") }); // NOI18N
111:
112: wizardIterator.setSourceType(sourceType);
113: setPanelsAndSettings(wizardIterator, this );
114: updateState();
115:
116: if (dialog == null)
117: dialog = DialogDisplayer.getDefault().createDialog(this );
118: dialog.setVisible(true);
119: dialog.dispose();
120:
121: return getValue() == FINISH_OPTION;
122: }
123:
124: // -------
125:
126: void stepToNext() {
127: if (wizardIterator.hasNext()) {
128: wizardIterator.nextPanel();
129: updateState();
130: }
131: }
132:
133: void setJARFiles(List<? extends ClassSource.Entry> files) {
134: selectedFiles = files;
135: }
136:
137: /** @return the JAR files representing the selected source in the first
138: * step of the wizard (i.e. a JAR file directly, library, or project) */
139: List<? extends ClassSource.Entry> getJARFiles() {
140: return selectedFiles;
141: }
142:
143: void setSelectedBeans(BeanInstaller.ItemInfo[] beans) {
144: selectedBeans = beans;
145: }
146:
147: BeanInstaller.ItemInfo[] getSelectedBeans() {
148: return selectedBeans;
149: }
150:
151: void setSelectedCategory(String name) {
152: selectedCategory = name;
153: }
154:
155: String getSelectedCategory() {
156: return selectedCategory;
157: }
158:
159: Class<? extends ClassSource.Entry> getSourceType() {
160: return sourceType;
161: }
162:
163: // -------
164:
165: /** Wizard iterator implementation for Add to Palette wizard */
166: static class ATPWizardIterator implements
167: WizardDescriptor.Iterator<AddToPaletteWizard> {
168:
169: List<WizardDescriptor.Panel<AddToPaletteWizard>> panels = new ArrayList<WizardDescriptor.Panel<AddToPaletteWizard>>();
170: int stage;
171:
172: void setSourceType(Class<? extends ClassSource.Entry> sourceType) {
173: panels.clear();
174: if (sourceType == ClassSource.JarEntry.class)
175: panels.add(new ChooseJARWizardPanel());
176: else if (sourceType == ClassSource.LibraryEntry.class)
177: panels.add(new ChooseLibraryWizardPanel());
178: else if (sourceType == ClassSource.ProjectEntry.class)
179: panels.add(new ChooseProjectWizardPanel());
180: else
181: throw new IllegalArgumentException();
182:
183: panels.add(new ChooseBeansWizardPanel());
184: panels.add(new ChooseCategoryWizardPanel());
185:
186: stage = 1;
187: }
188:
189: static int getPanelsCount() {
190: return 3;
191: }
192:
193: // ------
194: // WizardDescriptor.Iterator implementation
195:
196: public WizardDescriptor.Panel<AddToPaletteWizard> current() {
197: return panels.get(stage - 1);
198: }
199:
200: public boolean hasNext() {
201: return stage < getPanelsCount();
202: }
203:
204: public boolean hasPrevious() {
205: return stage > 1;
206: }
207:
208: public java.lang.String name() {
209: return ""; // NOI18N
210: }
211:
212: public void nextPanel() {
213: if (stage < getPanelsCount())
214: stage++;
215: }
216:
217: public void previousPanel() {
218: if (stage > 1)
219: stage--;
220: }
221:
222: public void addChangeListener(ChangeListener listener) {
223: }
224:
225: public void removeChangeListener(ChangeListener listener) {
226: }
227: }
228: }
|