KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tomcat5 > wizard > InstallPanelVisual


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.tomcat5.wizard;
21
22 import java.io.File JavaDoc;
23 import java.io.FilenameFilter JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Properties JavaDoc;
29 import javax.swing.JFileChooser JavaDoc;
30 import javax.swing.SwingUtilities JavaDoc;
31 import javax.swing.event.ChangeEvent JavaDoc;
32 import javax.swing.event.ChangeListener JavaDoc;
33 import javax.swing.event.DocumentEvent JavaDoc;
34 import javax.swing.event.DocumentListener JavaDoc;
35 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
36 import org.netbeans.modules.tomcat5.TomcatFactory;
37 import org.netbeans.modules.tomcat5.TomcatManager.TomcatVersion;
38 import org.netbeans.modules.tomcat5.config.gen.Server;
39 import org.netbeans.modules.tomcat5.util.TomcatInstallUtil;
40 import org.netbeans.modules.tomcat5.util.TomcatProperties;
41 import org.openide.ErrorManager;
42 import org.openide.util.NbBundle;
43 import org.openide.util.RequestProcessor;
44
45
46 /**
47  * Add Tomcat wizard panel.
48  *
49  * @author Martin Grebac
50  */

51 class InstallPanelVisual extends javax.swing.JPanel JavaDoc {
52     
53     private final String JavaDoc SERVER_XML = "conf/server.xml"; // NOI18N
54

55     private final List JavaDoc listeners = new ArrayList JavaDoc();
56     private final TomcatVersion tomcatVersion;
57     
58     private String JavaDoc errorMessage;
59     
60     private String JavaDoc serverPort;
61     private String JavaDoc shutdownPort;
62     
63     private RequestProcessor.Task validationTask;
64     
65     
66     /** Creates new form JPanel */
67     public InstallPanelVisual(TomcatVersion tomcatVersion) {
68         this.tomcatVersion = tomcatVersion;
69         initComponents();
70         DocumentListener JavaDoc updateListener = new DocumentListener JavaDoc() {
71             public void changedUpdate(DocumentEvent JavaDoc e) {
72                 fireChange();
73             }
74
75             public void removeUpdate(DocumentEvent JavaDoc e) {
76                 fireChange();
77             }
78
79             public void insertUpdate(DocumentEvent JavaDoc e) {
80                 fireChange();
81             }
82         };
83         jTextFieldHomeDir.getDocument().addDocumentListener(updateListener);
84         jTextFieldBaseDir.getDocument().addDocumentListener(updateListener);
85         addChangeListener(new ChangeListener JavaDoc() {
86             public void stateChanged(ChangeEvent JavaDoc e) {
87                 // if JWSDP installed, disable the catalina base directory
88
if (isJWSDP()) {
89                     if (jCheckBoxShared.isEnabled()) {
90                         jCheckBoxShared.setEnabled(false);
91                         setBaseEnabled(false);
92                     }
93                 } else {
94                     if (!jCheckBoxShared.isEnabled()) {
95                         jCheckBoxShared.setEnabled(true);
96                         if (jCheckBoxShared.isSelected()) {
97                             setBaseEnabled(true);
98                         }
99                     }
100                 }
101             }
102         });
103     }
104     
105     public void addChangeListener(ChangeListener JavaDoc l) {
106         synchronized (listeners) {
107             listeners.add(l);
108         }
109     }
110     
111     public void removeChangeListener(ChangeListener JavaDoc l) {
112         synchronized (listeners) {
113             listeners.remove(l);
114         }
115     }
116     
117     /** This method is called from within the constructor to
118      * initialize the form.
119      * WARNING: Do NOT modify this code. The content of this method is
120      * always regenerated by the Form Editor.
121      */

122     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
123
private void initComponents() {
124         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
125
126         jLabelHomeDir = new javax.swing.JLabel JavaDoc();
127         jLabelBaseDir = new javax.swing.JLabel JavaDoc();
128         jTextFieldHomeDir = new javax.swing.JTextField JavaDoc();
129         jTextFieldBaseDir = new javax.swing.JTextField JavaDoc();
130         jButtonBaseBrowse = new javax.swing.JButton JavaDoc();
131         jButtonHomeBrowse = new javax.swing.JButton JavaDoc();
132         jCheckBoxShared = new javax.swing.JCheckBox JavaDoc();
133         jLabelUsername = new javax.swing.JLabel JavaDoc();
134         jLabelPassword = new javax.swing.JLabel JavaDoc();
135         jLabel1 = new javax.swing.JLabel JavaDoc();
136         jPanel1 = new javax.swing.JPanel JavaDoc();
137         jTextFieldUsername = new javax.swing.JTextField JavaDoc();
138         jLabel2 = new javax.swing.JLabel JavaDoc();
139         jPanel2 = new javax.swing.JPanel JavaDoc();
140         jTextFieldPassword = new javax.swing.JPasswordField JavaDoc();
141         jLabel3 = new javax.swing.JLabel JavaDoc();
142
143         setLayout(new java.awt.GridBagLayout JavaDoc());
144
145         setName(org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_InstanceProperties"));
146         getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_panel"));
147         getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_panel"));
148         jLabelHomeDir.setLabelFor(jTextFieldHomeDir);
149         org.openide.awt.Mnemonics.setLocalizedText(jLabelHomeDir, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_home_dir"));
150         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
151         gridBagConstraints.gridx = 0;
152         gridBagConstraints.gridy = 1;
153         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
154         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
155         add(jLabelHomeDir, gridBagConstraints);
156         jLabelHomeDir.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_labelHomeDir"));
157         jLabelHomeDir.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_labelHomeDir"));
158
159         jLabelBaseDir.setLabelFor(jTextFieldBaseDir);
160         org.openide.awt.Mnemonics.setLocalizedText(jLabelBaseDir, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_base_dir"));
161         jLabelBaseDir.setEnabled(false);
162         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.gridx = 0;
164         gridBagConstraints.gridy = 3;
165         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
166         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 0);
167         add(jLabelBaseDir, gridBagConstraints);
168         jLabelBaseDir.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_labelBaseDir"));
169         jLabelBaseDir.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_labelBaseDir"));
170
171         jTextFieldHomeDir.setColumns(15);
172         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
173         gridBagConstraints.gridx = 1;
174         gridBagConstraints.gridy = 1;
175         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
176         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
177         gridBagConstraints.weightx = 1.0;
178         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 0);
179         add(jTextFieldHomeDir, gridBagConstraints);
180         jTextFieldHomeDir.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_homeDir"));
181         jTextFieldHomeDir.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_homeDir"));
182
183         jTextFieldBaseDir.setColumns(15);
184         jTextFieldBaseDir.setEnabled(false);
185         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
186         gridBagConstraints.gridx = 1;
187         gridBagConstraints.gridy = 3;
188         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
189         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
190         gridBagConstraints.weightx = 2.0;
191         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 0);
192         add(jTextFieldBaseDir, gridBagConstraints);
193         jTextFieldBaseDir.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_baseDir"));
194         jTextFieldBaseDir.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_baseDir"));
195
196         org.openide.awt.Mnemonics.setLocalizedText(jButtonBaseBrowse, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_file_chooser_base"));
197         jButtonBaseBrowse.setEnabled(false);
198         jButtonBaseBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
199             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
200                 jButtonBaseBrowseActionPerformed(evt);
201             }
202         });
203
204         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
205         gridBagConstraints.gridx = 2;
206         gridBagConstraints.gridy = 3;
207         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
208         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 0);
209         add(jButtonBaseBrowse, gridBagConstraints);
210         jButtonBaseBrowse.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_ButtonBaseBrowse"));
211         jButtonBaseBrowse.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_ButtonBaseBrowse"));
212
213         org.openide.awt.Mnemonics.setLocalizedText(jButtonHomeBrowse, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_file_chooser_home"));
214         jButtonHomeBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
215             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
216                 jButtonHomeBrowseActionPerformed(evt);
217             }
218         });
219
220         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
221         gridBagConstraints.gridx = 2;
222         gridBagConstraints.gridy = 1;
223         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
224         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 0);
225         add(jButtonHomeBrowse, gridBagConstraints);
226         jButtonHomeBrowse.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_ButtonHomeBrowse"));
227         jButtonHomeBrowse.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_ButtonHomeBrowse"));
228
229         org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxShared, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_SharedInstall"));
230         jCheckBoxShared.addActionListener(new java.awt.event.ActionListener JavaDoc() {
231             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
232                 jCheckBoxSharedActionPerformed(evt);
233             }
234         });
235
236         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
237         gridBagConstraints.gridx = 0;
238         gridBagConstraints.gridy = 2;
239         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
240         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
241         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
242         add(jCheckBoxShared, gridBagConstraints);
243         jCheckBoxShared.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_shared"));
244         jCheckBoxShared.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_shared"));
245
246         jLabelUsername.setLabelFor(jTextFieldUsername);
247         org.openide.awt.Mnemonics.setLocalizedText(jLabelUsername, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_Username"));
248         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
249         gridBagConstraints.gridx = 0;
250         gridBagConstraints.gridy = 4;
251         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
252         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 0, 0, 0);
253         add(jLabelUsername, gridBagConstraints);
254         jLabelUsername.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_labelUsername"));
255         jLabelUsername.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_labelUsername"));
256
257         jLabelPassword.setLabelFor(jTextFieldPassword);
258         org.openide.awt.Mnemonics.setLocalizedText(jLabelPassword, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_Password"));
259         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
260         gridBagConstraints.gridx = 0;
261         gridBagConstraints.gridy = 5;
262         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
263         gridBagConstraints.weighty = 1.0;
264         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
265         add(jLabelPassword, gridBagConstraints);
266         jLabelPassword.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_labelPassword"));
267         jLabelPassword.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_labelPassword"));
268
269         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "MSG_TextAbove"));
270         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
271         gridBagConstraints.gridx = 0;
272         gridBagConstraints.gridy = 0;
273         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
274         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
275         add(jLabel1, gridBagConstraints);
276
277         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
278
279         jTextFieldUsername.setColumns(15);
280         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
281         gridBagConstraints.gridx = 0;
282         gridBagConstraints.gridy = 0;
283         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
284         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
285         gridBagConstraints.weightx = 1.0;
286         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 5, 0, 0);
287         jPanel1.add(jTextFieldUsername, gridBagConstraints);
288         jTextFieldUsername.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_username"));
289         jTextFieldUsername.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_username"));
290
291         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_ForManager"));
292         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
293         gridBagConstraints.gridx = 1;
294         gridBagConstraints.gridy = 0;
295         gridBagConstraints.gridwidth = 2;
296         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
297         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 5, 0, 0);
298         jPanel1.add(jLabel2, gridBagConstraints);
299
300         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
301         gridBagConstraints.gridx = 1;
302         gridBagConstraints.gridy = 4;
303         gridBagConstraints.gridwidth = 2;
304         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
305         gridBagConstraints.weightx = 1.0;
306         add(jPanel1, gridBagConstraints);
307
308         jPanel2.setLayout(new java.awt.GridBagLayout JavaDoc());
309
310         jTextFieldPassword.setColumns(15);
311         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
312         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
313         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
314         gridBagConstraints.weightx = 1.0;
315         gridBagConstraints.weighty = 1.0;
316         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 0);
317         jPanel2.add(jTextFieldPassword, gridBagConstraints);
318         jTextFieldPassword.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_NAME_password"));
319         jTextFieldPassword.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InstallPanelVisual.class, "A11Y_DESC_password"));
320
321         jLabel3.setForeground(getBackground());
322         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(InstallPanelVisual.class, "LBL_ForManager"));
323         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
324         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
325         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 0);
326         jPanel2.add(jLabel3, gridBagConstraints);
327
328         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
329         gridBagConstraints.gridx = 1;
330         gridBagConstraints.gridy = 5;
331         gridBagConstraints.gridwidth = 2;
332         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
333         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
334         gridBagConstraints.weightx = 1.0;
335         gridBagConstraints.weighty = 1.0;
336         add(jPanel2, gridBagConstraints);
337
338     }
339     // </editor-fold>//GEN-END:initComponents
340

