KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 import java.awt.Component JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Vector JavaDoc;
26 import javax.swing.JComboBox JavaDoc;
27 import org.netbeans.api.project.SourceGroup;
28 import org.netbeans.modules.j2ee.common.Util;
29 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
30 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
31 import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants;
32 import org.openide.*;
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.event.ChangeListener JavaDoc;
35 import org.openide.util.HelpCtx;
36 import org.netbeans.api.project.Project;
37 import org.netbeans.spi.project.ui.templates.support.Templates;
38 import java.awt.event.ActionEvent JavaDoc;
39 import java.awt.event.ActionListener JavaDoc;
40 import javax.swing.ButtonGroup JavaDoc;
41 import javax.swing.JPanel JavaDoc;
42 import javax.swing.JRadioButton JavaDoc;
43 import javax.swing.JCheckBox JavaDoc;
44 import javax.swing.JButton JavaDoc;
45 import javax.swing.event.ChangeEvent JavaDoc;
46 import org.openide.util.NbBundle;
47 import java.awt.GridBagConstraints JavaDoc;
48 import java.awt.GridBagLayout JavaDoc;
49 import javax.swing.border.TitledBorder JavaDoc;
50 import javax.swing.JLabel JavaDoc;
51 import javax.swing.JTextField JavaDoc;
52 import java.awt.Insets JavaDoc;
53 import java.io.File JavaDoc;
54 import javax.swing.event.DocumentListener JavaDoc;
55 import javax.swing.event.DocumentEvent JavaDoc;
56 import javax.swing.JFileChooser JavaDoc;
57 import javax.swing.filechooser.FileFilter JavaDoc;
58 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
59 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
60 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
61 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
62 import org.openide.filesystems.FileUtil;
63 import org.openide.filesystems.FileObject;
64
65 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport;
66 import org.netbeans.modules.j2ee.dd.api.webservices.Webservices;
67 import org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription;
68 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
69 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
70 import org.netbeans.modules.j2ee.dd.api.web.Servlet;
71
72
73 /**
74  *
75  * @author rico
76  * Currently, this is the wizard descriptor for the panel below the
77  * TargetChooser.
78  */

