KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > 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.web.project.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.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
36 import org.netbeans.modules.web.project.ProjectWebModule;
37 import org.openide.DialogDisplayer;
38 import org.openide.ErrorManager;
39 import org.openide.NotifyDescriptor;
40 import org.openide.WizardDescriptor;
41 import org.openide.WizardValidationException;
42 import org.openide.filesystems.FileObject;
43 import org.openide.filesystems.FileUtil;
44 import org.openide.util.HelpCtx;
45 import org.openide.util.NbBundle;
46
47 //XXX There should be a way how to add nonexistent test dir
48

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

53 public class PanelSourceFolders extends SettingsPanel implements PropertyChangeListener JavaDoc {
54
55     private Panel firer;
56     private WizardDescriptor wizardDescriptor;
57
58     /** Creates new form PanelSourceFolders */
59     public PanelSourceFolders (Panel panel) {
60         this.firer = panel;
61         initComponents();
62         this.setName(NbBundle.getMessage(PanelSourceFolders.class,"LAB_ConfigureSourceRoots"));
63         this.putClientProperty ("NewProjectWizard_Title", NbBundle.getMessage(PanelSourceFolders.class,"TXT_WebExtSources")); // NOI18N
64
this.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PanelSourceFolders.class,"AN_PanelSourceFolders"));
65         this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PanelSourceFolders.class,"AD_PanelSourceFolders"));
66         this.sourcePanel.addPropertyChangeListener (this);
67         this.testsPanel.addPropertyChangeListener(this);
68         ((FolderList)this.sourcePanel).setRelatedFolderList((FolderList)this.testsPanel);
69         ((FolderList)this.testsPanel).setRelatedFolderList((FolderList)this.sourcePanel);
70     
71         DocumentListener JavaDoc pl = new DocumentListener JavaDoc () {
72             public void changedUpdate(DocumentEvent JavaDoc e) {
73         firer.fireChangeEvent();
74             }
75
76             public void insertUpdate(DocumentEvent JavaDoc e) {
77         firer.fireChangeEvent();
78             }
79
80             public void removeUpdate(DocumentEvent JavaDoc e) {
81         firer.fireChangeEvent();
82             }
83         };
84         jTextFieldWebPages.getDocument().addDocumentListener(pl);
85
86     }
87
88     public void initValues(FileObject fo) {
89         ((FolderList) this.sourcePanel).setLastUsedDir(FileUtil.toFile(fo));
90         ((FolderList) this.testsPanel).setLastUsedDir(FileUtil.toFile(fo));
91         
92         FileObject guessFO;
93         String JavaDoc webPages = ""; //NOI18N
94
String JavaDoc libraries = ""; //NOI18N
95
File JavaDoc javaRoots [] = null;
96         
97         guessFO = FileSearchUtility.guessDocBase(fo);
98         if (guessFO != null)
99             webPages = FileUtil.toFile(guessFO).getPath();
100         guessFO = FileSearchUtility.guessLibrariesFolder(fo);
101         if (guessFO != null)
102             libraries = FileUtil.toFile(guessFO).getPath();
103         javaRoots = FileSearchUtility.guessJavaRootsAsFiles(fo);
104         
105         //set the locations only if they weren't set before
106
if (jTextFieldWebPages.getText().trim().equals(""))
107             jTextFieldWebPages.setText(webPages);
108         if (jTextFieldLibraries.getText().trim().equals(""))
109             jTextFieldLibraries.setText(libraries);
110         
111         if (((FolderList) this.sourcePanel).getFiles().length == 0 && javaRoots.length > 0)
112             ((FolderList) this.sourcePanel).setFiles(javaRoots);
113     }
114         
115     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
116         if (FolderList.PROP_FILES.equals(evt.getPropertyName())) {
117             this.dataChanged();
118         } else if (FolderList.PROP_LAST_USED_DIR.equals (evt.getPropertyName())) {
119             if (evt.getSource() == this.sourcePanel) {
120                 ((FolderList)this.testsPanel).setLastUsedDir
121                         ((File JavaDoc)evt.getNewValue());
122             }
123             else if (evt.getSource() == this.testsPanel) {
124                 ((FolderList)this.sourcePanel).setLastUsedDir
125                         ((File JavaDoc)evt.getNewValue());
126             }
127         }
128     }
129
130     private void dataChanged () {
131         this.firer.fireChangeEvent();
132     }
133
134     void read (WizardDescriptor settings) {
135         this.wizardDescriptor = settings;
136         File JavaDoc[] srcRoot = (File JavaDoc[]) settings.getProperty (WizardProperties.JAVA_ROOT); //NOI18N
137
if (srcRoot!=null) {
138             ((FolderList)this.sourcePanel).setFiles(srcRoot);
139         }
140         File JavaDoc[] testRoot = (File JavaDoc[]) settings.getProperty (WizardProperties.TEST_ROOT); //NOI18N
141
if (testRoot != null) {
142             ((FolderList)this.testsPanel).setFiles (testRoot);
143         }
144         File JavaDoc projectLocation = (File JavaDoc) settings.getProperty(WizardProperties.SOURCE_ROOT);
145         ((FolderList)this.sourcePanel).setProjectFolder(projectLocation);
146         ((FolderList)this.testsPanel).setProjectFolder(projectLocation);
147         
148         initValues(FileUtil.toFileObject(projectLocation));
149     }
150
151     void store (WizardDescriptor settings) {
152         File JavaDoc[] sourceRoots = ((FolderList)this.sourcePanel).getFiles();
153         File JavaDoc[] testRoots = ((FolderList)this.testsPanel).getFiles();
154         settings.putProperty (WizardProperties.JAVA_ROOT,sourceRoots); //NOI18N
155
settings.putProperty(WizardProperties.TEST_ROOT,testRoots); //NOI18N
156
settings.putProperty(WizardProperties.DOC_BASE, jTextFieldWebPages.getText().trim());
157         settings.putProperty(WizardProperties.LIB_FOLDER, jTextFieldLibraries.getText().trim());
158     }
159     
160     boolean valid (WizardDescriptor settings) {
161         File JavaDoc projectLocation = (File JavaDoc) settings.getProperty (WizardProperties.PROJECT_DIR); //NOI18N
162

163     if (jTextFieldWebPages.getText().trim().length() == 0) {
164             wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(PanelSourceFolders.class, "MSG_WebPagesMandatory")); //NOI18N
165
return false;
166     }
167     
168     File JavaDoc webPages = getWebPages();
169         File JavaDoc[] sourceRoots = ((FolderList)this.sourcePanel).getFiles();
170         File JavaDoc[] testRoots = ((FolderList)this.testsPanel).getFiles();
171         String JavaDoc result = checkValidity (projectLocation, webPages, sourceRoots, testRoots);
172         if (result == null) {
173             wizardDescriptor.putProperty( "WizardPanel_errorMessage",""); //NOI18N
174
return true;
175         }
176         else {
177             wizardDescriptor.putProperty( "WizardPanel_errorMessage",result); //NOI18N
178
return false;
179         }
180     }
181
182     private String JavaDoc checkValidity (final File JavaDoc projectLocation, final File JavaDoc webPages, final File JavaDoc[] sources, final File JavaDoc[] tests) {
183         String JavaDoc ploc = projectLocation.getAbsolutePath ();
184         
185     if (projectLocation.equals(webPages))
186         return NbBundle.getMessage(PanelSourceFolders.class, "MSG_WebPagesFolderOverlapsProjectFolder"); //NOI18N
187

188     if (!webPages.exists() || !webPages.isDirectory())
189         return NbBundle.getMessage(PanelSourceFolders.class, "MSG_WebPagesFolderDoesNotExist"); //NOI18N
190

191         FileObject webInf = FileUtil.toFileObject(webPages).getFileObject(ProjectWebModule.FOLDER_WEB_INF);
192     if (webInf == null)
193         return NbBundle.getMessage(PanelSourceFolders.class, "MSG_WebInfCorrupted", webPages.getPath()); //NOI18N
194
else {
195             FileObject webXml = webInf.getFileObject(ProjectWebModule.FILE_DD);
196             
197             //#74837 - filesystem is probably not refreshed and file object for non-existing file is found
198
//rather setting to null that refreshing filesystem from a performance reason
199
if (webXml != null && !webXml.isValid())
200                 webXml = null;
201             
202             String JavaDoc j2eeLevel = (String JavaDoc) wizardDescriptor.getProperty(WizardProperties.J2EE_LEVEL);
203             if (webXml == null && (j2eeLevel.equals(J2eeModule.J2EE_13) || j2eeLevel.equals(J2eeModule.J2EE_14)))
204                 return NbBundle.getMessage(PanelSourceFolders.class, "MSG_FileNotFound", webPages.getPath()); //NOI18N
205
}
206         
207         for (int i=0; i<sources.length;i++) {
208             if (!sources[i].isDirectory() || !sources[i].canRead()) {
209                 return MessageFormat.format(NbBundle.getMessage(PanelSourceFolders.class,"MSG_IllegalSources"), //NOI18N
210
new Object JavaDoc[] {sources[i].getAbsolutePath()});
211             }
212             String JavaDoc sloc = sources[i].getAbsolutePath ();
213             if (ploc.equals (sloc) || ploc.startsWith (sloc + File.separatorChar)) {
214                 return NbBundle.getMessage(PanelSourceFolders.class,"MSG_IllegalProjectFolder"); //NOI18N
215
}
216         }
217         for (int i=0; i<tests.length; i++) {
218             if (!tests[i].isDirectory() || !tests[i].canRead()) {
219                 return MessageFormat.format(NbBundle.getMessage(PanelSourceFolders.class,"MSG_IllegalTests"), //NOI18N
220
new Object JavaDoc[] {sources[i].getAbsolutePath()});
221             }
222             String JavaDoc tloc = tests[i].getAbsolutePath();
223             if (ploc.equals(tloc) || ploc.startsWith(tloc + File.separatorChar)) {
224                 return NbBundle.getMessage(PanelSourceFolders.class,"MSG_IllegalProjectFolder"); //NOI18N
225
}
226         }
227         return null;
228     }
229     
230     void validate (WizardDescriptor d) throws WizardValidationException {
231         // sources root
232
searchClassFiles (((FolderList)this.sourcePanel).getFiles());
233         // test root, not asked in issue 48198
234
//searchClassFiles (FileUtil.toFileObject (FileUtil.normalizeFile(new File (tests.getText ()))));
235
}
236     
237     private void searchClassFiles (File JavaDoc[] folders) throws WizardValidationException {
238         boolean found = false;
239         for (int i=0; i<folders.length; i++) {
240             FileObject folder = FileUtil.toFileObject(folders[i]);
241             if (folder != null) {
242                 Enumeration JavaDoc en = folder.getData (true);
243                 while (!found && en.hasMoreElements ()) {
244                     Object JavaDoc obj = en.nextElement ();
245                     assert obj instanceof FileObject : "Instance of FileObject: " + obj; // NOI18N
246
FileObject fo = (FileObject) obj;
247                     found = "class".equals (fo.getExt ()); // NOI18N
248
}
249             }
250         }
251         if (found) {
252             Object JavaDoc DELETE_OPTION = NbBundle.getMessage (PanelSourceFolders.class, "TXT_DeleteOption"); // NOI18N
253
Object JavaDoc KEEP_OPTION = NbBundle.getMessage (PanelSourceFolders.class, "TXT_KeepOption"); // NOI18N
254
Object JavaDoc CANCEL_OPTION = NbBundle.getMessage (PanelSourceFolders.class, "TXT_CancelOption"); // NOI18N
255
NotifyDescriptor desc = new NotifyDescriptor (
256                     NbBundle.getMessage (PanelSourceFolders.class, "MSG_FoundClassFiles"), // NOI18N
257
NbBundle.getMessage (PanelSourceFolders.class, "MSG_FoundClassFiles_Title"), // NOI18N
258
NotifyDescriptor.YES_NO_CANCEL_OPTION,
259                     NotifyDescriptor.QUESTION_MESSAGE,
260                     new Object JavaDoc[] {DELETE_OPTION, KEEP_OPTION, CANCEL_OPTION},
261                     null
262                     );
263             Object JavaDoc result = DialogDisplayer.getDefault().notify(desc);
264             if (DELETE_OPTION.equals (result)) {
265                 deleteClassFiles (folders);
266             } else if (!KEEP_OPTION.equals (result)) {
267                 // cancel, back to wizard
268
throw new WizardValidationException (this.sourcePanel, "", ""); // NOI18N
269
}
270         }
271     }
272     
273     private void deleteClassFiles (File JavaDoc[] folders) {
274         for (int i=0; i<folders.length; i++) {
275             FileObject folder = FileUtil.toFileObject(folders[i]);
276             Enumeration JavaDoc en = folder.getData (true);
277             while (en.hasMoreElements ()) {
278                 Object JavaDoc obj = en.nextElement ();
279                 assert obj instanceof FileObject : "Instance of FileObject: " + obj;
280                 FileObject fo = (FileObject) obj;
281                 try {
282                     if ("class".equals (fo.getExt ())) { // NOI18N
283
fo.delete ();
284                     }
285                 } catch (IOException JavaDoc ioe) {
286                     ErrorManager.getDefault ().notify (ioe);
287                 }
288             }
289         }
290     }
291     
292     /** This method is called from within the constructor to
293      * initialize the form.
294      * WARNING: Do NOT modify this code. The content of this method is
295      * always regenerated by the Form Editor.
296      */

