KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > deployer > GeneralPanel


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.common.deployer;
24
25 // AddinCore
26
import org.enhydra.kelp.common.PathUtil;
27 import org.enhydra.kelp.common.event.WriteEvent;
28 import org.enhydra.kelp.common.event.WriteListener;
29 import org.enhydra.kelp.common.node.OtterProject;
30 import org.enhydra.kelp.common.swing.OutputPanel;
31 import org.enhydra.kelp.common.DirectoryFilter;
32
33 // ToolBox
34
import org.enhydra.tool.common.DataValidationException;
35 import org.enhydra.tool.common.ExtensionFilter;
36 import org.enhydra.tool.common.PathHandle;
37 import org.enhydra.tool.common.SwingUtil;
38 //Dusan 24.11.2002.
39
import org.enhydra.tool.common.ExtensionFilter;
40 import org.enhydra.tool.common.PathHandle;
41
42 // JDK
43
import java.awt.*;
44 import java.awt.event.ActionEvent JavaDoc;
45 import java.awt.event.ActionListener JavaDoc;
46 import java.awt.event.ItemEvent JavaDoc;
47 import java.awt.event.ItemListener JavaDoc;
48 import java.io.File JavaDoc;
49 import java.io.PrintWriter JavaDoc;
50 import java.lang.ref.WeakReference JavaDoc;
51 import javax.swing.*;
52 import javax.swing.border.EtchedBorder JavaDoc;
53 import javax.swing.border.TitledBorder JavaDoc;
54 import javax.swing.event.ChangeEvent JavaDoc;
55 import javax.swing.event.ChangeListener JavaDoc;
56 import java.beans.*;
57
58 //Dusan 24.11.2002.
59
// Standard imports
60
import java.awt.event.*;
61 import java.io.File JavaDoc;
62 import java.util.ResourceBundle JavaDoc;
63 // Kelp imports
64
import org.enhydra.kelp.common.Constants;
65 import org.enhydra.kelp.common.node.OtterNode;
66 import org.enhydra.kelp.common.node.OtterFileNode;
67
68 //
69
public class GeneralPanel extends JPanel implements Instructor, DeployStep {
70
71     static ResourceBundle JavaDoc res =
72         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
73
private GridBagLayout layoutMain;
74     private JCheckBox checkDeployBuild;
75     private JPanel panelDeployRoot;
76     private GridBagLayout layoutDeployRoot;
77     private JTextField textDeployRoot;
78     private JButton buttonDeployRoot;
79     private JPanel panelMessage;
80     private JPanel panelFiller;
81     private JCheckBox checkWriteMessage;
82     private JTextField textOutputFilename;
83     private JButton buttonMessage;
84     private JCheckBox checkEcho;
85     private JCheckBox checkOverwrite;
86     private JTabbedPane tabMessage;
87     private JPanel panelMessageOption;
88     private OutputPanel outputPanel;
89     private GridBagLayout layoutMessageOption;
90     private BorderLayout layoutMessage;
91     private LocalButtonListener buttonListener = null;
92     private LocalCheckListener checkListener = null;
93     private LocalComboListener comboListener = null;
94     private boolean ran = false;
95     private JPanel panelType;
96     private JComboBox comboType;
97     private WeakReference JavaDoc projectRef = null;
98     private GridBagLayout layoutType;
99
100     public GeneralPanel() {
101         try {
102             jbInit();
103             pmInit();
104         } catch (Exception JavaDoc e) {
105             e.printStackTrace();
106         }
107     }
108
109     // implements Instructor
110
public String JavaDoc getTab() {
111         return "General";
112     }
113
114     // implements Instructor
115
public String JavaDoc getTitle() {
116         return "General deployment options";
117     }
118
119     // implements Instructor
120
public String JavaDoc getInstructions() {
121         return "Messaging options control how status messages are handled during deployment.";
122     }
123
124     // implements DeployStep
125
public void refresh() {
126
127         // nothing to refresh
128
}
129
130     // implements DeployStep
131
public void clearAll() {
132         buttonDeployRoot.removeActionListener(buttonListener);
133         buttonMessage.removeActionListener(buttonListener);
134         checkWriteMessage.removeChangeListener(checkListener);
135         outputPanel.clearAll();
136         removeAll();
137         buttonListener = null;
138         checkListener = null;
139     }
140
141     // implements DeployStep
142
public boolean isDataValid() {
143         return DeployStepUtil.isDataValid(this);
144     }
145
146     // implements DeployStep
147
public boolean isDataEqual(OtterProject project) {
148         PathHandle projectPath = null;
149         PathHandle panelPath = null;
150         boolean equal = true;
151
152         projectRef = new WeakReference JavaDoc(project);
153         if (project == null) {
154             System.err.println("GeneralPanel.isDataEqual() - project null");
155             return true;
156         } else if (checkOverwrite.isSelected()
157                    != project.isDeployOverwrite()) {
158             equal = false;
159         } else if (checkEcho.isSelected() != project.isDeployEcho()) {
160             equal = false;
161         } else if (checkDeployBuild.isSelected() != project.isDeployBuild()) {
162             equal = false;
163         }
164         if (equal) {
165             projectPath =
166                 PathHandle.createPathHandle(project.getOutputFilename());
167             panelPath =
168                 PathHandle.createPathHandle(textOutputFilename.getText());
169             if (!projectPath.equals(panelPath)) {
170                 equal = false;
171             }
172         }
173         if (equal) {
174             projectPath =
175                 PathHandle.createPathHandle(project.getDeployRootPath());
176             panelPath = PathHandle.createPathHandle(textDeployRoot.getText());
177             if (!projectPath.equals(panelPath)) {
178                 equal = false;
179             }
180         }
181         return equal;
182     }
183
184     // implements DeployStep
185
public void validateData() throws DataValidationException {
186         PathHandle path = null;
187
188         if (checkWriteMessage.isSelected()) {
189             path = PathHandle.createPathHandle(textOutputFilename.getText());
190             if (!isValidLogFile(path)) {
191                 throw new DataValidationException("Invalid message log: "
192                                                   + path.getPath());
193             }
194         }
195         path = PathHandle.createPathHandle(textDeployRoot.getText());
196         if (!path.getPath().equals(textDeployRoot.getText())) {
197             throw new DataValidationException("Invalid deploy root: "
198                                               + textDeployRoot.getText());
199         }
200         if (!isValidDeployRoot(path)) {
201             throw new DataValidationException("Invalid deploy root: "
202                                               + textDeployRoot.getText());
203         }
204     }
205
206     // implements DeployStep
207
public boolean isBuilt(OtterProject project) {
208         projectRef = new WeakReference JavaDoc(project);
209         ran = DeployStepUtil.isBuilt(this, ran, project);
210         return ran;
211     }
212
213     // implements DeployStep
214
public boolean isSelectable(OtterProject project, DeployStep[] steps) {
215         projectRef = new WeakReference JavaDoc(project);
216         return true;
217     }
218
219     // implements DeployStep
220
public void build(OtterProject project,
221                       WriteListener listener) throws DataValidationException {
222         projectRef = new WeakReference JavaDoc(project);
223         if (!isBuilt(project)) {
224             write(project);
225             DeployBuilder.preBuild(this, project, listener);
226             ran = true;
227         }
228     }
229
230     // implements DeployStep
231
public void read(OtterProject project) {
232         PathHandle path = null;
233         int type = -1;
234
235         projectRef = new WeakReference JavaDoc(project);
236         checkOverwrite.setSelected(project.isDeployOverwrite());
237         checkEcho.setSelected(project.isDeployEcho());
238         checkDeployBuild.setSelected(project.isDeployBuild());
239         type = project.getDeployType();
240         if ((type > -1) && (type < comboType.getItemCount())) {
241             comboType.setSelectedIndex(type);
242         }
243         path = PathHandle.createPathHandle(project.getOutputFilename());
244         if (isValidLogFile(path)) {
245             checkWriteMessage.setSelected(true);
246             textOutputFilename.setText(path.getPath());
247         } else {
248             checkWriteMessage.setSelected(false);
249             textOutputFilename.setText(new String JavaDoc());
250         }
251         textOutputFilename.setToolTipText(textOutputFilename.getText());
252         path = PathHandle.createPathHandle(project.getDeployRootPath());
253         if (isValidDeployRoot(path)) {
254             textDeployRoot.setText(path.getPath());
255         } else {
256             textDeployRoot.setText(new String JavaDoc());
257         }
258         textDeployRoot.setToolTipText(textDeployRoot.getText());
259     }
260
261     // implements DeployStep
262
public void write(OtterProject project) throws DataValidationException {
263         projectRef = new WeakReference JavaDoc(project);
264         validateData();
265         if (!isDataEqual(project)) {
266             project.setDeployOverwrite(checkOverwrite.isSelected());
267             project.setDeployEcho(checkEcho.isSelected());
268             if (checkWriteMessage.isSelected()) {
269                 project.setOutputFilename(PathHandle.createPathString(textOutputFilename.getText()));
270             }
271             project.setDeployRootPath(PathHandle.createPathString(textDeployRoot.getText()));
272             project.setDeployBuild(checkDeployBuild.isSelected());
273
274             // deploy type auto-updated
275
}
276     }
277
278     //
279
protected WriteListener getWriteListener() {
280         return outputPanel;
281     }
282
283     protected Component[] getFirstFocusComponents() {
284         Component[] comps = new Component[6];
285
286         comps[0] = buttonDeployRoot;
287         comps[1] = tabMessage;
288         comps[2] = checkDeployBuild;
289         comps[3] = checkWriteMessage;
290         comps[4] = checkEcho;
291         comps[5] = checkOverwrite;
292         return comps;
293     }
294
295     //
296
private boolean isValidDeployRoot(PathHandle ph) {
297         boolean valid = false;
298
299         if (!ph.isFile()) {
300             if (ph.getParent() != null) {
301                 valid = ph.getParent().isDirectory();
302             }
303         }
304         return valid;
305     }
306
307     private boolean isValidLogFile(PathHandle ph) {
308         boolean valid = false;
309
310         if (ph.hasExtension("txt")) {
311             if (ph.isFile()) {
312                 valid = true;
313             } else if (ph.getParent() != null) {
314                 valid = ph.getParent().isDirectory();
315             }
316         }
317         return valid;
318     }
319
320
321 //Dusan 24.11.2002.
322
/* private void chooseDeployRoot() {
323         File choice = null;
324         PathHandle path = null;
325
326         choice =
327             SwingUtil.getDirectoryChoice(this, textDeployRoot.getText(),
328                                          "Select deployment root directory");
329         path = PathHandle.createPathHandle(choice);
330         if (path.isDirectory()) {
331             textDeployRoot.setText(path.getPath());
332             textDeployRoot.setToolTipText(textDeployRoot.getText());
333         }
334     }
335 */

336     private void chooseMessageFile() {
337         File JavaDoc choice = null;
338         PathHandle path = null;
339         ExtensionFilter filter = null;
340
341         filter = new ExtensionFilter();
342         filter.setDescriptionTitle("Message Log");
343         filter.addExtension("txt");
344         choice =
345             SwingUtil.getFileChoice(this, textOutputFilename.getText(),
346                                     filter,
347                                     "Select or enter a message log file");
348         path = PathHandle.createPathHandle(choice);
349         if (!path.isDirectory()) {
350             if (!path.hasExtension("txt")) {
351                 path.setExtension("txt");
352             }
353             textOutputFilename.setText(path.getPath());
354             textOutputFilename.setToolTipText(textOutputFilename.getText());
355         }
356     }
357
358     private void checkWriteRefresh() {
359         boolean write = checkWriteMessage.isSelected();
360
361         buttonMessage.setEnabled(write);
362         if (write) {
363             textOutputFilename.setBackground(SystemColor.info);
364         } else {
365             textOutputFilename.setBackground(SystemColor.control);
366         }
367     }
368
369     private void pmInit() {
370         buttonListener = new LocalButtonListener();
371         buttonDeployRoot.addActionListener(buttonListener);
372         buttonMessage.addActionListener(buttonListener);
373
374         //
375
checkListener = new LocalCheckListener();
376         checkWriteMessage.addChangeListener(checkListener);
377         outputPanel.setRows(4);
378
379         //
380
comboListener = new LocalComboListener();
381         comboType.removeAllItems();
382         comboType.addItem("Web Application");
383 // comboType.addItem("Enhydra Service");
384
comboType.addItem("Enhydra Application");
385         comboType.setSelectedIndex(0);
386         comboType.addItemListener(comboListener);
387     }
388
389     private void jbInit() throws Exception JavaDoc {
390         panelDeployRoot =
391             (JPanel) Beans.instantiate(getClass().getClassLoader(),
392                                        JPanel.class.getName());
393         layoutDeployRoot =
394             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
395                                               GridBagLayout.class.getName());
396
397         textDeployRoot =
398             (JTextField) Beans.instantiate(getClass().getClassLoader(),
399                                            JTextField.class.getName());
400         buttonDeployRoot =
401             (JButton) Beans.instantiate(getClass().getClassLoader(),
402                                         JButton.class.getName());
403         panelMessage = (JPanel) Beans.instantiate(getClass().getClassLoader(),
404                                                   JPanel.class.getName());
405         panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(),
406                                                  JPanel.class.getName());
407         checkWriteMessage =
408             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
409                                           JCheckBox.class.getName());
410         checkOverwrite =
411             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
412                                           JCheckBox.class.getName());
413         textOutputFilename =
414             (JTextField) Beans.instantiate(getClass().getClassLoader(),
415                                            JTextField.class.getName());
416         buttonMessage =
417             (JButton) Beans.instantiate(getClass().getClassLoader(),
418                                         JButton.class.getName());
419         checkEcho = (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
420                                                   JCheckBox.class.getName());
421         checkDeployBuild =
422             (JCheckBox) Beans.instantiate(getClass().getClassLoader(),
423                                           JCheckBox.class.getName());
424         layoutMain =
425             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
426                                               GridBagLayout.class.getName());
427         tabMessage =
428             (JTabbedPane) Beans.instantiate(getClass().getClassLoader(),
429                                             JTabbedPane.class.getName());
430         panelMessageOption =
431             (JPanel) Beans.instantiate(getClass().getClassLoader(),
432                                        JPanel.class.getName());
433         outputPanel =
434             (OutputPanel) Beans.instantiate(getClass().getClassLoader(),
435                                             OutputPanel.class.getName());
436         layoutMessageOption =
437             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
438                                               GridBagLayout.class.getName());
439         layoutMessage =
440             (BorderLayout) Beans.instantiate(getClass().getClassLoader(),
441                                              BorderLayout.class.getName());
442         panelType = (JPanel) Beans.instantiate(getClass().getClassLoader(),
443                                                JPanel.class.getName());
444         comboType = (JComboBox) Beans.instantiate(getClass().getClassLoader(),
445                                                   JComboBox.class.getName());
446         layoutType =
447             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
448                                               GridBagLayout.class.getName());
449         checkDeployBuild.setText("Deploy during project make/rebuild");
450         textDeployRoot.setEnabled(false);
451         textDeployRoot.setEditable(false);
452         textDeployRoot.setText("DEPLOY ROOT");
453         buttonDeployRoot.setText("...");
454         checkWriteMessage.setText("Write to file");
455         textOutputFilename.setEnabled(false);
456         textOutputFilename.setEditable(false);
457         textOutputFilename.setText("MESSAGE LOG");
458         buttonMessage.setText("...");
459         checkEcho.setText("Display during project make/rebuild");
460         panelDeployRoot.setLayout(layoutDeployRoot);
461         panelDeployRoot.setBorder(BorderFactory.createTitledBorder(new EtchedBorder JavaDoc(),
462                 "Deploy root"));
463         checkOverwrite.setText("Overwrite without warning");
464         panelMessageOption.setLayout(layoutMessageOption);
465         panelType.setLayout(layoutType);
466         panelDeployRoot.add(textDeployRoot,
467                             new GridBagConstraints(0, 0, 1, 1, 0.8, 0.0,
468                                                    GridBagConstraints.WEST,
469                                                    GridBagConstraints.HORIZONTAL,
470                                                    new Insets(3, 5, 3, 5), 0,
471                                                    0));
472         panelDeployRoot.add(buttonDeployRoot,
473                             new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
474                                                    GridBagConstraints.CENTER,
475                                                    GridBagConstraints.NONE,
476                                                    new Insets(3, 5, 3, 5), 0,
477                                                    0));
478         panelMessage.setLayout(layoutMessage);
479         panelMessage.setBorder(BorderFactory.createTitledBorder(new EtchedBorder JavaDoc(),
480                 "Deploy messages"));
481         panelMessageOption.add(checkWriteMessage,
482                                new GridBagConstraints(0, 2, 2, 1, 0.1, 0.0,
483                                GridBagConstraints.WEST,
484                                GridBagConstraints.HORIZONTAL,
485                                new Insets(0, 5, 2, 5), 0, 0));
486         panelMessageOption.add(textOutputFilename,
487                                new GridBagConstraints(0, 3, 1, 1, 0.9, 0.0,
488                                GridBagConstraints.CENTER,
489                                GridBagConstraints.HORIZONTAL,
490                                new Insets(2, 5, 3, 5), 0, 0));
491         panelMessageOption.add(buttonMessage,
492                                new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
493                                GridBagConstraints.CENTER,
494                                GridBagConstraints.NONE,
495                                new Insets(2, 5, 3, 5), 0, 0));
496         panelMessageOption.add(checkEcho,
497                                new GridBagConstraints(0, 1, 2, 1, 0.1, 0.0,
498                                GridBagConstraints.CENTER,
499                                GridBagConstraints.HORIZONTAL,
500                                new Insets(3, 5, 3, 5), 0, 0));
501         panelMessage.add(tabMessage, BorderLayout.CENTER);
502         tabMessage.add(outputPanel, "Messages");
503         tabMessage.add(panelMessageOption, "Options");
504         panelType.setBorder((BorderFactory.createTitledBorder(new EtchedBorder JavaDoc(),
505                 "Deploy type")));
506         panelType.add(comboType,
507                       new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0,
508                                              GridBagConstraints.CENTER,
509                                              GridBagConstraints.HORIZONTAL,
510                                              new Insets(2, 5, 2, 5), 0, 0));
511         this.setLayout(layoutMain);
512         this.add(panelFiller,
513                  new GridBagConstraints(0, 6, 1, 1, 0.1, 0.01,
514                                         GridBagConstraints.CENTER,
515                                         GridBagConstraints.BOTH,
516                                         new Insets(0, 0, 0, 0), 0, 0));
517         this.add(checkDeployBuild,
518                  new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
519                                         GridBagConstraints.WEST,
520                                         GridBagConstraints.HORIZONTAL,
521                                         new Insets(2, 10, 2, 10), 0, 0));
522         this.add(panelMessage,
523                  new GridBagConstraints(0, 2, 2, 1, 0.1, 0.0,
524                                         GridBagConstraints.CENTER,
525                                         GridBagConstraints.HORIZONTAL,
526                                         new Insets(2, 5, 2, 5), 0, 0));
527         this.add(panelDeployRoot,
528                  new GridBagConstraints(0, 0, 2, 1, 0.1, 0.0,
529                                         GridBagConstraints.CENTER,
530                                         GridBagConstraints.HORIZONTAL,
531                                         new Insets(2, 5, 2, 5), 0, 0));
532         this.add(checkOverwrite,
533                  new GridBagConstraints(1, 3, 1, 1, 0.1, 0.0,
534                                         GridBagConstraints.CENTER,
535                                         GridBagConstraints.HORIZONTAL,
536                                         new Insets(2, 10, 2, 10), 0, 0));
537         this.add(panelType,
538                  new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0,
539                                         GridBagConstraints.CENTER,
540                                         GridBagConstraints.HORIZONTAL,
541                                         new Insets(2, 5, 2, 5), 2, 0));
542     }
543
544     //
545
private class LocalCheckListener implements ChangeListener JavaDoc {
546         public void stateChanged(ChangeEvent JavaDoc e) {
547             Object JavaDoc source = e.getSource();
548
549             if (source == checkWriteMessage) {
550                 checkWriteRefresh();
551             }
552         }
553
554     }
555
556     //
557
private class LocalButtonListener implements ActionListener JavaDoc {
558         public void actionPerformed(ActionEvent JavaDoc event) {
559             Object JavaDoc source = event.getSource();
560
561             if (source == buttonDeployRoot) {
562 //Dusan 24.11.2002.
563
// chooseDeployRoot();
564
browseForDirectory();
565             } else if (source == buttonMessage) {
566                 chooseMessageFile();
567             }
568         }
569
570     }
571     private void saveType() {
572         OtterProject project = null;
573         int newType = OtterProject.TYPE_UNKNOWN;
574         int oldType = OtterProject.TYPE_UNKNOWN;
575
576         if (projectRef != null) {
577             project = (OtterProject) projectRef.get();
578             newType = comboType.getSelectedIndex();
579             oldType = project.getDeployType();
580             if (newType != oldType) {
581 //Dusan
582
// project.setDeployType(newType);
583
//Dusan
584
/* if (newType == OtterProject.TYPE_SERVICE) {
585                     project.setDeployContent(false);
586                     project.setDeployInput(false);
587                 } else if (oldType == OtterProject.TYPE_SERVICE) {
588                     project.setDeployContent(true);
589                     project.setDeployInput(true);
590                 } */

591
592 //Dusan
593
if (newType == OtterProject.TYPE_WEBAPP) {
594                   comboType.setSelectedIndex(1);
595                 } else if (oldType == OtterProject.TYPE_EN3APP) {
596                     project.setDeployType(newType);
597                     project.setDeployContent(false);
598                     project.setDeployInput(false);
599                 }
600
601                 project.setDeployBootstrapPath(PathUtil.getAutoDeployPath(newType));
602             }
603         }
604     }
605
606     private class LocalComboListener implements ItemListener JavaDoc {
607         public void itemStateChanged(ItemEvent JavaDoc event) {
608             if (event.getStateChange() == ItemEvent.SELECTED) {
609                 saveType();
610             }
611         }
612
613     }
614
615     /**
616      * Method declaration
617      *
618      */