79 public class WebServiceWizardDescriptor implements WizardDescriptor.FinishablePanel {
80     /*
81      * Wizard descriptor of the main wizard
82      */

83     private WizardDescriptor wizardDescriptor;
84     private WebServiceWizardPanel panel;
85     private WebServiceWizardHelper helper;
86     private ChangeListener JavaDoc listener;
87     private static String JavaDoc previousDirectory = "";
88
89     // !PW IZ 54686 Need to dig into TargetChooserGUI panel to retrieve current
90
// target name for additional validation.
91
//
92
// (I propose change this to not use TargetChooser UI or expand TargetChooser
93
// API to allow retrieving the current target name to get rid of this hack)
94
private JTextField JavaDoc nameField;
95     private Project namespaceProject;
96     private java.util.Map JavaDoc webServiceNamespace;
97     
98     private WizardDescriptor.Panel firstPanel;
99     
100     /** Creates a new instance of WebServiceWizardDescriptor */
101     public WebServiceWizardDescriptor(WizardDescriptor wizardDescriptor, WebServiceWizardHelper helper) {
102         this.wizardDescriptor = wizardDescriptor;
103         this.helper = helper;
104
105         this.nameField = null;
106         this.webServiceNamespace = null;
107     }
108     
109     public void setTargetChooserPanel(WizardDescriptor.Panel panel) {
110         this.firstPanel = panel;
111     }
112     
113     public boolean isFinishPanel(){
114         return false;
115     }
116     
117     public void addChangeListener(ChangeListener JavaDoc l) {
118         listener = l;
119     }
120     
121     public void removeChangeListener(ChangeListener JavaDoc l) {
122         if(listener == l) {
123             listener = null;
124         }
125     }
126     
127     public Component JavaDoc getComponent() {
128         if(panel == null){
129             panel = new WebServiceWizardPanel(helper);
130         }
131         return panel;
132     }
133     
134     public HelpCtx getHelp() {
135         return new HelpCtx(WebServiceWizardDescriptor.class);
136     }
137
138     private String JavaDoc validateWebServiceName(String JavaDoc name, java.util.Map JavaDoc namespace) {
139         String JavaDoc message = null;
140
141         if(name == null || name.length() == 0) {
142             // !PW target chooser gui forces null message for this case before we
143
// can check so this case actually doesn't do anything :(
144
message = NbBundle.getMessage(WebServiceWizardDescriptor.class, "MSG_EnterWebServiceName"); // NOI18N
145
} else if(namespace.containsKey(name)) {
146             String JavaDoc messageId = (String JavaDoc) namespace.get(name);
147             String JavaDoc servletName = "WSServlet_" + name; // NOI18N
148
message = NbBundle.getMessage(WebServiceWizardDescriptor.class, messageId, name, servletName);
149         }
150         
151         return message;
152     }
153     
154     private java.util.Map JavaDoc getWSNameSpace(Project p) {
155         long start = System.currentTimeMillis();
156         java.util.Map JavaDoc namespace = new java.util.HashMap JavaDoc();
157         WebServicesSupport wsSupport = WebServicesSupport.getWebServicesSupport(p.getProjectDirectory());
158
159         // First add existing web service names.
160
if(wsSupport != null) {
161             org.netbeans.modules.j2ee.dd.api.webservices.DDProvider wsDDProvider =
162                 org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.getDefault();
163             try {
164                 Webservices webServices = wsDDProvider.getDDRoot(wsSupport.getWebservicesDD());
165                 if(webServices != null) {
166                     WebserviceDescription [] descriptions = webServices.getWebserviceDescription();
167                     if(descriptions != null) {
168                         for(int i = 0; i < descriptions.length; i++) {
169                             String JavaDoc wsname = descriptions[i].getWebserviceDescriptionName();
170                             if(wsname != null && wsname.length() > 0) {
171                                 namespace.put(wsname, "ERR_WebServiceExists"); // NOI18N
172
}
173                         }
174                     }
175                 }
176             } catch(java.io.IOException JavaDoc ex) {
177                 // Nonexistent or invalid webservices.xml -- ignore.
178
}
179
180             // !PW FIXME if we enable this wizard for any freeform project types,
181
// the code that retrieves the deployment descriptor files will need updating.
182

183             // This code was supposed to use DDProvider to extract a root interface
184
// introspect the type, but it turns out that one needs the correct kind
185
// of DDProvider in order to read the file properly. We should resolve
186
// this in DDAPI in 5.0 by pushing DDProvider into common.
187
J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) p.getLookup ().lookup (J2eeModuleProvider.class);
188             Object JavaDoc moduleType = j2eeModuleProvider.getJ2eeModule().getModuleType();
189             if(J2eeModule.WAR.equals(moduleType)) {
190                 FileObject ddFO = org.netbeans.modules.web.api.webmodule.WebModule.getWebModule(p.getProjectDirectory()).getDeploymentDescriptor();
191                 if(ddFO != null) {
192                     try {
193                         WebApp webApp = org.netbeans.modules.j2ee.dd.api.web.DDProvider.getDefault().getDDRoot(ddFO);
194                         Servlet [] servlets = webApp.getServlet();
195                         if(servlets != null) {
196                             for(int i = 0; i < servlets.length; i++) {
197                                 // The servlet created by the new web service wizard has it's name prefixed with WSServlet_
198
// so we need to check against only the roots of servlet names with that prefix.
199
String JavaDoc servletName = servlets[i].getServletName();
200                                 if(servletName != null && servletName.length() > 10 && servletName.startsWith("WSServlet_")) { // NOI81N
201
String JavaDoc wsRootName = servletName.substring(10);
202                                     if(!namespace.containsKey(wsRootName)) {
203                                         namespace.put(wsRootName, "ERR_WS_ServletExists"); // NOI18N
204
}
205                                 }
206                             }
207                         }
208                     } catch(java.io.IOException JavaDoc ex) {
209                         // Nonexistent or invalid deployment descriptor file - ignore.
210
}
211                 }
212             } else if(J2eeModule.EJB.equals(moduleType)) {
213                 org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbjarModule = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(p.getProjectDirectory());
214 // if(ddFO != null) {
215
try {
216                         EjbJar ejbJar = org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(ejbjarModule.getMetadataUnit());
217
218                         EnterpriseBeans eb = ejbJar.getEnterpriseBeans();
219                         if(eb != null) {
220                             Ejb [] ejbs = eb.getEjbs();
221                             if(ejbs != null) {
222                                 for(int i = 0; i < ejbs.length; i++) {
223                                     // Unlike servlets, the generated ejb name is
224
// the same as the web service name.
225
String JavaDoc ejbName = ejbs[i].getEjbName();
226                                     if(ejbName != null && ejbName.length() > 0 && !namespace.containsKey(ejbName)) {
227                                         namespace.put(ejbName, "ERR_WS_EjbExists"); // NOI18N
228
}
229                                 }
230                             }
231                         }
232                     } catch(java.io.IOException JavaDoc ex) {
233                         // Nonexistent or invalid deployment descriptor file - ignore.
234
}
235 // }
236
}
237         }
238         
239         return namespace;
240     }
241     
242     private static JComboBox JavaDoc findCombo(JComponent JavaDoc comp) {
243         Vector JavaDoc allComponents = new Vector JavaDoc();
244         Util.getAllComponents(comp.getComponents(), allComponents);
245         Iterator JavaDoc iterator = allComponents.iterator();
246         while(iterator.hasNext()) {
247             Component JavaDoc c = (Component JavaDoc)iterator.next();
248             if(c instanceof JComboBox JavaDoc) {
249                 JComboBox JavaDoc combo = (JComboBox JavaDoc)c;
250                 if (combo.getSelectedItem() instanceof SourceGroup) {
251                     return combo;
252                 }
253             }
254         }
255         return null;
256     }
257     
258     public boolean isValid() {
259         Project p = Templates.getProject(wizardDescriptor);
260                 
261         // Project must currently have a target server that supports wscompile.
262
if(!isWsCompileSupported(p)) {
263             wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(WebServiceWizardDescriptor.class, "ERR_WsCompileNotSupportedByTargetServer")); // NOI18N
264
return false;
265         }
266         
267         J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) p.getLookup().lookup(J2eeModuleProvider.class);
268         String JavaDoc j2eeVersion = j2eeModuleProvider.getJ2eeModule().getModuleVersion();
269         Object JavaDoc moduleType = j2eeModuleProvider.getJ2eeModule().getModuleType();
270         if ((J2eeModule.WAR.equals(moduleType) && !WebApp.VERSION_2_4.equals(j2eeVersion)) ||
271         (J2eeModule.EJB.equals(moduleType) && !EjbJar.VERSION_2_1.equals(j2eeVersion))) {
272             wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
273
NbBundle.getMessage(WebServiceWizardDescriptor.class, "ERR_ProjectDoesNotSupportJ2EE14")); // NOI18N
274
return false;
275         }
276
277         // this is a hack for target chooser panel
278
if (firstPanel != null) {
279             JComponent JavaDoc targetChooserGUI = (JComponent JavaDoc)firstPanel.getComponent();
280             if (targetChooserGUI != null) {
281                 JComboBox JavaDoc rootFolderCombo = findCombo(targetChooserGUI);
282                 if (rootFolderCombo != null) {
283                    if (rootFolderCombo.isVisible()) {
284                         FileObject fo = ((SourceGroup) rootFolderCombo.getSelectedItem()).getRootFolder();
285                         if (fo != null) {
286                             WebServicesSupport wsSupport = WebServicesSupport.getWebServicesSupport(fo);
287                             if (wsSupport == null) {
288                                 String JavaDoc msg = NbBundle.getMessage(WebServiceWizard.class, "ERR_NoTargetFolder"); //NOI18N
289
wizardDescriptor.putProperty("WizardPanel_errorMessage", msg); //NOI18N
290
return false;
291                             }
292                         }
293                    } else {
294                         String JavaDoc msg = NbBundle.getMessage(WebServiceWizard.class, "ERR_NoTargetFolder"); //NOI18N
295
wizardDescriptor.putProperty("WizardPanel_errorMessage", msg); //NOI18N
296
return false;
297                    }
298                 }
299             }
300         }
301         
302         if (panel != null) {
303             // IZ 54686 validate the service name, if we know what field it's in.
304
if(nameField != null) {
305                 String JavaDoc wsname = nameField.getText().trim();
306                 if(webServiceNamespace == null || namespaceProject != p) {
307                     webServiceNamespace = getWSNameSpace(p);
308                     namespaceProject = p;
309                 }
310                 String JavaDoc message = validateWebServiceName(wsname, webServiceNamespace);
311                 if(message != null) { // name is invalid, message is the display text
312
wizardDescriptor.putProperty("WizardPanel_errorMessage", message); // NOI18N
313
return false; // web service name is invalid
314
}
315             }
316             
317             if(panel.getFromWSDLButton().isSelected()) {
318                 String JavaDoc wsdlFilePath = panel.getWSDLFilePath().trim();
319                 
320                 if(wsdlFilePath == null || wsdlFilePath.length() == 0) {
321                     wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
322
NbBundle.getMessage(WebServiceWizardDescriptor.class, "MSG_EnterWsdlName")); // NOI18N
323
return false; // unspecified WSDL file
324
}
325                 
326                 File JavaDoc f = new File JavaDoc(wsdlFilePath);
327                 String JavaDoc wsdlFileText = f.getAbsolutePath();
328                 f = getCanonicalFile(f);
329                 if(f == null) {
330                     wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
331
NbBundle.getMessage(WebServiceWizardDescriptor.class, "ERR_WsdlInvalid")); // NOI18N
332
return false; // invalid WSDL file
333
}
334                 
335                 if(!f.exists()) {
336                     wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
337
NbBundle.getMessage(WebServiceWizardDescriptor.class, "ERR_WsdlDoesNotExist")); // NOI18N
338
return false; // invalid WSDL file
339
}
340             }
341             else if(panel.getFromWSDLUrlButton().isSelected()) {
342                 String JavaDoc wsdlUrl = panel.getWSDLUrl().trim();
343                 if(wsdlUrl == null || wsdlUrl.length() == 0) {
344                     wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
345
NbBundle.getMessage(WebServiceWizardDescriptor.class, "MSG_EnterWsdlUrl")); // NOI18N
346
return false; // unspecified WSDL file
347
}
348             }
349         }
350         
351         return true;
352     }
353     
354     private boolean isWsCompileSupported(Project p) {
355         // Determine if wscompile is supported by the current target server of
356
// this project. Default to true so that the user can still continue, if on
357
// their own, in case we have difficulty getting the correct answer.
358
boolean result = true;
359
360         J2eeModuleProvider provider = (J2eeModuleProvider) p.getLookup().lookup(J2eeModuleProvider.class);
361         if(provider != null) {
362             String JavaDoc serverInstanceID = provider.getServerInstanceID();
363             if(serverInstanceID != null && serverInstanceID.length() > 0) {
364                 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID);
365                 if ((j2eePlatform == null) || (!j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE))) {
366                     result = false;
367                 }
368             }
369         }
370
371         return result;
372     }
373     
374     /** Retrieve the canonical version of a File instance, converting the possible
375      * IOException into a null (presumably for error presentation purposes).
376      * Copied from Utilities in core.
377      * FIX-ME: removet this when proper dependencies have been set up
378      */

