KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > ui > wizards > PanelSourceFolders


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.j2ee.clientproject.ui.wizards;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.io.File JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.text.MessageFormat JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Enumeration JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import javax.swing.JFileChooser 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.openide.DialogDisplayer;
36 import org.openide.ErrorManager;
37 import org.openide.NotifyDescriptor;
38 import org.openide.WizardDescriptor;
39 import org.openide.WizardValidationException;
40 import org.openide.filesystems.FileObject;
41 import org.openide.filesystems.FileUtil;
42 import org.openide.util.HelpCtx;
43 import org.openide.util.NbBundle;
44
45 //XXX There should be a way how to add nonexistent test dir
46

47 /**
48  * Sets up name and location for new Java project from existing sources.
49  * @author Tomas Zezula et al.
50  */

51 public class PanelSourceFolders extends SettingsPanel implements PropertyChangeListener JavaDoc {
52
53     private final Panel firer;
54     private WizardDescriptor wizardDescriptor;
55     private File JavaDoc oldProjectLocation;
56     
57     private final DocumentListener JavaDoc configFilesDocumentListener = new DocumentListener JavaDoc() {
58         public void changedUpdate(DocumentEvent JavaDoc e) {
59             configFilesChanged();
60         }
61         
62         public void insertUpdate(DocumentEvent JavaDoc e) {
63             configFilesChanged();
64         }
65         
66         public void removeUpdate(DocumentEvent JavaDoc e) {
67             configFilesChanged();
68         }
69     };
70
71     /** Creates new form PanelSourceFolders */
72     public PanelSourceFolders (Panel panel) {
73         this.firer = panel;
74         initComponents();
75         this.setName(NbBundle.getMessage(PanelSourceFolders.class,"LAB_ConfigureSourceRoots"));
76         this.putClientProperty ("NewProjectWizard_Title", NbBundle.getMessage(PanelSourceFolders.class,"TXT_ImportAppClientModule")); // NOI18N
77
this.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PanelSourceFolders.class,"AN_PanelSourceFolders"));
78         this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PanelSourceFolders.class,"AD_PanelSourceFolders"));
79         this.sourcePanel.addPropertyChangeListener (this);
80         this.testsPanel.addPropertyChangeListener(this);
81         ((FolderList)this.sourcePanel).setRelatedFolderList((FolderList)this.testsPanel);
82         ((FolderList)this.testsPanel).setRelatedFolderList((FolderList)this.sourcePanel);
83         this.jTextFieldConfigFiles.getDocument().addDocumentListener(configFilesDocumentListener);
84     }
85
86     public void initValues(FileObject fo) {
87         ((FolderList) this.sourcePanel).setLastUsedDir(FileUtil.toFile(fo));
88         ((FolderList) this.testsPanel).setLastUsedDir(FileUtil.toFile(fo));
89
90         FileObject confFO = FileSearchUtility.guessConfigFilesPath(fo);
91         if (confFO == null) { // without deployment descriptor
92
// XXX guess appropriate conf. folder
93
} else {
94             String JavaDoc configFiles = FileUtil.toFile(confFO).getAbsolutePath();
95             jTextFieldConfigFiles.setText(configFiles);
96         }
97         FileObject librariesFO = FileSearchUtility.guessLibrariesFolder(fo);
98         if (librariesFO != null) {
99             String JavaDoc libraries = FileUtil.toFile(librariesFO).getAbsolutePath();
100             jTextFieldLibraries.setText(libraries);
101         }
102     }
103
104     
105     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
106         if (FolderList.PROP_FILES.equals(evt.getPropertyName())) {
107             this.dataChanged();
108         } else if (FolderList.PROP_LAST_USED_DIR.equals (evt.getPropertyName())) {
109             if (evt.getSource() == this.sourcePanel) {
110                 ((FolderList)this.testsPanel).setLastUsedDir
111                         ((File JavaDoc)evt.getNewValue());
112             }
113             else if (evt.getSource() == this.testsPanel) {
114                 ((FolderList)this.sourcePanel).setLastUsedDir
115                         ((File JavaDoc)evt.getNewValue());
116             }
117         }
118     }
119
120     private void dataChanged () {
121         this.firer.fireChangeEvent();
122     }
123
124
125     void read (WizardDescriptor settings) {
126         this.wizardDescriptor = settings;
127         
128         // #56706: only reinitialize the locations on the panel if the user changed the project location
129
File JavaDoc projectLocation = (File JavaDoc) settings.getProperty(WizardProperties.SOURCE_ROOT);
130         ((FolderList)this.sourcePanel).setProjectFolder(projectLocation);
131         ((FolderList)this.testsPanel).setProjectFolder(projectLocation);
132         if (!projectLocation.equals(oldProjectLocation)) {
133             File JavaDoc[] srcRoot = (File JavaDoc[]) settings.getProperty (WizardProperties.JAVA_ROOT); //NOI18N
134
if (srcRoot!=null) {
135                 ((FolderList)this.sourcePanel).setFiles(srcRoot);
136             }
137             File JavaDoc[] testRoot = (File JavaDoc[]) settings.getProperty (WizardProperties.TEST_ROOT); //NOI18N
138
if (testRoot != null) {
139                 ((FolderList)this.testsPanel).setFiles (testRoot);
140             }
141             initValues(FileUtil.toFileObject(projectLocation));
142             oldProjectLocation = projectLocation;
143         }
144     }
145
146     void store (WizardDescriptor settings) {
147         File JavaDoc[] sourceRoots = ((FolderList)this.sourcePanel).getFiles();
148         File JavaDoc[] testRoots = ((FolderList)this.testsPanel).getFiles();
149         settings.putProperty (WizardProperties.JAVA_ROOT,sourceRoots); //NOI18N
150
settings.putProperty(WizardProperties.TEST_ROOT,testRoots); //NOI18N
151
String JavaDoc configFiles = jTextFieldConfigFiles.getText().trim();
152         if (configFiles.length() > 0) {
153             settings.putProperty(WizardProperties.CONFIG_FILES_FOLDER, new File JavaDoc(configFiles));
154         } else {
155             settings.putProperty(WizardProperties.CONFIG_FILES_FOLDER, null);
156         }
157         String JavaDoc libPath = jTextFieldLibraries.getText().trim();
158         if (libPath != null && !libPath.equals("")) {
159             settings.putProperty(WizardProperties.LIB_FOLDER, new File JavaDoc(libPath));
160         }
161     }
162     
163     boolean valid (WizardDescriptor settings) {
164         File JavaDoc projectLocation = (File JavaDoc) settings.getProperty (WizardProperties.PROJECT_DIR); //NOI18N
165
String JavaDoc confFolder = jTextFieldConfigFiles.getText().trim();
166         if (confFolder.length() == 0) {
167             wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
168
NbBundle.getMessage(PanelSourceFolders.class, "MSG_BlankConfigurationFilesFolder"));
169             return false;
170         }
171         File JavaDoc[] sourceRoots = ((FolderList)this.sourcePanel).getFiles();
172         File JavaDoc[] testRoots = ((FolderList)this.testsPanel).getFiles();
173         String JavaDoc result = checkValidity (projectLocation, getConfigFiles(), sourceRoots, testRoots);
174         if (result == null) {
175             wizardDescriptor.putProperty( "WizardPanel_errorMessage"," "); //NOI18N
176
return true;
177         }
178         else {
179             wizardDescriptor.putProperty( "WizardPanel_errorMessage",result); //NOI18N
180
return false;
181         }
182     }
183
184     static String JavaDoc checkValidity (final File JavaDoc projectLocation, final File JavaDoc configFilesLocation, final File JavaDoc[] sources, final File JavaDoc[] tests ) {
185         String JavaDoc ploc = projectLocation.getAbsolutePath ();
186         if (configFilesLocation != null) {
187             FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(configFilesLocation));
188             if (fo == null || !fo.isFolder()) {
189                 return NbBundle.getMessage(PanelSourceFolders.class, "MSG_IllegalConfigurationFilesFolder");
190             }
191         }
192         if (sources.length ==0) {
193             return " "; //NOI18N
194
}
195         for (int i=0; i<sources.length;i++) {
196             if (!sources[i].isDirectory() || !sources[i].canRead()) {
197                 return MessageFormat.format(NbBundle.getMessage(PanelSourceFolders.class,"MSG_IllegalSources"),
198                         new Object JavaDoc[] {sources[i].getAbsolutePath()});
199             }
200             String JavaDoc sloc = sources[i].getAbsolutePath ();
201             if (ploc.equals (sloc) || ploc.startsWith (sloc + File.separatorChar)) {
202                 return NbBundle.getMessage(PanelSourceFolders.class,"MSG_IllegalProjectFolder");
203             }
204         }
205         for (int i=0; i<tests.length; i++) {
206             if (!tests[i].isDirectory() || !tests[i].canRead()) {
207                 return MessageFormat.format(NbBundle.getMessage(PanelSourceFolders.class,"MSG_IllegalTests"),
208                         new Object JavaDoc[] {sources[i].getAbsolutePath()});
209             }
210             String JavaDoc tloc = tests[i].getAbsolutePath();
211             if (ploc.equals(tloc) || ploc.startsWith(tloc + File.separatorChar)) {
212                 return NbBundle.getMessage(PanelSourceFolders.class,"MSG_IllegalProjectFolder");
213             }
214         }
215         return null;
216     }
217     
218     void validate (WizardDescriptor d) throws WizardValidationException {
219         // sources root
220
searchClassFiles (((FolderList)this.sourcePanel).getFiles());
221         // test root, not asked in issue 48198
222
//searchClassFiles (FileUtil.toFileObject (FileUtil.normalizeFile(new File (tests.getText ()))));
223
}
224     
225     private void searchClassFiles (File JavaDoc[] folders) throws WizardValidationException {
226         boolean found = false;
227         for (int i=0; i<folders.length; i++) {
228             FileObject folder = FileUtil.toFileObject(folders[i]);
229             if (folder != null) {
230                 Enumeration JavaDoc en = folder.getData (true);
231                 while (!found && en.hasMoreElements ()) {
232                     Object JavaDoc obj = en.nextElement ();
233                     assert obj instanceof FileObject : "Instance of FileObject: " + obj; // NOI18N
234
FileObject fo = (FileObject) obj;
235                     found = "class".equals (fo.getExt ()); // NOI18N
236
}
237             }
238         }
239         if (found) {
240             Object JavaDoc DELETE_OPTION = NbBundle.getMessage (PanelSourceFolders.class, "TXT_DeleteOption"); // NOI18N
241
Object JavaDoc KEEP_OPTION = NbBundle.getMessage (PanelSourceFolders.class, "TXT_KeepOption"); // NOI18N
242
Object JavaDoc CANCEL_OPTION = NbBundle.getMessage (PanelSourceFolders.class, "TXT_CancelOption"); // NOI18N
243
NotifyDescriptor desc = new NotifyDescriptor (
244                     NbBundle.getMessage (PanelSourceFolders.class, "MSG_FoundClassFiles"), // NOI18N
245
NbBundle.getMessage (PanelSourceFolders.class, "MSG_FoundClassFiles_Title"), // NOI18N
246
NotifyDescriptor.YES_NO_CANCEL_OPTION,
247                     NotifyDescriptor.QUESTION_MESSAGE,
248                     new Object JavaDoc[] {DELETE_OPTION, KEEP_OPTION, CANCEL_OPTION},
249                     null
250                     );
251             Object JavaDoc result = DialogDisplayer.getDefault().notify(desc);
252             if (DELETE_OPTION.equals (result)) {
253                 deleteClassFiles (folders);
254             } else if (!KEEP_OPTION.equals (result)) {
255                 // cancel, back to wizard
256
throw new WizardValidationException (this.sourcePanel, "", ""); // NOI18N
257
}
258         }
259     }
260     
261     private void deleteClassFiles (File JavaDoc[] folders) {
262         for (int i=0; i<folders.length; i++) {
263             FileObject folder = FileUtil.toFileObject(folders[i]);
264             Enumeration JavaDoc en = folder.getData (true);
265             while (en.hasMoreElements ()) {
266                 Object JavaDoc obj = en.nextElement ();
267                 assert obj instanceof FileObject : "Instance of FileObject: " + obj;
268                 FileObject fo = (FileObject) obj;
269                 try {
270                     if ("class".equals (fo.getExt ())) { // NOI18N
271
fo.delete ();
272                     }
273                 } catch (IOException JavaDoc ioe) {
274                     ErrorManager.getDefault ().notify (ioe);
275                 }
276             }
277         }
278     }
279     
280     /** This method is called from within the constructor to
281      * initialize the form.
282      * WARNING: Do NOT modify this code. The content of this method is
283      * always regenerated by the Form Editor.
284      */

