KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > ui > wizards > PanelProjectImportVisual


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.earproject.ui.wizards;
21
22 import java.io.File JavaDoc;
23 import java.text.MessageFormat JavaDoc;
24 import java.util.ResourceBundle JavaDoc;
25 import javax.swing.JFileChooser JavaDoc;
26 import javax.swing.event.DocumentEvent JavaDoc;
27 import javax.swing.event.DocumentListener JavaDoc;
28 import org.netbeans.spi.project.ui.support.ProjectChooser;
29 import org.netbeans.spi.project.ui.templates.support.Templates;
30 import org.openide.WizardDescriptor;
31 import org.openide.filesystems.FileObject;
32 import org.openide.filesystems.FileUtil;
33
34 final class PanelProjectImportVisual extends SettingsPanel implements DocumentListener JavaDoc {
35     
36     private final PanelConfigureProject panel;
37     private final String JavaDoc propNameIndex;
38     private final ResourceBundle JavaDoc customBundle;
39     private final boolean importStyle;
40     private String JavaDoc lastComputedPrjName;
41     private String JavaDoc lastComputedPrjFolder;
42     private boolean ignoreEvent;
43
44     // wheter this panel is being shown first time
45
private boolean firstTime = true;
46     
47     /** Creates new form PanelProjectLocationVisual */
48     public PanelProjectImportVisual(PanelConfigureProject panel, String JavaDoc propNameIndex, ResourceBundle JavaDoc customBundle, boolean importStyle) {
49         this.customBundle = customBundle;
50         initComponents();
51         this.panel = panel;
52         this.propNameIndex = propNameIndex;
53         
54         // Register listener on the textFields to make the automatic updates
55
projectNameTextField.getDocument().addDocumentListener(this);
56         projectLocationTextField.getDocument().addDocumentListener(this);
57         this.importStyle = importStyle;
58         createdFolderTextField.setEditable(importStyle);
59         if (importStyle) {
60             createdFolderTextField.getDocument().addDocumentListener(this);
61         }
62         browseFolderButton.setVisible(importStyle);
63     }
64     
65     void addNameListener(DocumentListener JavaDoc listener) {
66         projectNameTextField.getDocument().addDocumentListener(listener);
67     }
68     
69     /** This method is called from within the constructor to
70      * initialize the form.
71      * WARNING: Do NOT modify this code. The content of this method is
72      * always regenerated by the Form Editor.
73      */

74     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
75
private void initComponents() {
76         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
77
78         projectNameLabel = new javax.swing.JLabel JavaDoc();
79         projectNameTextField = new javax.swing.JTextField JavaDoc();
80         projectLocationLabel = new javax.swing.JLabel JavaDoc();
81         projectLocationTextField = new javax.swing.JTextField JavaDoc();
82         browseLocationButton = new javax.swing.JButton JavaDoc();
83         createdFolderLabel = new javax.swing.JLabel JavaDoc();
84         createdFolderTextField = new javax.swing.JTextField JavaDoc();
85         browseFolderButton = new javax.swing.JButton JavaDoc();
86         instructionLabel = new javax.swing.JLabel JavaDoc();
87         descriptionArea = new javax.swing.JTextArea JavaDoc();
88         spaceFiller = new javax.swing.JPanel JavaDoc();
89
90         setLayout(new java.awt.GridBagLayout JavaDoc());
91
92         projectNameLabel.setLabelFor(projectNameTextField);
93         org.openide.awt.Mnemonics.setLocalizedText(projectNameLabel, org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "LBL_NWP1_ProjectName_Label")); // NOI18N
94
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
95         gridBagConstraints.gridx = 0;
96         gridBagConstraints.gridy = 3;
97         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
98         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
99         add(projectNameLabel, gridBagConstraints);
100
101         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
102         gridBagConstraints.gridx = 1;
103         gridBagConstraints.gridy = 3;
104         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
105         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
106         gridBagConstraints.weightx = 1.0;
107         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 6, 0);
108         add(projectNameTextField, gridBagConstraints);
109         projectNameTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "ACS_LBL_NWP1_ProjectName_A11YDesc")); // NOI18N
110