619     private void browseForDirectory() {
620         JFileChooser chooser;
621         File JavaDoc file;
622         String JavaDoc fileDir = new String JavaDoc();
623         String JavaDoc fileName = new String JavaDoc();
624
625         chooser = new JFileChooser();
626         if (textDeployRoot.getText().trim().length() > 0) {
627             chooser.setCurrentDirectory(new File JavaDoc(textDeployRoot.getText()));
628         } else {
629             PathHandle ph = null;
630
631             chooser.setCurrentDirectory(new File JavaDoc(""));
632         }
633         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
634         chooser.setFileFilter((javax.swing.filechooser.FileFilter JavaDoc) new DirectoryFilter());
635         chooser.setDialogTitle(res.getString("chooser_DeployRoot_DialogTitle"));
636         chooser.setApproveButtonText(res.getString("OK"));
637         int v = chooser.showOpenDialog(this);
638
639         this.requestFocus();
640         buttonDeployRoot.requestFocus();
641         if (v == JFileChooser.APPROVE_OPTION) {
642             if (chooser.getSelectedFile() == null) {
643                 textDeployRoot.setText(new String JavaDoc());
644             } else {
645                 fileDir = chooser.getCurrentDirectory().toString();
646                 fileDir = stripSlash(fileDir);
647                 fileName = chooser.getSelectedFile().getName();
648                 String JavaDoc strDeployRoot = fileDir + File.separator + fileName;
649                 textDeployRoot.setText(strDeployRoot.replace('\\','/'));
650             }
651         }
652         chooser.removeAll();
653         chooser = null;
654     }
655
656     /**
657      * Method declaration
658      *
659      *
660      * @param dir
661      *
662      * @return
663      */

664     private String JavaDoc stripSlash(String JavaDoc dir) {
665         String JavaDoc stripped = new String JavaDoc(dir);
666
667         if (dir != null) {
668             if (dir.length() > 0) {
669                 if (dir.endsWith(File.separator)) {
670                     stripped = dir.substring(0, dir.length() - 1);
671                 }
672             }
673         }
674         return stripped;
675     }
676 }
677
Popular Tags