341     private void jButtonBaseBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonBaseBrowseActionPerformed
342
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
343         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
344         chooser.setSelectedFile(new File JavaDoc(jTextFieldBaseDir.getText().trim()));
345         if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
346             jTextFieldBaseDir.setText(chooser.getSelectedFile().getAbsolutePath());
347             fireChange();
348         }
349     }//GEN-LAST:event_jButtonBaseBrowseActionPerformed
350

351     private void jButtonHomeBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonHomeBrowseActionPerformed
352
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
353         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
354         chooser.setSelectedFile(new File JavaDoc(jTextFieldHomeDir.getText().trim()));
355         if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
356             jTextFieldHomeDir.setText(chooser.getSelectedFile().getAbsolutePath());
357             fireChange();
358         }
359     }//GEN-LAST:event_jButtonHomeBrowseActionPerformed
360

361     private void jCheckBoxSharedActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jCheckBoxSharedActionPerformed
362
setBaseEnabled(jCheckBoxShared.isSelected());
363         fireChange();
364     }//GEN-LAST:event_jCheckBoxSharedActionPerformed
365

366     public java.util.Properties JavaDoc getProperties() {
367         Properties JavaDoc p = new Properties JavaDoc();
368         p.put(TomcatProperties.PROP_SERVER_PORT, serverPort);
369         p.put(TomcatProperties.PROP_SHUTDOWN, shutdownPort);
370         p.put(TomcatProperties.PROP_MONITOR, "false"); // NOI18N
371
return p;
372     }
373     
374     public String JavaDoc getUrl() {
375         String JavaDoc url;
376         switch (tomcatVersion) {
377             case TOMCAT_60:
378                 url = TomcatFactory.TOMCAT_URI_PREFIX_60;
379                 break;
380             case TOMCAT_55:
381                 url = TomcatFactory.TOMCAT_URI_PREFIX_55;
382                 break;
383             case TOMCAT_50:
384             default:
385                 url = TomcatFactory.TOMCAT_URI_PREFIX_50;
386                 break;
387         }
388         
389         url += "home=" + jTextFieldHomeDir.getText(); // NOI18N
390

391         if (jCheckBoxShared.isEnabled() && jCheckBoxShared.isSelected()) {
392             url += ":base=" + jTextFieldBaseDir.getText(); // NOI18N
393
}
394         
395         TomcatFactory.getEM().log("TomcatInstall.getUrl: " + url); // NOI18N
396
return url;
397     }
398     
399     public String JavaDoc getUsername() {
400         return jTextFieldUsername.getText();
401     }
402     
403     public String JavaDoc getPassword() {
404         return new String JavaDoc(jTextFieldPassword.getPassword());
405     }
406     
407     public File JavaDoc getHomeDir() {
408         return new File JavaDoc(jTextFieldHomeDir.getText());
409     }
410     
411     public String JavaDoc getErrorMessage() {
412         // prevent the message from being cut off - wizard descriptor issue work-around
413
return errorMessage == null
414                 ? null
415                 : "<html>" + errorMessage.replaceAll("<", "&lt;").replaceAll(">", "&gt;") + "</html>"; // NIO18N
416
}
417     
418     boolean isServerXmlValid(File JavaDoc file) {
419         try {
420             Server server = Server.createGraph(file);
421             serverPort = TomcatInstallUtil.getPort(server);
422             shutdownPort = TomcatInstallUtil.getShutdownPort(server);
423             if (serverPort != null && shutdownPort != null) {
424                 // test whether it's parseable
425
Integer.parseInt(serverPort);
426                 Integer.parseInt(shutdownPort);
427                 return true;
428             }
429         } catch (IOException JavaDoc ioe) {
430             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
431         } catch (NumberFormatException JavaDoc nfe) {
432             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, nfe);
433         } catch (RuntimeException JavaDoc e) {
434             // catch any runtime exception that may occur during graph parsing
435
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
436         }
437         return false;
438     }
439     
440     private boolean isHomeValid() {
441         String JavaDoc homeDir = jTextFieldHomeDir.getText();
442         if (homeDir.length() == 0) {
443             errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_SpecifyHomeDir");
444             return false;
445         }
446         if (!new File JavaDoc(homeDir, "bin/bootstrap.jar").exists()) { // NOI18N
447
errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_InvalidHomeDir");
448             return false;
449         }
450         if ((!jCheckBoxShared.isEnabled() || !jCheckBoxShared.isSelected()) && !isServerXmlValid(new File JavaDoc(homeDir, SERVER_XML))) {
451             errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_CorruptedHomeServerXml");
452             return false;
453         }
454         return true;
455     }
456     
457     /** Is it Tomcat with the JWSDP installed? Does it contain the jwsdp-shared folder? */
458     private boolean isJWSDP() {
459         if (isHomeValid()) {
460             File JavaDoc homeDir = getHomeDir();
461             if (homeDir != null && homeDir.exists()) {
462                 File JavaDoc files[] = homeDir.listFiles(new FilenameFilter JavaDoc() {
463                     public boolean accept(File JavaDoc dir, String JavaDoc name) {
464                         if ("jwsdp-shared".equals(name)) { // NOI18N
465
return true;
466                         }
467                         return false;
468                     }
469                 });
470                 return files.length != 0 ? true : false;
471             }
472         }
473         return false;
474     }
475     
476     private boolean isBaseValid() {
477         // catalina base
478
if (jCheckBoxShared.isEnabled() && jCheckBoxShared.isSelected()) {
479             String JavaDoc base = jTextFieldBaseDir.getText();
480             if (base.length() == 0) {
481                 errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_SpecifyBaseDir");
482                 return false;
483             }
484             File JavaDoc baseDir = new File JavaDoc(base);
485             String JavaDoc[] files = baseDir.list();
486             File JavaDoc serverXml = new File JavaDoc(baseDir, SERVER_XML);
487             // is the base dir empty or does the server.xml file exists?
488
if (!baseDir.exists() || files == null
489                 || (files.length > 0 && !serverXml.exists())) {
490                 errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_InvalidBaseDir");
491                 return false;
492             }
493             if (files.length > 0) {
494                 // check CATALINA_BASE/conf/server.xml, if base dir not empty
495
if (!isServerXmlValid(serverXml)) {
496                     errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_CorruptedBaseServerXml");
497                     return false;
498                 }
499             } else {
500                 // otherwise check CATALINA_HOME/conf/server.xml which we will copy to base dir
501
if (!isServerXmlValid(new File JavaDoc(jTextFieldHomeDir.getText(), SERVER_XML))) {
502                     errorMessage = NbBundle.getMessage(InstallPanelVisual.class, "MSG_CorruptedHomeServerXml");
503                     return false;
504                 }
505             }
506         }
507         return true;
508     }
509     
510     private boolean isAlreadyRegistered() {
511         if (InstanceProperties.getInstanceProperties(getUrl()) != null) {
512             errorMessage = NbBundle.getMessage(InstallPanelVisual.class,
513                                 jCheckBoxShared.isEnabled() && jCheckBoxShared.isSelected()
514                                     ? "MSG_AlreadyRegisteredBase"
515                                     : "MSG_AlreadyRegisteredHome");
516             return true;
517         }
518         return false;
519     }
520     
521     private void setBaseEnabled(boolean enabled) {
522         jLabelBaseDir.setEnabled(enabled);
523         jTextFieldBaseDir.setEnabled(enabled);
524         jButtonBaseBrowse.setEnabled(enabled);
525     }
526     
527     public boolean isValid() {
528         errorMessage = null;
529         return isHomeValid() && isBaseValid() && !isAlreadyRegistered();
530     }
531     
532     private void fireChange() {
533         // schedule the validation task so that error messages won't flash e.g.
534
// when calling jTextFieldBaseDir.setText which triggers two consecutive
535
// events removeUpdate and insertUpdate. validation after the first one
536
// inevitably leads to a failure.
537
if (validationTask == null) {
538             validationTask = RequestProcessor.getDefault().create(new Runnable JavaDoc() {
539                 public void run() {
540                     if (!SwingUtilities.isEventDispatchThread()) {
541                         SwingUtilities.invokeLater(this);
542                         return;
543                     }
544                     
545                     ChangeEvent JavaDoc event = new ChangeEvent JavaDoc(this);
546                     ArrayList JavaDoc tempList;
547                     
548                     synchronized(listeners) {
549                         tempList = new ArrayList JavaDoc(listeners);
550                     }
551                     
552                     Iterator JavaDoc iter = tempList.iterator();
553                     while (iter.hasNext()) {
554                         ((ChangeListener JavaDoc)iter.next()).stateChanged(event);
555                     }
556                 }
557             });
558         }
559         validationTask.schedule(60);
560     }
561     
562     // Variables declaration - do not modify//GEN-BEGIN:variables
563
private javax.swing.JButton JavaDoc jButtonBaseBrowse;
564     private javax.swing.JButton JavaDoc jButtonHomeBrowse;
565     private javax.swing.JCheckBox JavaDoc jCheckBoxShared;
566     private javax.swing.JLabel JavaDoc jLabel1;
567     private javax.swing.JLabel JavaDoc jLabel2;
568     private javax.swing.JLabel JavaDoc jLabel3;
569     private javax.swing.JLabel JavaDoc jLabelBaseDir;
570     private javax.swing.JLabel JavaDoc jLabelHomeDir;
571     private javax.swing.JLabel JavaDoc jLabelPassword;
572     private javax.swing.JLabel JavaDoc jLabelUsername;
573     private javax.swing.JPanel JavaDoc jPanel1;
574     private javax.swing.JPanel JavaDoc jPanel2;
575     private javax.swing.JTextField JavaDoc jTextFieldBaseDir;
576     private javax.swing.JTextField JavaDoc jTextFieldHomeDir;
577     private javax.swing.JPasswordField JavaDoc jTextFieldPassword;
578     private javax.swing.JTextField JavaDoc jTextFieldUsername;
579     // End of variables declaration//GEN-END:variables
580

581 }
582
Popular Tags