111         projectLocationLabel.setLabelFor(projectLocationTextField);
112         org.openide.awt.Mnemonics.setLocalizedText(projectLocationLabel, org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "LBL_ImportLocation_Label")); // NOI18N
113
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
114         gridBagConstraints.gridx = 0;
115         gridBagConstraints.gridy = 1;
116         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
117         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
118         add(projectLocationLabel, gridBagConstraints);
119
120         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
121         gridBagConstraints.gridx = 1;
122         gridBagConstraints.gridy = 1;
123         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
124         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
125         gridBagConstraints.weightx = 1.0;
126         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 6, 0);
127         add(projectLocationTextField, gridBagConstraints);
128         projectLocationTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "ACS_LBL_NPW1_ProjectLocation_A11YDesc")); // NOI18N
129

130         org.openide.awt.Mnemonics.setLocalizedText(browseLocationButton, org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "LBL_NWP1_BrowseLocation_Button")); // NOI18N
131
browseLocationButton.setActionCommand("BROWSE");
132         browseLocationButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
133             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
134                 browseLocationAction(evt);
135             }
136         });
137
138         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
139         gridBagConstraints.gridx = 2;
140         gridBagConstraints.gridy = 1;
141         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
142         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
143         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 6, 0);
144         add(browseLocationButton, gridBagConstraints);
145         browseLocationButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "ACS_LBL_NWP1_BrowseLocation_A11YDesc")); // NOI18N
146

147         createdFolderLabel.setLabelFor(createdFolderTextField);
148         org.openide.awt.Mnemonics.setLocalizedText(createdFolderLabel, org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "LBL_NWP1_CreatedProjectFolder_Lablel")); // NOI18N
149
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
150         gridBagConstraints.gridx = 0;
151         gridBagConstraints.gridy = 4;
152         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
153         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
154         add(createdFolderLabel, gridBagConstraints);
155
156         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
157         gridBagConstraints.gridx = 1;
158         gridBagConstraints.gridy = 4;
159         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
160         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
161         gridBagConstraints.weightx = 1.0;
162         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
163         add(createdFolderTextField, gridBagConstraints);
164         createdFolderTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "ACS_LBL_NWP1_CreatedProjectFolder_A11YDesc")); // NOI18N
165

166         org.openide.awt.Mnemonics.setLocalizedText(browseFolderButton, org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "LBL_NWP1_BrowseProjectFolder_Button")); // NOI18N
167
browseFolderButton.setActionCommand("BROWSE");
168         browseFolderButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
169             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
170                 browseFolderAction(evt);
171             }
172         });
173
174         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
175         gridBagConstraints.gridx = 2;
176         gridBagConstraints.gridy = 4;
177         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
178         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
179         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
180         add(browseFolderButton, gridBagConstraints);
181         browseFolderButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "ACSN_LBL_NWP1_BrowseProjectFolder_Button")); // NOI18N
182
browseFolderButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "ACSD_LBL_NWP1_BrowseProjectFolder_Button")); // NOI18N
183

184         instructionLabel.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
185         org.openide.awt.Mnemonics.setLocalizedText(instructionLabel, org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "LBL_ImportInstructions2")); // NOI18N
186
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
187         gridBagConstraints.gridx = 0;
188         gridBagConstraints.gridy = 2;
189         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
190         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
191         add(instructionLabel, gridBagConstraints);
192
193         descriptionArea.setEditable(false);
194         descriptionArea.setLineWrap(true);
195         descriptionArea.setRows(2);
196         descriptionArea.setText(org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "LBL_ImportInstructions1")); // NOI18N
197
descriptionArea.setWrapStyleWord(true);
198         descriptionArea.setOpaque(false);
199         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
200         gridBagConstraints.gridx = 0;
201         gridBagConstraints.gridy = 0;
202         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
203         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
204         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 5, 0);
205         add(descriptionArea, gridBagConstraints);
206         descriptionArea.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "ACSN_LBL_ImportInstructions1")); // NOI18N
207
descriptionArea.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelProjectImportVisual.class, "ACSD_LBL_ImportInstructions1")); // NOI18N
208

209         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
210         gridBagConstraints.gridx = 0;
211         gridBagConstraints.gridy = 5;
212         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
213         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
214         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
215         gridBagConstraints.weighty = 1.0;
216         add(spaceFiller, gridBagConstraints);
217
218     }// </editor-fold>//GEN-END:initComponents
219