297     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
298
private void initComponents() {
299         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
300
301         jLabel3 = new javax.swing.JLabel JavaDoc();
302         jLabelWebPages = new javax.swing.JLabel JavaDoc();
303         jTextFieldWebPages = new javax.swing.JTextField JavaDoc();
304         jButtonWebpagesLocation = new javax.swing.JButton JavaDoc();
305         jLabelLibraries = new javax.swing.JLabel JavaDoc();
306         jTextFieldLibraries = new javax.swing.JTextField JavaDoc();
307         jButtonLibraries = new javax.swing.JButton JavaDoc();
308         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"),
309             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"));
310         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"),
311             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"));
312
313         setPreferredSize(new java.awt.Dimension JavaDoc(500, 340));
314         setLayout(new java.awt.GridBagLayout JavaDoc());
315
316         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(PanelSourceFolders.class, "LBL_IW_LocationDesc_Label")); // NOI18N
317
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
318         gridBagConstraints.gridy = 0;
319         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
320         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
321         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
322         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
323         add(jLabel3, gridBagConstraints);
324         jLabel3.getAccessibleContext().setAccessibleName(null);
325         jLabel3.getAccessibleContext().setAccessibleDescription(null);
326
327         jLabelWebPages.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(PanelSourceFolders.class, "LBL_IW_WebPagesLocation_LabelMnemonic").charAt(0));
328         jLabelWebPages.setLabelFor(jTextFieldWebPages);
329         jLabelWebPages.setText(NbBundle.getMessage(PanelSourceFolders.class, "LBL_IW_WebPagesLocation_Label")); // NOI18N
330
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
331         gridBagConstraints.gridx = 0;
332         gridBagConstraints.gridy = 1;
333         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
334         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 11);
335         add(jLabelWebPages, gridBagConstraints);
336         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
337         gridBagConstraints.gridx = 1;
338         gridBagConstraints.gridy = 1;
339         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
340         gridBagConstraints.weightx = 1.0;
341         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 11);
342         add(jTextFieldWebPages, gridBagConstraints);
343         jTextFieldWebPages.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelSourceFolders.class, "ACSD_WebPagesFolder")); // NOI18N
344