285     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
286
private void initComponents() {
287         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
288
289         jLabel3 = new javax.swing.JLabel JavaDoc();
290         sourcePanel = new FolderList (NbBundle.getMessage(PanelSourceFolders.class,"CTL_SourceRoots"), NbBundle.getMessage(PanelSourceFolders.class,"MNE_SourceRoots").charAt(0),NbBundle.getMessage(PanelSourceFolders.class,"AD_SourceRoots"), NbBundle.getMessage(PanelSourceFolders.class,"CTL_AddSourceRoot"),
291             NbBundle.getMessage(PanelSourceFolders.class,"MNE_AddSourceFolder").charAt(0), NbBundle.getMessage(PanelSourceFolders.class,"AD_AddSourceFolder"),NbBundle.getMessage(PanelSourceFolders.class,"MNE_RemoveSourceFolder").charAt(0), NbBundle.getMessage(PanelSourceFolders.class,"AD_RemoveSourceFolder"));
292         testsPanel = new FolderList (NbBundle.getMessage(PanelSourceFolders.class,"CTL_TestRoots"), NbBundle.getMessage(PanelSourceFolders.class,"MNE_TestRoots").charAt(0),NbBundle.getMessage(PanelSourceFolders.class,"AD_TestRoots"), NbBundle.getMessage(PanelSourceFolders.class,"CTL_AddTestRoot"),
293             NbBundle.getMessage(PanelSourceFolders.class,"MNE_AddTestFolder").charAt(0), NbBundle.getMessage(PanelSourceFolders.class,"AD_AddTestFolder"),NbBundle.getMessage(PanelSourceFolders.class,"MNE_RemoveTestFolder").charAt(0), NbBundle.getMessage(PanelSourceFolders.class,"AD_RemoveTestFolder"));
294         jLabel1 = new javax.swing.JLabel JavaDoc();
295         jTextFieldConfigFiles = new javax.swing.JTextField JavaDoc();
296         jButtonConfigFilesLocation = new javax.swing.JButton JavaDoc();
297         jLabel2 = new javax.swing.JLabel JavaDoc();
298         jTextFieldLibraries = new javax.swing.JTextField JavaDoc();
299         jButtonLibraries = new javax.swing.JButton JavaDoc();
300
301         setLayout(new java.awt.GridBagLayout JavaDoc());
302
303         getAccessibleContext().setAccessibleName(null);
304         getAccessibleContext().setAccessibleDescription(null);
305         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(PanelSourceFolders.class, "LBL_SourceDirectoriesLabel"));
306         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
307         gridBagConstraints.gridy = 0;
308         gridBagConstraints.gridwidth = 3;
309         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
310         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
311         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
312         add(jLabel3, gridBagConstraints);
313         jLabel3.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelSourceFolders.class).getString("ACSN_jLabel3"));
314         jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelSourceFolders.class).getString("ACSD_jLabel3"));
315
316         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
317         gridBagConstraints.gridy = 3;
318         gridBagConstraints.gridwidth = 3;
319         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
320         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
321         gridBagConstraints.weightx = 1.0;
322         gridBagConstraints.weighty = 0.45;
323         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
324         add(sourcePanel, gridBagConstraints);
325
326         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
327         gridBagConstraints.gridy = 4;
328         gridBagConstraints.gridwidth = 3;
329         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
330         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
331         gridBagConstraints.weightx = 1.0;
332         gridBagConstraints.weighty = 0.45;
333         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
334         add(testsPanel, gridBagConstraints);
335
336         jLabel1.setLabelFor(jTextFieldConfigFiles);
337         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/clientproject/ui/wizards/Bundle").getString("LBL_IW_ConfigFilesFolder_Label"));
338         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
339         gridBagConstraints.gridx = 0;
340         gridBagConstraints.gridy = 1;
341         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
342         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
343         add(jLabel1, gridBagConstraints);
344
345         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
346         gridBagConstraints.gridx = 1;
347         gridBagConstraints.gridy = 1;
348         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
349         gridBagConstraints.weightx = 1.0;
350         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
351         add(jTextFieldConfigFiles, gridBagConstraints);
352
353         org.openide.awt.Mnemonics.setLocalizedText(jButtonConfigFilesLocation, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/clientproject/ui/wizards/Bundle").getString("LBL_NWP1_BrowseLocation_Button_w"));
354         jButtonConfigFilesLocation.addActionListener(new java.awt.event.ActionListener JavaDoc() {
355             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
356                 jButtonConfigFilesLocationActionPerformed(evt);
357             }
358         });
359
360         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
361         gridBagConstraints.gridx = 2;
362         gridBagConstraints.gridy = 1;
363         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
364         add(jButtonConfigFilesLocation, gridBagConstraints);
365
366         jLabel2.setLabelFor(jTextFieldLibraries);
367         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/clientproject/ui/wizards/Bundle").getString("LBL_IW_LibrariesLocation_Label"));
368         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
369         gridBagConstraints.gridx = 0;
370         gridBagConstraints.gridy = 2;
371         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
372         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
373         add(jLabel2, gridBagConstraints);
374
375         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
376         gridBagConstraints.gridx = 1;
377         gridBagConstraints.gridy = 2;
378         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
379         gridBagConstraints.weightx = 1.0;
380         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
381         add(jTextFieldLibraries, gridBagConstraints);
382
383         org.openide.awt.Mnemonics.setLocalizedText(jButtonLibraries, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/clientproject/ui/wizards/Bundle").getString("LBL_NWP1_BrowseLocation_Button"));
384         jButtonLibraries.addActionListener(new java.awt.event.ActionListener JavaDoc() {
385             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
386                 jButtonLibrariesActionPerformed(evt);
387             }
388         });
389
390         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
391         gridBagConstraints.gridx = 2;
392         gridBagConstraints.gridy = 2;
393         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
394         add(jButtonLibraries, gridBagConstraints);
395
396     }// </editor-fold>//GEN-END:initComponents
397