220     private void browseFolderAction(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseFolderAction
221
String JavaDoc command = evt.getActionCommand();
222         
223         if ("BROWSE".equals(command)) { //NOI18N
224
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
225             chooser.setDialogTitle(customBundle.getString("LBL_NWP1_BrowseProjectFolder")); //NOI18N
226
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
227             String JavaDoc path = getCreatedFolderText();
228             if (path.length() > 0) {
229                 File JavaDoc f = new File JavaDoc(path);
230                 if (f.exists()) {
231                     chooser.setSelectedFile(f);
232                 }
233             } else {
234                 chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
235             }
236             if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
237                 File JavaDoc projectDir = chooser.getSelectedFile();
238                 createdFolderTextField.setText(projectDir.getAbsolutePath());
239             }
240             panel.fireChangeEvent();
241         }
242     }//GEN-LAST:event_browseFolderAction
243

244     private void browseLocationAction(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseLocationAction
245
String JavaDoc command = evt.getActionCommand();
246         
247         if ("BROWSE".equals(command)) { //NOI18N
248
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
249             chooser.setDialogTitle(customBundle.getString("LBL_NWP1_SelectProjectLocation")); //NOI18N
250
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
251             String JavaDoc path = projectLocationTextField.getText();
252             if (path.length() > 0) {
253                 File JavaDoc f = new File JavaDoc(path);
254                 if (f.exists()) {
255                     chooser.setSelectedFile(f);
256                 }
257             } else {
258                 chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
259             }
260             if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
261                 File JavaDoc projectDir = chooser.getSelectedFile();
262                 projectLocationTextField.setText(projectDir.getAbsolutePath());
263             }
264             panel.fireChangeEvent();
265         }
266     }//GEN-LAST:event_browseLocationAction
267