345         jButtonWebpagesLocation.setMnemonic(org.openide.util.NbBundle.getMessage(PanelSourceFolders.class, "LBL_WebPagesFolder_MNE").charAt(0));
346         jButtonWebpagesLocation.setText(NbBundle.getMessage(PanelSourceFolders.class, "LBL_BrowseWebPagesLocation_Button")); // NOI18N
347
jButtonWebpagesLocation.addActionListener(new java.awt.event.ActionListener JavaDoc() {
348             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
349                 jButtonWebpagesLocationActionPerformed(evt);
350             }
351         });
352         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
353         gridBagConstraints.gridx = 2;
354         gridBagConstraints.gridy = 1;
355         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
356         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
357         add(jButtonWebpagesLocation, gridBagConstraints);
358         jButtonWebpagesLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelSourceFolders.class, "ACSD_BrowseWebPageFolder")); // NOI18N
359

360         jLabelLibraries.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(PanelSourceFolders.class, "LBL_IW_LibrariesLocation_LabelMnemonic").charAt(0));
361         jLabelLibraries.setLabelFor(jTextFieldLibraries);
362         jLabelLibraries.setText(NbBundle.getMessage(PanelSourceFolders.class, "LBL_IW_LibrariesLocation_Label")); // NOI18N
363
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
364         gridBagConstraints.gridx = 0;
365         gridBagConstraints.gridy = 2;
366         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
367         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
368         add(jLabelLibraries, gridBagConstraints);
369         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
370         gridBagConstraints.gridx = 1;
371         gridBagConstraints.gridy = 2;
372         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
373         gridBagConstraints.weightx = 1.0;
374         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
375         add(jTextFieldLibraries, gridBagConstraints);
376         jTextFieldLibraries.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelSourceFolders.class, "ACSD_LibrariesFolder")); // NOI18N
377

