KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > dev > wizard > NewWebServiceWizardIterator


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.websvc.dev.wizard;
21
22 import java.awt.Component JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.NoSuchElementException JavaDoc;
27 import java.util.Set JavaDoc;
28
29 import javax.swing.JComponent JavaDoc;
30 import javax.swing.event.ChangeListener JavaDoc;
31 import org.netbeans.api.project.Project;
32 import org.netbeans.api.project.SourceGroup;
33
34 import org.openide.WizardDescriptor;
35
36 import org.netbeans.modules.j2ee.common.Util;
37 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates;
38 import org.netbeans.spi.project.ui.templates.support.Templates;
39 import org.openide.filesystems.FileObject;
40 import org.openide.loaders.DataObject;
41 import org.openide.loaders.TemplateWizard;
42 import org.openide.util.NbBundle;
43
44 /**
45  * Wizard to create a new Web project.
46  * @author Jesse Glick, Radko Najman
47  */

48 public class NewWebServiceWizardIterator implements TemplateWizard.Iterator /*, ItemListener*/ {
49     
50     private Project project;
51
52     /** Create a new wizard iterator. */
53     public NewWebServiceWizardIterator() {
54     }
55         
56     public static NewWebServiceWizardIterator create() {
57         return new NewWebServiceWizardIterator();
58     }
59
60     public Set JavaDoc instantiate(TemplateWizard wiz) throws IOException JavaDoc {
61         FileObject template = Templates.getTemplate( wiz );
62         DataObject dTemplate = DataObject.find( template );
63         
64         new WebServiceCreator(project, wiz).create();
65                 
66         return Collections.singleton(dTemplate);
67     }
68     
69     private transient int index;
70     private transient WizardDescriptor.Panel[] panels;
71     private transient TemplateWizard wiz;
72     private transient WizardDescriptor.Panel bottomPanel;
73
74 //convert Java class not implemented for 5.5 release
75
// private int serviceType = WizardProperties.FROM_SCRATCH;
76

77     public void initialize(TemplateWizard wiz) {
78         this.wiz = wiz;
79         index = 0;
80
81         project = Templates.getProject(wiz);
82
83         SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project);
84         bottomPanel = new WebServiceType(project, wiz);
85 //convert Java class not implemented for 5.5 release
86
// ((WebServiceTypePanel) bottomPanel.getComponent()).addItemListener(this);
87
WizardDescriptor.Panel firstPanel; //special case: use Java Chooser
88
if (sourceGroups.length == 0)
89             firstPanel = new FinishableProxyWizardPanel(Templates.createSimpleTargetChooser(project, sourceGroups, bottomPanel));
90         else
91             firstPanel = new FinishableProxyWizardPanel(JavaTemplates.createPackageChooser(project, sourceGroups, bottomPanel, true));
92
93         JComponent JavaDoc comp = (JComponent JavaDoc) firstPanel.getComponent();
94         Util.changeLabelInComponent(comp, NbBundle.getMessage(Util.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_Webservice_Name") );
95         Util.hideLabelAndLabelFor(comp, NbBundle.getMessage(Util.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label"));
96         
97         panels = new WizardDescriptor.Panel[] {
98             firstPanel,
99 //convert Java class not implemented for 5.5 release
100
// new WebServiceMethodChooser()
101
};
102         
103         // Creating steps.
104
Object JavaDoc prop = this.wiz.getProperty("WizardPanel_contentData"); // NOI18N
105
String JavaDoc[] beforeSteps = null;
106         if (prop != null && prop instanceof String JavaDoc[]) {
107             beforeSteps = (String JavaDoc[]) prop;
108         }
109         String JavaDoc[] steps = createSteps(beforeSteps, panels);
110         
111         // Make sure list of steps is accurate.
112
for (int i = 0; i < panels.length; i++) {
113             Component JavaDoc c = panels[i].getComponent();
114             if (c instanceof JComponent JavaDoc) { // assume Swing components
115
JComponent JavaDoc jc = (JComponent JavaDoc) c;
116                 // Step #.
117
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i)); // NOI18N
118
// Step name (actually the whole list for reference).
119
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
120
}
121         }
122     }
123     
124     public void uninitialize(TemplateWizard wiz) {
125         if (this.wiz != null) {
126             this.wiz.putProperty(WizardProperties.WEB_SERVICE_TYPE, null);
127         }
128 //convert Java class not implemented for 5.5 release
129
// ((WebServiceTypePanel) bottomPanel.getComponent()).removeItemListener(this);
130
panels = null;
131     }
132     
133     private String JavaDoc[] createSteps(String JavaDoc[] before, WizardDescriptor.Panel[] panels) {
134         int diff = 0;
135         if (before == null) {
136             before = new String JavaDoc[0];
137         } else if (before.length > 0) {
138             diff = ("...".equals (before[before.length - 1])) ? 1 : 0; // NOI18N
139
}
140         String JavaDoc[] res = new String JavaDoc[ (before.length - diff) + panels.length];
141         for (int i = 0; i < res.length; i++) {
142             if (i < (before.length - diff)) {
143                 res[i] = before[i];
144             } else {
145                 res[i] = panels[i - before.length + diff].getComponent ().getName ();
146             }
147         }
148         return res;
149     }
150
151     public String JavaDoc name() {
152         return MessageFormat.format(NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_WizardStepsCount"), new String JavaDoc[] {(new Integer JavaDoc(index + 1)).toString(), (new Integer JavaDoc(panels.length)).toString()}); //NOI18N
153
}
154     
155     public boolean hasNext() {
156 //convert Java class not implemented for 5.5 release
157
// if (index == 0 && serviceType != WizardProperties.CONVERT_JAVA_CLASS)
158
// return false;
159
// else
160
return index < panels.length - 1;
161     }
162     
163     public boolean hasPrevious() {
164         return index > 0;
165     }
166     
167     public void nextPanel() {
168         if (!hasNext()) throw new NoSuchElementException JavaDoc();
169         index++;
170     }
171     
172     public void previousPanel() {
173         if (!hasPrevious()) throw new NoSuchElementException JavaDoc();
174         index--;
175     }
176     
177     public WizardDescriptor.Panel current() {
178         return panels[index];
179     }
180     
181     // If nothing unusual changes in the middle of the wizard, simply:
182
public final void addChangeListener(ChangeListener JavaDoc l) {}
183     public final void removeChangeListener(ChangeListener JavaDoc l) {}
184
185 //convert Java class not implemented for 5.5 release
186
// public void itemStateChanged(ItemEvent e) {
187
// serviceType = ((WebServiceTypePanel) bottomPanel.getComponent()).getServiceType();
188
// //refresh wizard buttons
189
// wiz.setTitleFormat(wiz.getTitleFormat());
190
// }
191

192 }
193
Popular Tags