268     public void addNotify() {
269         super.addNotify();
270         //same problem as in 31086, initial focus on Cancel button
271
projectNameTextField.requestFocus();
272     }
273     
274     boolean valid(WizardDescriptor wizardDescriptor) {
275         String JavaDoc sourceLocationPath = projectLocationTextField.getText().trim();
276         if (sourceLocationPath.length() == 0
277                 || !new File JavaDoc(sourceLocationPath).isDirectory()) {
278             wizardDescriptor.putProperty("WizardPanel_errorMessage", //NOI18N
279
customBundle.getString("MSG_ProvideExistingSourcesLocation")); //NOI18N
280
return false;
281         }
282         
283         if (!SettingsPanel.isValidProjectName(projectNameTextField.getText())) {
284             wizardDescriptor.putProperty("WizardPanel_errorMessage", //NOI18N
285
customBundle.getString("MSG_IllegalProjectName")); //NOI18N
286
return false;
287         }
288         
289         if (importStyle && getCreatedFolderText().length() == 0) {
290             wizardDescriptor.putProperty("WizardPanel_errorMessage", //NOI18N
291
customBundle.getString("MSG_EmptyProjectFolder"));//NOI18N
292
return false;
293         }
294         
295         File JavaDoc destParent = SettingsPanel.findExistingParent(getCreatedFolderText());
296         
297         File JavaDoc destDir = new File JavaDoc(getCreatedFolderText());
298         if (destDir.exists() && !destDir.isDirectory()) {
299             wizardDescriptor.putProperty("WizardPanel_errorMessage", //NOI18N
300
MessageFormat.format(customBundle.getString("MSG_WillOverwrite"),new Object JavaDoc[] {destDir.getAbsolutePath() })); //NOI18N
301
return false;
302         }
303         File JavaDoc buildXml = new File JavaDoc(getCreatedFolderText()+
304             File.separator+"build.xml"); // NOI18N
305
if (buildXml.exists()) {
306             wizardDescriptor.putProperty("WizardPanel_errorMessage", //NOI18N
307
MessageFormat.format(customBundle.getString("MSG_WillOverwrite"),new Object JavaDoc[] {buildXml.getAbsolutePath() })); //NOI18N
308
return false;
309         }
310         File JavaDoc tFile = null; //new File(getCreatedFolderText()+
311
// File.separator+"src"+File.separator+"conf"+File.separator+ //NOI18N
312
// "application.xml"); //NOI18N
313
// if (tFile.exists()) {
314
// wizardDescriptor.putProperty("WizardPanel_errorMessage",
315
// MessageFormat.format(customBundle.getString("MSG_WillOverwrite"),new Object[] {tFile.getAbsolutePath()})); //NOI18N
316
// return false;
317
// }
318

319         tFile = new File JavaDoc(getCreatedFolderText()+
320             File.separator+"nbproject"+File.separator+"project.xml"); //NOI18N
321
if (tFile.exists()) {
322             wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
323
MessageFormat.format(customBundle.getString("MSG_AlreadyExixts"),new Object JavaDoc[] {tFile.getAbsolutePath()})); //NOI18N
324
return false;
325         }
326         tFile = new File JavaDoc(getCreatedFolderText()+
327             File.separator+"nbproject"+File.separator+"project.properties"); //NOI18N
328
if (tFile.exists()) {
329             wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
330
MessageFormat.format(customBundle.getString("MSG_AlreadyExixts"),new Object JavaDoc[] {tFile.getAbsolutePath()})); //NOI18N
331
return false;
332         }
333         if (null != destParent && destParent.exists() && !destParent.canWrite()) {
334             // Read only project location
335
wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
336
MessageFormat.format(customBundle.getString("MSG_ProjectLocationRO"),new Object JavaDoc[] {destParent.getAbsolutePath()})); //NOI18N
337
return false;
338         }
339                 
340         wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); //NOI18N
341
return true;
342     }
343     
344     void store(WizardDescriptor d) {
345         String JavaDoc name = projectNameTextField.getText().trim();
346         
347         d.putProperty(WizardProperties.PROJECT_DIR, new File JavaDoc(getCreatedFolderText()));
348         d.putProperty(WizardProperties.NAME, name);
349         File JavaDoc srcRoot = null;
350         String JavaDoc srcPath = projectLocationTextField.getText();
351         if (srcPath.length() > 0) {
352             srcRoot = FileUtil.normalizeFile(new File JavaDoc(srcPath));
353         }
354         d.putProperty(WizardProperties.SOURCE_ROOT, srcRoot);
355     }
356     
357     void read(WizardDescriptor settings) {
358         if (!firstTime) {
359             return;
360         }
361         firstTime = false;
362         File JavaDoc projectLocation = getPreferredProjectLocation(settings);
363         
364         if (null != projectLocation) {
365             //projectLocationTextField.setText(projectLocation.getAbsolutePath());
366
String JavaDoc projectName = (String JavaDoc) settings.getProperty(WizardProperties.NAME);
367             if (projectName == null) {
368                 // XXX re-examine this
369
int baseCount = 1; // FoldersListSettings.getDefault().getNewProjectCount() + 1;
370
String JavaDoc formater = customBundle.getString( "TXT_DefaultProjectName");
371                 while ((projectName = validFreeProjectName(projectLocation, formater, baseCount)) == null) {
372                     baseCount++;
373                 }
374                 //settings.putProperty(NewEarProjectWizardIterator.PROP_NAME_INDEX, new Integer(baseCount));
375
settings.putProperty(propNameIndex, baseCount);
376             }
377             //projectNameTextField.setText(projectName);
378
//if (importStyle) {
379
// createdFolderTextField.setText(System.getProperty("user.home") +
380
// File.separator+projectName);
381
//}
382
}
383         
384         projectNameTextField.selectAll();
385     }
386     
387     private static File JavaDoc getPreferredProjectLocation(final WizardDescriptor settings) {
388         File JavaDoc projectLocation = null;
389         FileObject existingSourcesFO = Templates.getExistingSourcesFolder(settings);
390         if (existingSourcesFO != null) {
391             File JavaDoc existingSourcesFile = FileUtil.toFile(existingSourcesFO);
392             if (existingSourcesFile != null && existingSourcesFile.isDirectory()) {
393                 projectLocation = existingSourcesFile;
394             }
395         } else {
396             projectLocation = (File JavaDoc) settings.getProperty(WizardProperties.PROJECT_DIR);
397             if (projectLocation == null) {
398                 projectLocation = ProjectChooser.getProjectsFolder();
399             } else {
400                 projectLocation = projectLocation.getParentFile();
401             }
402         }
403         return projectLocation;
404     }
405     
406     // Variables declaration - do not modify//GEN-BEGIN:variables
407
private javax.swing.JButton JavaDoc browseFolderButton;
408     private javax.swing.JButton JavaDoc browseLocationButton;
409     private javax.swing.JLabel JavaDoc createdFolderLabel;
410     private javax.swing.JTextField JavaDoc createdFolderTextField;
411     private javax.swing.JTextArea JavaDoc descriptionArea;
412     private javax.swing.JLabel JavaDoc instructionLabel;
413     private javax.swing.JLabel JavaDoc projectLocationLabel;
414     private javax.swing.JTextField JavaDoc projectLocationTextField;
415     private javax.swing.JLabel JavaDoc projectNameLabel;
416     private javax.swing.JTextField JavaDoc projectNameTextField;
417     private javax.swing.JPanel JavaDoc spaceFiller;
418     // End of variables declaration//GEN-END:variables
419