378         jButtonLibraries.setMnemonic(org.openide.util.NbBundle.getMessage(PanelSourceFolders.class, "MNE_BrowseLibrariesLocation").charAt(0));
379         jButtonLibraries.setText(NbBundle.getMessage(PanelSourceFolders.class, "LBL_BrowseLibrariesLocation_Button")); // NOI18N
380
jButtonLibraries.addActionListener(new java.awt.event.ActionListener JavaDoc() {
381             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
382                 jButtonLibrariesActionPerformed(evt);
383             }
384         });
385         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
386         gridBagConstraints.gridx = 2;
387         gridBagConstraints.gridy = 2;
388         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
389         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
390         add(jButtonLibraries, gridBagConstraints);
391         jButtonLibraries.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelSourceFolders.class, "ACSD_BrowseLibrariesFolder")); // NOI18N
392

393         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
394         gridBagConstraints.gridy = 3;
395         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
396         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
397         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
398         gridBagConstraints.weightx = 1.0;
399         gridBagConstraints.weighty = 0.45;
400         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
401         add(sourcePanel, gridBagConstraints);
402         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
403         gridBagConstraints.gridy = 4;
404         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
405         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
406         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
407         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
408         gridBagConstraints.weightx = 1.0;
409         gridBagConstraints.weighty = 0.45;
410         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
411         add(testsPanel, gridBagConstraints);
412
413         getAccessibleContext().setAccessibleName(null);
414         getAccessibleContext().setAccessibleDescription(null);
415     }// </editor-fold>//GEN-END:initComponents
416

