KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > 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.core.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 import org.netbeans.modules.websvc.core.CreatorProvider;
34 import org.netbeans.modules.websvc.core.ServiceCreator;
35
36 import org.openide.WizardDescriptor;
37
38 import org.netbeans.modules.j2ee.common.Util;
39 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates;
40 import org.netbeans.spi.project.ui.templates.support.Templates;
41 import org.openide.filesystems.FileObject;
42 import org.openide.loaders.DataObject;
43 import org.openide.loaders.TemplateWizard;
44 import org.openide.util.NbBundle;
45
46 /**
47  * Wizard to create a new Web project.
48  * @author Jesse Glick, Radko Najman
49  */

50 public class NewWebServiceFromWSDLWizardIterator implements TemplateWizard.Iterator {
51     
52     private Project project;
53
54     /** Create a new wizard iterator. */
55     public NewWebServiceFromWSDLWizardIterator() {
56     }
57         
58     public static NewWebServiceFromWSDLWizardIterator create() {
59         return new NewWebServiceFromWSDLWizardIterator();
60     }
61
62     public Set JavaDoc instantiate(TemplateWizard wiz) throws IOException JavaDoc {
63         FileObject template = Templates.getTemplate( wiz );
64         DataObject dTemplate = DataObject.find( template );
65         
66         //new WebServiceCreator(project, wiz).createFromWSDL();
67
ServiceCreator creator = CreatorProvider.getServiceCreator(project, wiz);
68         if (creator!=null) {
69             creator.createServiceFromWsdl();
70         }
71         return Collections.singleton(dTemplate);
72     }
73     
74     private transient int index;
75     private transient WizardDescriptor.Panel[] panels;
76     private transient TemplateWizard wiz;
77     private transient WizardDescriptor.Panel bottomPanel;
78
79     public void initialize(TemplateWizard wiz) {
80         this.wiz = wiz;
81         index = 0;
82
83         project = Templates.getProject(wiz);
84
85         SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project);
86         bottomPanel = new WebServiceFromWSDL(wiz, project);
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(NewWebServiceFromWSDLWizardIterator.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_Webservice_Name") );
95         Util.hideLabelAndLabelFor(comp, NbBundle.getMessage(NewWebServiceFromWSDLWizardIterator.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label"));
96         
97         panels = new WizardDescriptor.Panel[] {
98             firstPanel,
99         };
100         
101         // Creating steps.
102
Object JavaDoc prop = this.wiz.getProperty("WizardPanel_contentData"); // NOI18N
103
String JavaDoc[] beforeSteps = null;
104         if (prop != null && prop instanceof String JavaDoc[]) {
105             beforeSteps = (String JavaDoc[]) prop;
106         }
107         String JavaDoc[] steps = createSteps(beforeSteps, panels);
108         
109         // Make sure list of steps is accurate.
110
for (int i = 0; i < panels.length; i++) {
111             Component JavaDoc c = panels[i].getComponent();
112             if (c instanceof JComponent JavaDoc) { // assume Swing components
113
JComponent JavaDoc jc = (JComponent JavaDoc) c;
114                 // Step #.
115
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i)); // NOI18N
116
// Step name (actually the whole list for reference).
117
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
118
}
119         }
120     }
121     
122     public void uninitialize(TemplateWizard wiz) {
123         if (this.wiz != null) {
124             this.wiz.putProperty(WizardProperties.WEB_SERVICE_TYPE, null);
125         }
126         panels = null;
127     }
128     
129     private String JavaDoc[] createSteps(String JavaDoc[] before, WizardDescriptor.Panel[] panels) {
130         int diff = 0;
131         if (before == null) {
132             before = new String JavaDoc[0];
133         } else if (before.length > 0) {
134             diff = ("...".equals (before[before.length - 1])) ? 1 : 0; // NOI18N
135
}
136         String JavaDoc[] res = new String JavaDoc[ (before.length - diff) + panels.length];
137         for (int i = 0; i < res.length; i++) {
138             if (i < (before.length - diff)) {
139                 res[i] = before[i];
140             } else {
141                 res[i] = panels[i - before.length + diff].getComponent ().getName ();
142             }
143         }
144         return res;
145     }
146
147     public String JavaDoc name() {
148         return MessageFormat.format(NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_WizardStepsCount"), (new Integer JavaDoc(index + 1)).toString(), (new Integer JavaDoc(panels.length)).toString()); //NOI18N
149
}
150     
151     public boolean hasNext() {
152         return index < panels.length - 1;
153     }
154     
155     public boolean hasPrevious() {
156         return index > 0;
157     }
158     
159     public void nextPanel() {
160         if (!hasNext()) throw new NoSuchElementException JavaDoc();
161         index++;
162     }
163     
164     public void previousPanel() {
165         if (!hasPrevious()) throw new NoSuchElementException JavaDoc();
166         index--;
167     }
168     
169     public WizardDescriptor.Panel current() {
170         return panels[index];
171     }
172     
173     // If nothing unusual changes in the middle of the wizard, simply:
174
public final void addChangeListener(ChangeListener JavaDoc l) {}
175     public final void removeChangeListener(ChangeListener JavaDoc l) {}
176
177 }
178
Popular Tags