420 // private static JFileChooser createChooser() {
421
// JFileChooser chooser = new JFileChooser();
422
// chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
423
// chooser.setAcceptAllFileFilterUsed(false);
424
//
425
// return chooser;
426
// }
427

428     private String JavaDoc validFreeProjectName(final File JavaDoc parentFolder, final String JavaDoc formater, final int index) {
429         String JavaDoc name = MessageFormat.format(formater, index);
430         File JavaDoc file = new File JavaDoc(parentFolder, name);
431         return file.exists() ? null : name;
432     }
433
434     // Implementation of DocumentListener --------------------------------------
435
public void changedUpdate(final DocumentEvent JavaDoc e) {
436         updateTexts(e);
437     }
438     
439     public void insertUpdate(final DocumentEvent JavaDoc e) {
440         updateTexts(e);
441     }
442     
443     public void removeUpdate(final DocumentEvent JavaDoc e) {
444         updateTexts(e);
445     }
446     // End of implementation of DocumentListener -------------------------------
447

448     /** Handles changes in the project name and the project directory. */
449     private void updateTexts(final DocumentEvent JavaDoc e) {
450         if (!importStyle) {
451             createdFolderTextField.setText(getCreatedFolderPath());
452         } else {
453             if (ignoreEvent) {
454                 return;
455             }
456             ignoreEvent = true;
457             if (e.getDocument() != projectNameTextField.getDocument()) { // #81196
458
updateProjectName();
459             }
460             if (e.getDocument() != createdFolderTextField.getDocument()) { // #81196
461
updateProjectFolder();
462             }
463             ignoreEvent = false;
464         }
465         panel.fireChangeEvent(); // Notify that the panel changed
466
}
467     
468     private void updateProjectName() {
469         String JavaDoc prjName = computeProjectName();
470         if ((lastComputedPrjName != null) && (!lastComputedPrjName.equals(projectNameTextField.getText().trim()))) {
471             return;
472         }
473         lastComputedPrjName = prjName;
474         if (prjName != null) {
475             projectNameTextField.setText(prjName);
476         }
477     }
478     
479     private String JavaDoc computeProjectName() {
480         String JavaDoc cPrjName = null;
481         File JavaDoc f = FileUtil.normalizeFile(new File JavaDoc(projectLocationTextField.getText()));
482         FileObject fo = FileUtil.toFileObject(f);
483         if (fo != null) {
484             cPrjName = fo.getName();
485         }
486         return cPrjName;
487     }
488     
489     private void updateProjectFolder() {
490         String JavaDoc prjFolder = computeProjectFolder();
491         if ((lastComputedPrjFolder != null) && (!lastComputedPrjFolder.equals(createdFolderTextField.getText().trim()))) {
492             return;
493         }
494         lastComputedPrjFolder = prjFolder;
495         if (prjFolder != null) {
496             createdFolderTextField.setText(prjFolder);
497         } else {
498             createdFolderTextField.setText(""); // NOI18N
499
}
500     }
501     
502     private String JavaDoc computeProjectFolder() {
503         return FileUtil.normalizeFile(new File JavaDoc(projectLocationTextField.getText())).getAbsolutePath();
504     }
505     
506     private String JavaDoc getCreatedFolderPath() {
507         StringBuffer JavaDoc folder = new StringBuffer JavaDoc(projectLocationTextField.getText().trim());
508         if (!importStyle) {
509             if (!projectLocationTextField.getText().endsWith(File.separator)) {
510                 folder.append(File.separatorChar);
511             }
512             folder.append(projectNameTextField.getText().trim());
513         }
514         
515         return folder.toString();
516     }
517     
518     private String JavaDoc getCreatedFolderText() {
519         return createdFolderTextField.getText().trim();
520     }
521     
522 }
523
524 //TODO implement check for project folder name and location
525
Popular Tags