417     private void jButtonLibrariesActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonLibrariesActionPerformed
418
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
419         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
420         chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
421         if (jTextFieldLibraries.getText().length() > 0 && getLibraries().exists()) {
422             chooser.setSelectedFile(getLibraries());
423         } else {
424             chooser.setCurrentDirectory((File JavaDoc) wizardDescriptor.getProperty(WizardProperties.SOURCE_ROOT));
425         }
426         if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
427             File JavaDoc configFilesDir = FileUtil.normalizeFile(chooser.getSelectedFile());
428             jTextFieldLibraries.setText(configFilesDir.getAbsolutePath());
429         }
430     }//GEN-LAST:event_jButtonLibrariesActionPerformed
431

432     private void jButtonWebpagesLocationActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonWebpagesLocationActionPerformed
433
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
434         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
435         chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
436         if (jTextFieldWebPages.getText().length() > 0 && getWebPages().exists()) {
437             chooser.setSelectedFile(getWebPages());
438         } else {
439             chooser.setCurrentDirectory((File JavaDoc) wizardDescriptor.getProperty(WizardProperties.SOURCE_ROOT));
440         }
441         if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
442             File JavaDoc webPagesDir = FileUtil.normalizeFile(chooser.getSelectedFile());
443             jTextFieldWebPages.setText(webPagesDir.getAbsolutePath());
444         }
445     }//GEN-LAST:event_jButtonWebpagesLocationActionPerformed
446

447     
448     
449     // Variables declaration - do not modify//GEN-BEGIN:variables
450
private javax.swing.JButton JavaDoc jButtonLibraries;
451     private javax.swing.JButton JavaDoc jButtonWebpagesLocation;
452     private javax.swing.JLabel JavaDoc jLabel3;
453     private javax.swing.JLabel JavaDoc jLabelLibraries;
454     private javax.swing.JLabel JavaDoc jLabelWebPages;
455     private javax.swing.JTextField JavaDoc jTextFieldLibraries;
456     private javax.swing.JTextField JavaDoc jTextFieldWebPages;
457     private javax.swing.JPanel JavaDoc sourcePanel;
458     private javax.swing.JPanel JavaDoc testsPanel;
459     // End of variables declaration//GEN-END:variables
460

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