KickJava   Java API By Example, From Geeks To Geeks.

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


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 NewWebServiceFromWSDLWizardIterator implements TemplateWizard.Iterator {
49     
50     private Project project;
51
52     /** Create a new wizard iterator. */
53     public NewWebServiceFromWSDLWizardIterator() {
54     }
55         
56     public static NewWebServiceFromWSDLWizardIterator create() {
57         return new NewWebServiceFromWSDLWizardIterator();
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).createFromWSDL();
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     public void initialize(TemplateWizard wiz) {
75         this.wiz = wiz;
76         index = 0;
77
78         project = Templates.getProject(wiz);
79
80         SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project);
81         bottomPanel = new WebServiceFromWSDL(wiz, project);
82         WizardDescriptor.Panel firstPanel; //special case: use Java Chooser
83
if (sourceGroups.length == 0)
84             firstPanel = new FinishableProxyWizardPanel(Templates.createSimpleTargetChooser(project, sourceGroups, bottomPanel));
85         else
86             firstPanel = new FinishableProxyWizardPanel(JavaTemplates.createPackageChooser(project, sourceGroups, bottomPanel, true));
87
88         JComponent JavaDoc comp = (JComponent JavaDoc) firstPanel.getComponent();
89         Util.changeLabelInComponent(comp, NbBundle.getMessage(Util.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_Webservice_Name") );
90         Util.hideLabelAndLabelFor(comp, NbBundle.getMessage(Util.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label"));
91         
92         panels = new WizardDescriptor.Panel[] {
93             firstPanel,
94         };
95         
96         // Creating steps.
97
Object JavaDoc prop = this.wiz.getProperty("WizardPanel_contentData"); // NOI18N
98
String JavaDoc[] beforeSteps = null;
99         if (prop != null && prop instanceof String JavaDoc[]) {
100             beforeSteps = (String JavaDoc[]) prop;
101         }
102         String JavaDoc[] steps = createSteps(beforeSteps, panels);
103         
104         // Make sure list of steps is accurate.
105
for (int i = 0; i < panels.length; i++) {
106             Component JavaDoc c = panels[i].getComponent();
107             if (c instanceof JComponent JavaDoc) { // assume Swing components
108
JComponent JavaDoc jc = (JComponent JavaDoc) c;
109                 // Step #.
110
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i)); // NOI18N
111
// Step name (actually the whole list for reference).
112
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
113
}
114         }
115     }
116     
117     public void uninitialize(TemplateWizard wiz) {
118         if (this.wiz != null) {
119             this.wiz.putProperty(WizardProperties.WEB_SERVICE_TYPE, null);
120         }
121         panels = null;
122     }
123     
124     private String JavaDoc[] createSteps(String JavaDoc[] before, WizardDescriptor.Panel[] panels) {
125         int diff = 0;
126         if (before == null) {
127             before = new String JavaDoc[0];
128         } else if (before.length > 0) {
129             diff = ("...".equals (before[before.length - 1])) ? 1 : 0; // NOI18N
130
}
131         String JavaDoc[] res = new String JavaDoc[ (before.length - diff) + panels.length];
132         for (int i = 0; i < res.length; i++) {
133             if (i < (before.length - diff)) {
134                 res[i] = before[i];
135             } else {
136                 res[i] = panels[i - before.length + diff].getComponent ().getName ();
137             }
138         }
139         return res;
140     }
141
142     public String JavaDoc name() {
143         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
144
}
145     
146     public boolean hasNext() {
147         return index < panels.length - 1;
148     }
149     
150     public boolean hasPrevious() {
151         return index > 0;
152     }
153     
154     public void nextPanel() {
155         if (!hasNext()) throw new NoSuchElementException JavaDoc();
156         index++;
157     }
158     
159     public void previousPanel() {
160         if (!hasPrevious()) throw new NoSuchElementException JavaDoc();
161         index--;
162     }
163     
164     public WizardDescriptor.Panel current() {
165         return panels[index];
166     }
167     
168     // If nothing unusual changes in the middle of the wizard, simply:
169
public final void addChangeListener(ChangeListener JavaDoc l) {}
170     public final void removeChangeListener(ChangeListener JavaDoc l) {}
171
172 }
173
Popular Tags