KickJava   Java API By Example, From Geeks To Geeks.

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

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

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

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

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

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