379     public static File JavaDoc getCanonicalFile(File JavaDoc f) {
380         File JavaDoc f1;
381         try {
382             f1 = f.getCanonicalFile();
383         } catch (java.io.IOException JavaDoc e) {
384             f1 = null;
385         }
386         return f1;
387     }
388
389
390     public void readSettings(Object JavaDoc settings) {
391         if(settings instanceof WizardDescriptor) {
392             panel.readSettings((WizardDescriptor) settings);
393             
394             Project p = Templates.getProject((WizardDescriptor) settings);
395             if(p != null) {
396                 if(namespaceProject != p) {
397                     webServiceNamespace = getWSNameSpace(p);
398                     namespaceProject = p;
399                 }
400             } else {
401                 webServiceNamespace = null;
402                 namespaceProject = null;
403             }
404         }
405     }
406
407     public void storeSettings(Object JavaDoc settings) {
408         WebServiceWizardHelper helper = panel.getWizardHelper();
409         
410         //FIX-ME: Will this ever happen?
411
if(settings instanceof WebServiceWizardHelper) {
412             helper = (WebServiceWizardHelper)settings;
413         }
414         
415         if(helper != null) {
416             if(panel.isFromScratch()) {
417                 helper.setCreateFrom(WebServiceWizardHelper.CREATE_FROM_SCRATCH);
418             }
419             else if(panel.isFromExistingCode()) {
420                 helper.setCreateFrom(WebServiceWizardHelper.CREATE_FROM_EXISTING_CODE);
421             }
422             else if(panel.isFromWSDL()) {
423                 helper.setCreateFrom(WebServiceWizardHelper.CREATE_FROM_WSDL_FILE);
424             }
425             else if(panel.isFromWSDLUrl()) {
426                 helper.setCreateFrom(WebServiceWizardHelper.CREATE_FROM_WSDL_URL);
427             }
428         }
429         
430         if(settings instanceof WizardDescriptor) {
431             panel.storeSettings((WizardDescriptor)settings);
432         }
433     }
434     
435     class WebServiceWizardPanel extends JPanel JavaDoc implements DocumentListener JavaDoc{
436         WebServiceWizardHelper helper;
437         private final FileFilter JavaDoc WSDL_FILE_FILTER = new WsdlFileFilter();
438         
439         public WebServiceWizardPanel(WebServiceWizardHelper helper) {
440             this.helper = helper;
441             initComponents();
442             addListeners();
443         }
444         
445         private void initComponents() {
446             java.awt.GridBagConstraints JavaDoc gridBagConstraints;
447             
448             typeButtons = new ButtonGroup JavaDoc();
449             
450             fromScratchButton = new JRadioButton JavaDoc(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromScratch")); // NOI18N
451
fromScratchButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromScratch"));
452             fromScratchButton.setMnemonic(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromScratch_mnem").charAt(0));
453
454             fromWSDLButton = new JRadioButton JavaDoc(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromWSDL")); // NOI18N
455
fromWSDLButton.getAccessibleContext().setAccessibleDescription(fromWSDLButton.getText());
456             fromWSDLButton.setMnemonic(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromWSDL_mnem").charAt(0));
457             
458             fromWSDLUrlButton = new JRadioButton JavaDoc(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromWSDLUrl")); // NOI18N
459
fromWSDLUrlButton.getAccessibleContext().setAccessibleDescription(fromWSDLUrlButton.getText());
460             fromWSDLUrlButton.setMnemonic(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromWSDLUrl_mnem").charAt(0));
461             
462             fromExistingCodeButton = new JCheckBox JavaDoc(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromExistingCode")); // NOI18N
463
fromExistingCodeButton.getAccessibleContext().setAccessibleDescription(fromExistingCodeButton.getText());
464             fromExistingCodeButton.setMnemonic(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromExistingCode_mnem").charAt(0));
465                     
466             wsdlFileTextField = new JTextField JavaDoc();
467             wsdlFileTextField.getDocument().addDocumentListener(this);
468             wsdlFileTextField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(WebServiceWizardPanel.class, "A11Y_WSDL_TF"));
469             
470             browseButton = new JButton JavaDoc(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_Browse")); // NOI18N
471
browseButton.getAccessibleContext().setAccessibleDescription(browseButton.getText());
472             browseButton.setMnemonic(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_Browse_mnem").charAt(0));
473             
474             urlLabel = new JLabel JavaDoc(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_UrlLabel")); // NOI18N
475
urlLabel.setDisplayedMnemonic(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_UrlLabel_mnem").charAt(0));
476             
477             urlTextField = new JTextField JavaDoc();
478             urlLabel.setLabelFor(urlTextField);
479             urlTextField.getDocument().addDocumentListener(this);
480             urlTextField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(WebServiceWizardPanel.class, "A11Y_WSDL_URL_TF"));
481             
482             setLayout(new GridBagLayout JavaDoc());
483             setBorder(new TitledBorder JavaDoc(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_WebService_Type"))); // NOI18N
484

485             typeButtons.add(fromScratchButton);
486             typeButtons.add(fromWSDLButton);
487             typeButtons.add(fromWSDLUrlButton);
488             fromScratchButton.setSelected(true);
489             browseButton.setEnabled(false);
490             urlTextField.setEnabled(false);
491             wsdlFileTextField.setEnabled(false);
492             
493             wsdlFilePanel = new JPanel JavaDoc();
494             wsdlFilePanel.setLayout(new GridBagLayout JavaDoc());
495             gridBagConstraints = new GridBagConstraints JavaDoc();
496             gridBagConstraints.insets = new Insets JavaDoc(0, 0, 0, 0);
497             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
498             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
499             gridBagConstraints.weightx = 4.0;
500             gridBagConstraints.weighty = 1.0;
501             gridBagConstraints.gridx = 0;
502             gridBagConstraints.gridy = 0;
503             wsdlFilePanel.add(wsdlFileTextField, gridBagConstraints);
504             
505             gridBagConstraints.gridx = 1;
506             gridBagConstraints.weightx = 1.0;
507             gridBagConstraints.insets = new Insets JavaDoc(0, 10, 0, 24);
508             wsdlFilePanel.add(browseButton, gridBagConstraints);
509             
510             urlPanel = new JPanel JavaDoc();
511             urlPanel.setLayout(new GridBagLayout JavaDoc());
512             gridBagConstraints = new GridBagConstraints JavaDoc();
513             gridBagConstraints.insets = new Insets JavaDoc(0, 0, 0, 0);
514             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
515             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
516             gridBagConstraints.weightx = 0.0;
517             gridBagConstraints.weighty = 1.0;
518             gridBagConstraints.gridx = 0;
519             gridBagConstraints.gridy = 0;
520             urlPanel.add(urlLabel, gridBagConstraints);
521             
522             gridBagConstraints.weightx = 1.0;
523             gridBagConstraints.gridx = 1;
524             urlPanel.add(urlTextField, gridBagConstraints);
525             
526             gridBagConstraints = new GridBagConstraints JavaDoc();
527             gridBagConstraints.insets = new Insets JavaDoc(0, 0, 0, 0);
528             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
529             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
530             gridBagConstraints.weightx = 0.0;
531             gridBagConstraints.weighty = 1.0;
532             gridBagConstraints.gridx = 0;
533             gridBagConstraints.gridy = 0;
534             add(fromScratchButton, gridBagConstraints);
535             gridBagConstraints.gridx = 1;
536             gridBagConstraints.weightx = 2.0;
537             add(fromExistingCodeButton, gridBagConstraints);
538             gridBagConstraints.gridx = 0;
539             gridBagConstraints.gridy = 1;
540             gridBagConstraints.weightx = 0.0;
541             add(fromWSDLButton, gridBagConstraints);
542             gridBagConstraints.gridx = 1;
543             gridBagConstraints.insets = new Insets JavaDoc(0, 0, 0, 24);
544             add(wsdlFilePanel, gridBagConstraints);
545             gridBagConstraints.gridx = 0;
546             gridBagConstraints.gridy = 2;
547             add(fromWSDLUrlButton, gridBagConstraints);
548             gridBagConstraints.gridx = 1;
549             gridBagConstraints.insets = new Insets JavaDoc(0, 0, 0, 50);
550             add(urlPanel, gridBagConstraints);
551             
552         }
553
554         public void addNotify() {
555             super.addNotify();
556
557             // !PW Part of namefield locator hack for IZ 54686
558
nameField = null;
559             java.awt.Container JavaDoc holderPanel = getParent();
560             if(holderPanel != null) {
561                 java.awt.Container JavaDoc guiPanel = holderPanel.getParent();
562                 if(guiPanel != null) {
563                     nameField = getFirstTextField(guiPanel);
564                 }
565             }
566             
567             // if nameField is still null here, then we couldn't find the namefield
568
// correctly. Later validation attempts should do nothing in this case.
569
}
570         
571         private JTextField JavaDoc getFirstTextField(java.awt.Container JavaDoc top) {
572             // Depth first search from top for the first component that is a
573
// JTextField -- this one should be the target name field.
574
JTextField JavaDoc result = null;
575             java.awt.Component JavaDoc[] components = top.getComponents();
576             for(int i = 0; i < components.length && result == null; i++) {
577                 if(components[i] instanceof JTextField JavaDoc) {
578                     result = (JTextField JavaDoc) components[i];
579                 } else if(components[i] instanceof java.awt.Container JavaDoc) {
580                     result = getFirstTextField((java.awt.Container JavaDoc) components[i]);
581                 }
582             }
583             return result;
584         }
585
586         public JRadioButton JavaDoc getFromWSDLButton() {
587             return fromWSDLButton;
588         }
589         
590         public JRadioButton JavaDoc getFromWSDLUrlButton() {
591             return fromWSDLUrlButton;
592         }
593         
594         public boolean isFromScratch(){
595             return fromScratchButton.isSelected() && !fromExistingCodeButton.isSelected();
596         }
597         
598         public boolean isFromWSDL(){
599             return fromWSDLButton.isSelected();
600         }
601         
602         public boolean isFromWSDLUrl() {
603             return fromWSDLUrlButton.isSelected();
604         }
605         
606         public boolean isFromExistingCode(){
607             return fromScratchButton.isSelected() && fromExistingCodeButton.isSelected();
608         }
609         
610         
611         public WebServiceWizardHelper getWizardHelper() {
612             return helper;
613         }
614         
615         private void addListeners() {
616             final WebServiceWizard wiz = helper.getWizard();
617             fromScratchButton.addActionListener(new ActionListener JavaDoc() {
618                 public void actionPerformed(ActionEvent JavaDoc evt) {
619                     if(!fromExistingCodeButton.isEnabled()) {
620                         fromExistingCodeButton.setEnabled(true);
621                     }
622                     if(browseButton.isEnabled()){
623                         browseButton.setEnabled(false);
624                     }
625                     if(wsdlFileTextField.isEnabled()){
626                         wsdlFileTextField.setEnabled(false);
627                     }
628                     if(urlTextField.isEnabled()){
629                         urlTextField.setEnabled(false);
630                     }
631                     if(!fromExistingCodeButton.isSelected()) {
632                         wiz.setPanelsAndSteps(
633                         WebServiceWizard.PATH_CREATE_FROM_SCRATCH);
634                     }
635                     else {
636                         wiz.setPanelsAndSteps(
637                         WebServiceWizard.PATH_CREATE_FROM_EXISTING_CODE);
638                     }
639                     
640                     fireStateChanged();
641                 }
642             });
643             fromExistingCodeButton.addActionListener(new ActionListener JavaDoc() {
644                 public void actionPerformed(ActionEvent JavaDoc evt) {
645                     if(fromExistingCodeButton.isSelected()) {
646                         wiz.setPanelsAndSteps(
647                         WebServiceWizard.PATH_CREATE_FROM_EXISTING_CODE);
648                     }
649                     else {
650                         wiz.setPanelsAndSteps(
651                         WebServiceWizard.PATH_CREATE_FROM_SCRATCH);
652                     }
653                     fireStateChanged();
654                 }
655             });
656             fromWSDLButton.addActionListener(new ActionListener JavaDoc() {
657                 public void actionPerformed(ActionEvent JavaDoc evt) {
658                     if(!wsdlFileTextField.isEnabled()){
659                         wsdlFileTextField.setEnabled(true);
660                     }
661                     if(!browseButton.isEnabled()){
662                         browseButton.setEnabled(true);
663                     }
664                     if(urlTextField.isEnabled()){
665                         urlTextField.setEnabled(false);
666                     }
667                     ((WebServiceWizard)(helper.getWizard())).setPanelsAndSteps(
668                     WebServiceWizard.PATH_CREATE_FROM_WSDL_FILE);
669                     if(fromExistingCodeButton.isSelected()) {
670                         fromExistingCodeButton.setSelected(false);
671                     }
672                     fromExistingCodeButton.setEnabled(false);
673                     fireStateChanged();
674                 }
675             });
676             fromWSDLUrlButton.addActionListener(new ActionListener JavaDoc() {
677                 public void actionPerformed(ActionEvent JavaDoc evt) {
678                     ((WebServiceWizard)(helper.getWizard())).setPanelsAndSteps(
679                     WebServiceWizard.PATH_CREATE_FROM_WSDL_URL);
680                     if(!urlTextField.isEnabled()){
681                         urlTextField.setEnabled(true);
682                     }
683                     if(fromExistingCodeButton.isSelected()) {
684                         fromExistingCodeButton.setSelected(false);
685                     }
686                     fromExistingCodeButton.setEnabled(false);
687                     if(browseButton.isEnabled()){
688                         browseButton.setEnabled(false);
689                     }
690                     if(wsdlFileTextField.isEnabled()){
691                         wsdlFileTextField.setEnabled(false);
692                     }
693                     fireStateChanged();
694                 }
695             });
696             browseButton.addActionListener(new ActionListener JavaDoc() {
697                 public void actionPerformed(ActionEvent JavaDoc evt) {
698                     JFileChooser JavaDoc chooser = new JFileChooser JavaDoc(previousDirectory);
699                     chooser.setMultiSelectionEnabled(false);
700                     chooser.setAcceptAllFileFilterUsed(false);
701                     chooser.addChoosableFileFilter(WSDL_FILE_FILTER);
702                     chooser.setFileFilter(WSDL_FILE_FILTER);
703                     
704                     if(chooser.showOpenDialog(WebServiceWizardPanel.this) == JFileChooser.APPROVE_OPTION) {
705                         File JavaDoc wsdlFile = chooser.getSelectedFile();
706                         wsdlFileTextField.setText(wsdlFile.getAbsolutePath());
707                         previousDirectory = wsdlFile.getPath();
708                     }
709                 }
710             });
711             
712         }
713         
714         public void changedUpdate(DocumentEvent JavaDoc e) {
715             fireStateChanged();
716         }
717         
718         public void insertUpdate(DocumentEvent JavaDoc e) {
719             fireStateChanged();
720         }
721         
722         public void removeUpdate(DocumentEvent JavaDoc e) {
723             fireStateChanged();
724         }
725         
726         
727         public String JavaDoc getWSDLFilePath() {
728             return wsdlFileTextField.getText();
729         }
730         
731         public String JavaDoc getWSDLUrl() {
732             return urlTextField.getText();
733         }
734
735
736         void readSettings(WizardDescriptor wizDescriptor) {
737             // IZ 54686 - need to fire a state change to force initial validation
738
// of name.
739
javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
740                 public void run() {
741                     fireStateChanged();
742                 }
743             });
744         }
745         
746         void storeSettings(WizardDescriptor wizDescriptor) {
747             wizDescriptor.putProperty(WebServiceWizard.WSDL_FILE_PATH, wsdlFileTextField.getText().trim());
748             wizDescriptor.putProperty(WebServiceWizard.WSDL_FILE_URL, urlTextField.getText().trim());
749         }
750         
751         
752         // Invoking this method causes the wizard framework (listener) to invoke
753
// the isValid() method.
754
private void fireStateChanged() {
755             if (listener != null) {
756                 ChangeEvent JavaDoc evt = new ChangeEvent JavaDoc(this);
757                 listener.stateChanged(evt);
758             }
759         }
760         
761         private ButtonGroup JavaDoc typeButtons;
762         private JRadioButton JavaDoc fromScratchButton;
763         private JRadioButton JavaDoc fromWSDLButton;
764         private JRadioButton JavaDoc fromWSDLUrlButton;
765         private JCheckBox JavaDoc fromExistingCodeButton;
766         private JPanel JavaDoc wsdlFilePanel;
767         private JTextField JavaDoc wsdlFileTextField;
768         private JButton JavaDoc browseButton;
769         private JPanel JavaDoc urlPanel;
770         private JLabel JavaDoc urlLabel;
771         private JTextField JavaDoc urlTextField;
772     }
773     private static class WsdlFileFilter extends FileFilter JavaDoc {
774         public boolean accept(File JavaDoc f) {
775             boolean result;
776             if(f.isDirectory() || "wsdl".equalsIgnoreCase(FileUtil.getExtension(f.getName()))) { // NOI18N
777
result = true;
778             } else {
779                 result = false;
780             }
781             return result;
782         }
783         
784         public String JavaDoc getDescription() {
785             return NbBundle.getMessage(WebServiceWizardDescriptor.class, "LBL_WsdlFilterDescription"); // NOI18N
786
}
787     }
788 }
789
Popular Tags