KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > 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.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 NewWebServiceWizardIterator implements TemplateWizard.Iterator /*, ItemListener*/ {
51     
52     private Project project;
53
54     /** Create a new wizard iterator. */
55     public NewWebServiceWizardIterator() {
56     }
57         
58     public static NewWebServiceWizardIterator create() {
59         return new NewWebServiceWizardIterator();
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).create();
67
ServiceCreator creator = CreatorProvider.getServiceCreator(project, wiz);
68         if (creator!=null) {
69             creator.createService();
70         }
71                 
72         return Collections.singleton(dTemplate);
73     }
74     
75     private transient int index;
76     private transient WizardDescriptor.Panel[] panels;
77     private transient TemplateWizard wiz;
78     private transient WizardDescriptor.Panel bottomPanel;
79
80 //convert Java class not implemented for 5.5 release
81
// private int serviceType = WizardProperties.FROM_SCRATCH;
82

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

198 }
199
Popular Tags