398     private void jButtonLibrariesActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonLibrariesActionPerformed
399
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
400         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
401         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
402         if (jTextFieldLibraries.getText().length() > 0 && getLibraries().exists()) {
403             chooser.setSelectedFile(getLibraries());
404         } else {
405             chooser.setCurrentDirectory((File JavaDoc) wizardDescriptor.getProperty(WizardProperties.PROJECT_DIR));
406         }
407         if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
408             File JavaDoc configFilesDir = FileUtil.normalizeFile(chooser.getSelectedFile());
409             jTextFieldLibraries.setText(configFilesDir.getAbsolutePath());
410         }
411     }//GEN-LAST:event_jButtonLibrariesActionPerformed
412

413     private void jButtonConfigFilesLocationActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonConfigFilesLocationActionPerformed
414
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
415         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
416         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
417         if (jTextFieldConfigFiles.getText().length() > 0 && getConfigFiles().exists()) {
418             chooser.setSelectedFile(getConfigFiles());
419         } else {
420             chooser.setCurrentDirectory((File JavaDoc) wizardDescriptor.getProperty(WizardProperties.PROJECT_DIR));
421         }
422         if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
423             File JavaDoc configFilesDir = FileUtil.normalizeFile(chooser.getSelectedFile());
424             jTextFieldConfigFiles.setText(configFilesDir.getAbsolutePath());
425         }
426     }//GEN-LAST:event_jButtonConfigFilesLocationActionPerformed
427

428     
429     
430     // Variables declaration - do not modify//GEN-BEGIN:variables
431
private javax.swing.JButton JavaDoc jButtonConfigFilesLocation;
432     private javax.swing.JButton JavaDoc jButtonLibraries;
433     private javax.swing.JLabel JavaDoc jLabel1;
434     private javax.swing.JLabel JavaDoc jLabel2;
435     private javax.swing.JLabel JavaDoc jLabel3;
436     private javax.swing.JTextField JavaDoc jTextFieldConfigFiles;
437     private javax.swing.JTextField JavaDoc jTextFieldLibraries;
438     private javax.swing.JPanel JavaDoc sourcePanel;
439     private javax.swing.JPanel JavaDoc testsPanel;
440     // End of variables declaration//GEN-END:variables
441

442     
443     static class Panel implements WizardDescriptor.ValidatingPanel {
444         
445         private ArrayList JavaDoc<ChangeListener JavaDoc> listeners;
446         private PanelSourceFolders component;
447         private WizardDescriptor settings;
448         
449         public synchronized void removeChangeListener(ChangeListener JavaDoc l) {
450             if (this.listeners == null) {
451                 return;
452             }
453             this.listeners.remove(l);
454         }
455
456         public void addChangeListener(ChangeListener JavaDoc l) {
457             if (this.listeners == null) {
458                 this.listeners = new ArrayList JavaDoc<ChangeListener JavaDoc>();
459             }
460             this.listeners.add (l);
461         }
462
463         public void readSettings(Object JavaDoc settings) {
464             this.settings = (WizardDescriptor) settings;
465             this.component.read (this.settings);
466             // XXX hack, TemplateWizard in final setTemplateImpl() forces new wizard's title
467
// this name is used in NewProjectWizard to modify the title
468
Object JavaDoc substitute = component.getClientProperty ("NewProjectWizard_Title"); // NOI18N
469
if (substitute != null) {
470                 this.settings.putProperty ("NewProjectWizard_Title", substitute); // NOI18N
471
}
472         }
473
474         public void storeSettings(Object JavaDoc settings) {
475             this.component.store (this.settings);
476         }
477         
478         public void validate() throws WizardValidationException {
479             this.component.validate(this.settings);
480         }
481                 
482         public boolean isValid() {
483             return this.component.valid (this.settings);
484         }
485
486         public synchronized java.awt.Component JavaDoc getComponent() {
487             if (this.component == null) {
488                 this.component = new PanelSourceFolders (this);
489             }
490             return this.component;
491         }
492
493         public HelpCtx getHelp() {
494             return new HelpCtx (PanelSourceFolders.class);
495         }
496         
497         private void fireChangeEvent () {
498            Iterator JavaDoc it = null;
499            synchronized (this) {
500                if (this.listeners == null) {
501                    return;
502                }
503                it = ((ArrayList JavaDoc)this.listeners.clone()).iterator();
504            }
505            ChangeEvent JavaDoc event = new ChangeEvent JavaDoc (this);
506            while (it.hasNext()) {
507                ((ChangeListener JavaDoc)it.next()).stateChanged(event);
508            }
509         }
510                 
511     }
512
513     private File JavaDoc getAsFile(String JavaDoc filename) {
514         return FileUtil.normalizeFile(new File JavaDoc(filename));
515     }
516
517     public File JavaDoc getConfigFiles() {
518         return getAsFile(jTextFieldConfigFiles.getText());
519     }
520
521     public File JavaDoc getLibraries() {
522         return getAsFile(jTextFieldLibraries.getText());
523     }
524     
525     private void configFilesChanged() {
526         dataChanged();
527     }
528
529 }
530
Popular Tags