KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > ui > wizards > ImportLocationVisual


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.awt.Dimension JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.text.MessageFormat JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Set JavaDoc;
29 import java.util.TreeSet JavaDoc;
30
31 import javax.swing.*;
32 import javax.swing.event.DocumentEvent JavaDoc;
33 import javax.swing.event.DocumentListener JavaDoc;
34 import javax.swing.text.Document JavaDoc;
35 import org.netbeans.api.project.ProjectUtils;
36 import org.netbeans.modules.j2ee.deployment.devmodules.api.ServerManager;
37 import org.netbeans.modules.web.project.Utils;
38
39 import org.openide.WizardDescriptor;
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 import org.netbeans.api.project.Project;
46 import org.netbeans.api.project.ProjectInformation;
47 import org.netbeans.api.project.ProjectManager;
48 import org.netbeans.api.project.ui.OpenProjects;
49 import org.netbeans.spi.project.ui.support.ProjectChooser;
50
51 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
52 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
53 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModuleContainer;
54 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
55 import org.netbeans.modules.web.project.ui.*;
56 import org.netbeans.spi.project.ui.templates.support.Templates;
57
58 /**
59  *
60  * @author Pavel Buzek, Radko Najman
61  */

62 public class ImportLocationVisual extends SettingsPanel implements HelpCtx.Provider {
63     
64     private ImportWebProjectWizardIterator.ThePanel panel;
65     private Document JavaDoc moduleDocument;
66     private Document JavaDoc nameDocument;
67     private boolean contextModified = false;
68     private boolean locationModified = false;
69     private boolean locationComputed = false;
70     private WizardDescriptor wizardDescriptor;
71     
72     private J2eeVersionWarningPanel warningPanel;
73
74     private String JavaDoc generatedProjectName = "";
75     private int generatedProjectNameIndex = 0;
76     private final DefaultComboBoxModel serversModel = new DefaultComboBoxModel();
77     private List JavaDoc earProjects;
78     
79     private static final String JavaDoc J2EE_SPEC_13_LABEL = NbBundle.getMessage(ImportLocationVisual.class, "J2EESpecLevel_13"); //NOI18N
80
private static final String JavaDoc J2EE_SPEC_14_LABEL = NbBundle.getMessage(ImportLocationVisual.class, "J2EESpecLevel_14"); //NOI18N
81
private static final String JavaDoc JAVA_EE_5_LABEL = NbBundle.getMessage(ImportLocationVisual.class, "JavaEESpecLevel_50"); //NOI18N
82

83     /** Creates new form TestPanel */
84     public ImportLocationVisual (ImportWebProjectWizardIterator.ThePanel panel) {
85         this.panel = panel;
86         initComponents ();
87         initServers(FoldersListSettings.getDefault().getLastUsedServer());
88         // preselect the first item in the j2ee spec combo
89
if (j2eeSpecComboBox.getModel().getSize() > 0) {
90             j2eeSpecComboBox.setSelectedIndex(0);
91         }
92         initEnterpriseApplications();
93         
94         setJ2eeVersionWarningPanel();
95         
96         //resize panel to show all components
97
computeSize();
98         
99         this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_NWP1_NamePanel_A11YDesc")); // NOI18N
100

101         setName(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_ImportTitle")); //NOI18N
102

103         moduleDocument = moduleLocationTextField.getDocument ();
104         nameDocument = projectNameTextField.getDocument();
105         
106         moduleLocationTextField.getDocument().addDocumentListener(new DocumentListener JavaDoc () {
107             public void changedUpdate(DocumentEvent JavaDoc e) {
108                 locationDataChanged(e);
109             }
110             public void insertUpdate(DocumentEvent JavaDoc e) {
111                 locationDataChanged(e);
112             }
113             public void removeUpdate(DocumentEvent JavaDoc e) {
114                 locationDataChanged(e);
115             }
116         });
117         
118         projectNameTextField.getDocument().addDocumentListener (new DocumentListener JavaDoc () {
119             public void changedUpdate(DocumentEvent JavaDoc e) {
120                 nameDataChanged(e);
121             }
122             public void insertUpdate(DocumentEvent JavaDoc e) {
123                 nameDataChanged(e);
124             }
125             public void removeUpdate(DocumentEvent JavaDoc e) {
126                 nameDataChanged(e);
127             }
128         });
129         
130         projectLocationTextField.getDocument().addDocumentListener (new DocumentListener JavaDoc () {
131             public void changedUpdate(DocumentEvent JavaDoc e) {
132                 fireChanges();
133             }
134             public void insertUpdate(DocumentEvent JavaDoc e) {
135                 fireChanges();
136             }
137             public void removeUpdate(DocumentEvent JavaDoc e) {
138                 fireChanges();
139             }
140         });
141         
142     }
143     
144     private void computeSize() {
145         double srcLocLabelLength = jLabelSrcLocationDesc.getFontMetrics(jLabelSrcLocationDesc.getFont()).getStringBounds(jLabelSrcLocationDesc.getText(), getGraphics()).getWidth() * 0.85;
146         int width = new Double JavaDoc(srcLocLabelLength).intValue();
147         if (width < 500)
148             width = 500;
149         int height = jComboBoxEnterprise.getFontMetrics(jComboBoxEnterprise.getFont()).getHeight() * 13 + 150;
150         if (height > 340) {
151             Dimension JavaDoc dim = new Dimension JavaDoc(width, height);
152             setMinimumSize(dim);
153             setPreferredSize(dim);
154         }
155     }
156     
157     void read(WizardDescriptor settings) {
158         wizardDescriptor = settings;
159         
160         File JavaDoc projectLocation = (File JavaDoc) settings.getProperty ("projdir"); //NOI18N
161
if (projectLocation == null || projectLocation.getParentFile() == null || !projectLocation.getParentFile().isDirectory ())
162             projectLocation = ProjectChooser.getProjectsFolder();
163         else
164             projectLocation = projectLocation.getParentFile();
165         
166         if(generatedProjectNameIndex == 0) {
167             generatedProjectName = (String JavaDoc) settings.getProperty ("name"); //NOI18N
168
if (generatedProjectName == null) {
169                     generatedProjectNameIndex = FoldersListSettings.getDefault().getNewProjectCount() + 1;
170                     String JavaDoc formater = NbBundle.getMessage(ImportLocationVisual.class,"LBL_NPW1_DefaultProjectName");
171                     while ((generatedProjectName = validFreeProjectName(projectLocation, formater, generatedProjectNameIndex)) == null)
172                         generatedProjectNameIndex++;
173                     settings.putProperty (NewWebProjectWizardIterator.PROP_NAME_INDEX, Integer.valueOf(generatedProjectNameIndex));
174             }
175             // no project name needs to be generated
176
//projectNameTextField.setText(generatedProjectName);
177
moduleLocationTextField.selectAll();
178         }
179     }
180
181     void store (WizardDescriptor settings) {
182         File JavaDoc srcRoot = null;
183         String JavaDoc srcPath = moduleLocationTextField.getText();
184         if (srcPath.length() > 0) {
185             srcRoot = FileUtil.normalizeFile(new File JavaDoc(srcPath));
186         }
187         if (srcRoot != null)
188             FoldersListSettings.getDefault().setLastUsedImportLocation(srcRoot);
189         settings.putProperty (WizardProperties.SOURCE_ROOT, srcRoot);
190         settings.putProperty (WizardProperties.NAME, projectNameTextField.getText().trim());
191
192         final String JavaDoc projectLocation = projectLocationTextField.getText().trim();
193         if (projectLocation.length() >= 0) {
194             settings.putProperty (WizardProperties.PROJECT_DIR, new File JavaDoc(projectLocation));
195         }
196
197         String JavaDoc contextPath = jTextFieldContextPath.getText().trim();
198         if (!contextPath.startsWith("/")) //NOI18N
199
contextPath = "/" + contextPath; //NOI18N
200
settings.putProperty(WizardProperties.CONTEXT_PATH, contextPath);
201         final Integer JavaDoc nameIndex = projectNameTextField.getText().equals(generatedProjectName) ?
202                 Integer.valueOf(generatedProjectNameIndex) : null;
203         settings.putProperty(NewWebProjectWizardIterator.PROP_NAME_INDEX, nameIndex);
204         
205         settings.putProperty(WizardProperties.SET_AS_MAIN, setAsMainCheckBox.isSelected() ? Boolean.TRUE : Boolean.FALSE );
206         settings.putProperty(WizardProperties.SERVER_INSTANCE_ID, getSelectedServer());
207         settings.putProperty(WizardProperties.J2EE_LEVEL, getSelectedJ2eeSpec());
208         settings.putProperty(WizardProperties.EAR_APPLICATION, getSelectedEarApplication());
209         
210         if (warningPanel != null && warningPanel.getDowngradeAllowed()) {
211             settings.putProperty(WizardProperties.JAVA_PLATFORM, warningPanel.getSuggestedJavaPlatformName());
212             
213             String JavaDoc j2ee = getSelectedJ2eeSpec();
214             if (j2ee != null) {
215                 String JavaDoc warningType = J2eeVersionWarningPanel.findWarningType(j2ee);
216                 FoldersListSettings fls = FoldersListSettings.getDefault();
217                 String JavaDoc srcLevel = "1.6"; //NOI18N
218
if (warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_14) && fls.isAgreedSetSourceLevel14())
219                     srcLevel = "1.4"; //NOI18N
220
else if (warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_15) && fls.isAgreedSetSourceLevel15())
221                     srcLevel = "1.5"; //NOI18N
222

223                 settings.putProperty(WizardProperties.SOURCE_LEVEL, srcLevel);
224             }
225         } else
226             settings.putProperty(WizardProperties.SOURCE_LEVEL, null);
227     }
228
229     boolean valid (WizardDescriptor settings) {
230         String JavaDoc sourceLocationPath = moduleLocationTextField.getText().trim();
231         if (sourceLocationPath.length() == 0) {
232             setErrorMessage("MSG_ProvideExistingSourcesLocation"); //NOI18N
233
return false;
234         }
235         File JavaDoc f = new File JavaDoc (sourceLocationPath);
236         if (!f.isDirectory() || !f.canRead()) {
237         String JavaDoc format = NbBundle.getMessage(ImportLocationVisual.class, "MSG_IllegalSources"); //NOI18N
238
wizardDescriptor.putProperty( "WizardPanel_errorMessage", MessageFormat.format(format, new Object JavaDoc[] {sourceLocationPath})); //NOI18N
239
return false;
240         }
241
242         String JavaDoc projectLocationPath = projectLocationTextField.getText().trim();
243         f = new File JavaDoc(projectLocationPath);
244         String JavaDoc projectName = projectNameTextField.getText().trim();
245         f = new File JavaDoc(f, projectName);
246         f = PanelProjectLocationVisual.getCanonicalFile(f);
247         if(f == null || !projectName.equals(f.getName())) {
248             settings.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class, "MSG_ProvideProjectName"));
249             return false; // Invalid project name
250
}
251
252         if(projectLocationPath.length() == 0) {
253             setErrorMessage("MSG_ProvideProjectFolder"); //NOI18N
254
return false;
255         }
256         File JavaDoc projectLocation;
257         if (locationComputed)
258             projectLocation = ProjectChooser.getProjectsFolder();
259         else
260             projectLocation = new File JavaDoc(projectLocationPath);
261         if (projectLocation.exists() && !projectLocation.canWrite()) {
262             // Read only project location
263
setErrorMessage("MSG_ProjectLocationRO"); //NOI18N
264
return false;
265         }
266
267         File JavaDoc destFolder = FileUtil.normalizeFile(new File JavaDoc(projectLocationPath));
268     
269     // #47611: if there is a live project still residing here, forbid project creation.
270
if (destFolder.isDirectory()) {
271             FileObject destFO = FileUtil.toFileObject(destFolder);
272             assert destFO != null : "No FileObject for " + destFolder;
273             boolean clear = false;
274             try {
275                 clear = ProjectManager.getDefault().findProject(destFO) == null;
276             } catch (IOException JavaDoc e) {
277                 // need not report here; clear remains false -> error
278
}
279             if (!clear) {
280         setErrorMessage("MSG_ProjectFolderHasDeletedProject"); //NOI18N
281
return false;
282             }
283         }
284
285     
286         File JavaDoc[] kids = destFolder.listFiles();
287         if ( destFolder.exists() && kids != null && kids.length > 0) {
288             String JavaDoc file = null;
289             for (int i=0; i< kids.length; i++) {
290                 String JavaDoc childName = kids[i].getName();
291                 if ("nbproject".equals(childName)) { //NOI18N
292
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_NetBeansProject");
293                 }
294                 else if ("build".equals(childName)) { //NOI18N
295
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_BuildFolder");
296                 }
297                 else if ("WEB-INF".equals(childName)) { //NOI18N
298
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_WebInfFolder");
299                 }
300                 else if ("dist".equals(childName)) { //NOI18N
301
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_DistFolder");
302                 }
303                 else if ("manifest.mf".equals(childName)) { //NOI18N
304
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_Manifest");
305                 }
306                 if (file != null) {
307                     String JavaDoc format = NbBundle.getMessage (ImportLocationVisual.class,"MSG_ProjectFolderInvalid");
308                     wizardDescriptor.putProperty( "WizardPanel_errorMessage", MessageFormat.format(format, new Object JavaDoc[] {file})); //NOI18N
309
return false;
310                 }
311             }
312         }
313
314         setErrorMessage(null);
315         return true;
316     }
317
318     private void setErrorMessage(String JavaDoc messageId) {
319         wizardDescriptor.putProperty( "WizardPanel_errorMessage",
320                 messageId == null ? null : NbBundle.getMessage(ImportLocationVisual.class, messageId));
321     }
322
323
324     /** This method is called from within the constructor to
325      * initialize the form.
326      * WARNING: Do NOT modify this code. The content of this method is
327      * always regenerated by the Form Editor.
328      */

329     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
330
private void initComponents() {
331         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
332
333         jLabelSrcLocationDesc = new javax.swing.JLabel JavaDoc();
334         jLabelSrcLocation = new javax.swing.JLabel JavaDoc();
335         moduleLocationTextField = new javax.swing.JTextField JavaDoc();
336         jButtonSrcLocation = new javax.swing.JButton JavaDoc();
337         jLabelPrjLocationDesc = new javax.swing.JLabel JavaDoc();
338         jLabelPrjName = new javax.swing.JLabel JavaDoc();
339         projectNameTextField = new javax.swing.JTextField JavaDoc();
340         jLabelPrjLocation = new javax.swing.JLabel JavaDoc();
341         projectLocationTextField = new javax.swing.JTextField JavaDoc();
342         jButtonPrjLocation = new javax.swing.JButton JavaDoc();
343         jSeparator1 = new javax.swing.JSeparator JavaDoc();
344         jPanelOptions = new javax.swing.JPanel JavaDoc();
345         jLabelEnterprise = new javax.swing.JLabel JavaDoc();
346         jComboBoxEnterprise = new javax.swing.JComboBox JavaDoc();
347         setAsMainCheckBox = new javax.swing.JCheckBox JavaDoc();
348         jPanel1 = new javax.swing.JPanel JavaDoc();
349         serverInstanceLabel = new javax.swing.JLabel JavaDoc();
350         serverInstanceComboBox = new javax.swing.JComboBox JavaDoc();
351         j2eeSpecLabel = new javax.swing.JLabel JavaDoc();
352         j2eeSpecComboBox = new javax.swing.JComboBox JavaDoc();
353         jLabelContextPath = new javax.swing.JLabel JavaDoc();
354         jTextFieldContextPath = new javax.swing.JTextField JavaDoc();
355         manageServersButton = new javax.swing.JButton JavaDoc();
356         warningPlaceHolderPanel = new javax.swing.JPanel JavaDoc();
357
358         setLayout(new java.awt.GridBagLayout JavaDoc());
359
360         org.openide.awt.Mnemonics.setLocalizedText(jLabelSrcLocationDesc, NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_LocationSrcDesc")); // NOI18N
361
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
362         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
363         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
364         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
365         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
366         add(jLabelSrcLocationDesc, gridBagConstraints);
367
368         jLabelSrcLocation.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_ImportLocation_LabelMnemonic").charAt(0));
369         jLabelSrcLocation.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
370         jLabelSrcLocation.setLabelFor(moduleLocationTextField);
371         jLabelSrcLocation.setText(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_LocationSrc_Label")); // NOI18N
372
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
373         gridBagConstraints.gridx = 0;
374         gridBagConstraints.gridy = 1;
375         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
376         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
377         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
378         add(jLabelSrcLocation, gridBagConstraints);
379         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
380         gridBagConstraints.gridx = 1;
381         gridBagConstraints.gridy = 1;
382         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
383         gridBagConstraints.weightx = 1.0;
384         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
385         add(moduleLocationTextField, gridBagConstraints);
386         moduleLocationTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_IW_ImportLocation_A11YDesc")); // NOI18N
387

388         jButtonSrcLocation.setMnemonic(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_BrowseLocation_MNE").charAt(0));
389         jButtonSrcLocation.setText(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_BrowseLocation_Button")); // NOI18N
390
jButtonSrcLocation.addActionListener(new java.awt.event.ActionListener JavaDoc() {
391             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
392                 jButtonSrcLocationActionPerformed(evt);
393             }
394         });
395         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
396         gridBagConstraints.gridx = 2;
397         gridBagConstraints.gridy = 1;
398         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
399         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
400         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
401         add(jButtonSrcLocation, gridBagConstraints);
402         jButtonSrcLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_IW_ImportLocationBrowse_A11YDesc")); // NOI18N
403

404         org.openide.awt.Mnemonics.setLocalizedText(jLabelPrjLocationDesc, NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_LocationPrjDesc")); // NOI18N
405
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
406         gridBagConstraints.gridx = 0;
407         gridBagConstraints.gridy = 2;
408         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
409         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
410         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
411         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
412         add(jLabelPrjLocationDesc, gridBagConstraints);
413
414         jLabelPrjName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_ProjectName_LabelMnemonic").charAt(0));
415         jLabelPrjName.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
416         jLabelPrjName.setLabelFor(projectNameTextField);
417         jLabelPrjName.setText(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_ProjectName_Label")); // NOI18N
418
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
419         gridBagConstraints.gridx = 0;
420         gridBagConstraints.gridy = 3;
421         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
422         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
423         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 11);
424         add(jLabelPrjName, gridBagConstraints);
425         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
426         gridBagConstraints.gridx = 1;
427         gridBagConstraints.gridy = 3;
428         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
429         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 11);
430         add(projectNameTextField, gridBagConstraints);
431         projectNameTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NWP1_ProjectName_A11YDesc")); // NOI18N
432

433         jLabelPrjLocation.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_ProjectLocation_LabelMnemonic").charAt(0));
434         jLabelPrjLocation.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
435         jLabelPrjLocation.setLabelFor(projectLocationTextField);
436         jLabelPrjLocation.setText(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_CreatedProjectFolder_Lablel")); // NOI18N
437
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
438         gridBagConstraints.gridx = 0;
439         gridBagConstraints.gridy = 4;
440         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
441         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
442         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
443         add(jLabelPrjLocation, gridBagConstraints);
444
445         projectLocationTextField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
446             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
447                 projectLocationTextFieldKeyReleased(evt);
448             }
449         });
450         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
451         gridBagConstraints.gridx = 1;
452         gridBagConstraints.gridy = 4;
453         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
454         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
455         add(projectLocationTextField, gridBagConstraints);
456         projectLocationTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NPW1_ProjectLocation_A11YDesc")); // NOI18N
457

458         jButtonPrjLocation.setMnemonic(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_BrowseProjectFolder_MNE").charAt(0));
459         jButtonPrjLocation.setText(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_BrowseProjectLocation_Button")); // NOI18N
460
jButtonPrjLocation.addActionListener(new java.awt.event.ActionListener JavaDoc() {
461             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
462                 jButtonPrjLocationActionPerformed(evt);
463             }
464         });
465         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
466         gridBagConstraints.gridx = 2;
467         gridBagConstraints.gridy = 4;
468         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
469         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
470         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
471         add(jButtonPrjLocation, gridBagConstraints);
472         jButtonPrjLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NWP1_BrowseLocation_A11YDesc")); // NOI18N
473

474         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
475         gridBagConstraints.gridx = 0;
476         gridBagConstraints.gridy = 5;
477         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
478         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
479         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
480         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
481         add(jSeparator1, gridBagConstraints);
482
483         jPanelOptions.setLayout(new java.awt.GridBagLayout JavaDoc());
484
485         jLabelEnterprise.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_AddToEnterprise_LabelMnemonic").charAt(0));
486         jLabelEnterprise.setText(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_AddToEnterprise_Label")); // NOI18N
487
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
488         gridBagConstraints.gridx = 0;
489         gridBagConstraints.gridy = 0;
490         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
491         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
492         jPanelOptions.add(jLabelEnterprise, gridBagConstraints);
493         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
494         gridBagConstraints.gridx = 1;
495         gridBagConstraints.gridy = 0;
496         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
497         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
498         gridBagConstraints.weightx = 1.0;
499         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
500         jPanelOptions.add(jComboBoxEnterprise, gridBagConstraints);
501         jComboBoxEnterprise.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NWP1_AddToEnterpriseComboBox_A11YDesc")); // NOI18N
502

503         setAsMainCheckBox.setMnemonic(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_SetAsMain_CheckBoxMnemonic").charAt(0));
504         setAsMainCheckBox.setSelected(true);
505         setAsMainCheckBox.setText(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_SetAsMain_CheckBox")); // NOI18N
506
setAsMainCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
507         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
508         gridBagConstraints.gridx = 0;
509         gridBagConstraints.gridy = 3;
510         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
511         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
512         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
513         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
514         gridBagConstraints.weightx = 1.0;
515         gridBagConstraints.weighty = 1.0;
516         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
517         jPanelOptions.add(setAsMainCheckBox, gridBagConstraints);
518         setAsMainCheckBox.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NWP1_SetAsMain_A11YDesc")); // NOI18N
519

520         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
521
522         serverInstanceLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_Server_LabelMnemonic").charAt(0));
523         serverInstanceLabel.setLabelFor(serverInstanceComboBox);
524         serverInstanceLabel.setText(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_Server")); // NOI18N
525
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
526         gridBagConstraints.gridx = 0;
527         gridBagConstraints.gridy = 0;
528         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
529         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
530         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 11);
531         jPanel1.add(serverInstanceLabel, gridBagConstraints);
532
533         serverInstanceComboBox.setModel(serversModel);
534         serverInstanceComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
535             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
536                 serverInstanceComboBoxActionPerformed(evt);
537             }
538         });
539         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
540         gridBagConstraints.gridx = 1;
541         gridBagConstraints.gridy = 0;
542         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
543         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
544         gridBagConstraints.weightx = 1.0;
545         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
546         jPanel1.add(serverInstanceComboBox, gridBagConstraints);
547         serverInstanceComboBox.getAccessibleContext().setAccessibleName("Server");
548         serverInstanceComboBox.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_NWP1_Server_ComboBox_A11YDesc")); // NOI18N
549

550         j2eeSpecLabel.setDisplayedMnemonic(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_J2EESpecLevel_CheckBoxMnemonic").charAt(0));
551         j2eeSpecLabel.setLabelFor(j2eeSpecComboBox);
552         j2eeSpecLabel.setText(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_J2EESpecLevel_Label")); // NOI18N
553
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
554         gridBagConstraints.gridx = 0;
555         gridBagConstraints.gridy = 1;
556         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
557         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
558         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 11);
559         jPanel1.add(j2eeSpecLabel, gridBagConstraints);
560
561         j2eeSpecComboBox.setPrototypeDisplayValue("MMMMMMMMM" /* "Java EE 5" */);
562         j2eeSpecComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
563             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
564                 j2eeSpecComboBoxActionPerformed(evt);
565             }
566         });
567         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
568         gridBagConstraints.gridx = 1;
569         gridBagConstraints.gridy = 1;
570         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
571         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
572         jPanel1.add(j2eeSpecComboBox, gridBagConstraints);
573         j2eeSpecComboBox.getAccessibleContext().setAccessibleName("J2EE Version");
574         j2eeSpecComboBox.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NPW1_J2EESpecLevel_A11YDesc")); // NOI18N
575

576         jLabelContextPath.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_ContextPath_CheckBoxMnemonic").charAt(0));
577         jLabelContextPath.setLabelFor(jTextFieldContextPath);
578         jLabelContextPath.setText(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_ContextPath_Label")); // NOI18N
579
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
580         gridBagConstraints.gridx = 0;
581         gridBagConstraints.gridy = 2;
582         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
583         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
584         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
585         jPanel1.add(jLabelContextPath, gridBagConstraints);
586
587         jTextFieldContextPath.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
588             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
589                 jTextFieldContextPathKeyReleased(evt);
590             }
591         });
592         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
593         gridBagConstraints.gridx = 1;
594         gridBagConstraints.gridy = 2;
595         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
596         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
597         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
598         gridBagConstraints.weightx = 1.0;
599         gridBagConstraints.weighty = 1.0;
600         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
601         jPanel1.add(jTextFieldContextPath, gridBagConstraints);
602         jTextFieldContextPath.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NWP1_ContextPath_A11YDesc")); // NOI18N
603

604         org.openide.awt.Mnemonics.setLocalizedText(manageServersButton, org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_ManageServers")); // NOI18N
605
manageServersButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
606             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
607                 manageServersButtonActionPerformed(evt);
608             }
609         });
610         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
611         gridBagConstraints.gridx = 2;
612         gridBagConstraints.gridy = 0;
613         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
614         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 5, 0);
615         jPanel1.add(manageServersButton, gridBagConstraints);
616         manageServersButton.getAccessibleContext().setAccessibleName(null);
617         manageServersButton.getAccessibleContext().setAccessibleDescription(null);
618
619         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
620         gridBagConstraints.gridx = 0;
621         gridBagConstraints.gridy = 1;
622         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
623         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
624         jPanelOptions.add(jPanel1, gridBagConstraints);
625
626         warningPlaceHolderPanel.setLayout(new java.awt.BorderLayout JavaDoc());
627         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
628         gridBagConstraints.gridx = 0;
629         gridBagConstraints.gridy = 2;
630         gridBagConstraints.gridwidth = 2;
631         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
632         gridBagConstraints.weightx = 1.0;
633         jPanelOptions.add(warningPlaceHolderPanel, gridBagConstraints);
634
635         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
636         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
637         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
638         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
639         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
640         gridBagConstraints.weightx = 1.0;
641         gridBagConstraints.weighty = 1.0;
642         add(jPanelOptions, gridBagConstraints);
643     }// </editor-fold>//GEN-END:initComponents
644

645     private void j2eeSpecComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_j2eeSpecComboBoxActionPerformed
646
setJ2eeVersionWarningPanel();
647     }//GEN-LAST:event_j2eeSpecComboBoxActionPerformed
648

649     private void manageServersButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_manageServersButtonActionPerformed
650
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
651         String JavaDoc lastSelectedServerInstanceID = null;
652         if (serverInstanceWrapper != null) {
653             lastSelectedServerInstanceID = serverInstanceWrapper.getServerInstanceID();
654         }
655         ServerManager.showCustomizer(lastSelectedServerInstanceID);
656         String JavaDoc lastSelectedJ2eeSpecLevel = (String JavaDoc) j2eeSpecComboBox.getSelectedItem();
657         // refresh the list of servers
658
initServers(lastSelectedServerInstanceID);
659         if (lastSelectedJ2eeSpecLevel != null) {
660             j2eeSpecComboBox.setSelectedItem(lastSelectedJ2eeSpecLevel);
661         }
662     }//GEN-LAST:event_manageServersButtonActionPerformed
663

664     private void serverInstanceComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_serverInstanceComboBoxActionPerformed
665
String JavaDoc prevSelectedItem = (String JavaDoc) j2eeSpecComboBox.getSelectedItem();
666         // update the j2ee spec list according to the selected server
667
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
668         if (serverInstanceWrapper != null) {
669             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceWrapper.getServerInstanceID());
670             Set JavaDoc supportedVersions = j2eePlatform.getSupportedSpecVersions(J2eeModule.WAR);
671             j2eeSpecComboBox.removeAllItems();
672             if (supportedVersions.contains(J2eeModule.JAVA_EE_5)) {
673                 j2eeSpecComboBox.addItem(JAVA_EE_5_LABEL);
674             }
675             if (supportedVersions.contains(J2eeModule.J2EE_14)) {
676                 j2eeSpecComboBox.addItem(J2EE_SPEC_14_LABEL);
677             }
678             if (supportedVersions.contains(J2eeModule.J2EE_13)) {
679                 j2eeSpecComboBox.addItem(J2EE_SPEC_13_LABEL);
680             }
681             if (prevSelectedItem != null) {
682                 j2eeSpecComboBox.setSelectedItem(prevSelectedItem);
683             }
684         } else {
685             j2eeSpecComboBox.removeAllItems();
686         }
687         // revalidate the form
688
panel.fireChangeEvent();
689     }//GEN-LAST:event_serverInstanceComboBoxActionPerformed
690

691     private void projectLocationTextFieldKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_projectLocationTextFieldKeyReleased
692
locationModified = true;
693     }//GEN-LAST:event_projectLocationTextFieldKeyReleased
694

695     private void jTextFieldContextPathKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTextFieldContextPathKeyReleased
696
contextModified = true;
697     }//GEN-LAST:event_jTextFieldContextPathKeyReleased
698

699     private void jButtonPrjLocationActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonPrjLocationActionPerformed
700
JFileChooser chooser = org.netbeans.modules.web.project.ui.FileChooser.createDirectoryChooser(
701                 "ImportLocationVisual.Project", projectLocationTextField.getText()); //NOI18N
702
chooser.setDialogTitle(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_BrowseProjectFolder"));
703         if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
704             File JavaDoc projectDir = chooser.getSelectedFile();
705             projectLocationTextField.setText( projectDir.getAbsolutePath());
706         }
707     }//GEN-LAST:event_jButtonPrjLocationActionPerformed
708

709     private void jButtonSrcLocationActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonSrcLocationActionPerformed
710
JFileChooser chooser = new JFileChooser();
711         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
712         chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
713         chooser.setDialogTitle(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_BrowseExistingSource"));
714         
715         if (moduleLocationTextField.getText().length() > 0 && getProjectLocation().exists()) {
716             chooser.setSelectedFile(getProjectLocation());
717         } else {
718             // honor the contract in issue 58987
719
File JavaDoc currentDirectory = null;
720             FileObject existingSourcesFO = Templates.getExistingSourcesFolder(wizardDescriptor);
721             if (existingSourcesFO != null) {
722                 File JavaDoc existingSourcesFile = FileUtil.toFile(existingSourcesFO);
723                 if (existingSourcesFile != null && existingSourcesFile.isDirectory()) {
724                     currentDirectory = existingSourcesFile;
725                 }
726             }
727             if (currentDirectory != null) {
728                 chooser.setCurrentDirectory(currentDirectory);
729             } else {
730                 File JavaDoc lastUsedImportLoc = (File JavaDoc) FoldersListSettings.getDefault().getLastUsedImportLocation();
731                 if (lastUsedImportLoc != null)
732                     chooser.setCurrentDirectory(lastUsedImportLoc.getParentFile());
733                 else
734                     chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
735             }
736         }
737         
738         if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
739             File JavaDoc projectDir = FileUtil.normalizeFile(chooser.getSelectedFile());
740             moduleLocationTextField.setText(projectDir.getAbsolutePath());
741         }
742     }//GEN-LAST:event_jButtonSrcLocationActionPerformed
743

744     // Variables declaration - do not modify//GEN-BEGIN:variables
745
private javax.swing.JComboBox JavaDoc j2eeSpecComboBox;
746     private javax.swing.JLabel JavaDoc j2eeSpecLabel;
747     private javax.swing.JButton JavaDoc jButtonPrjLocation;
748     private javax.swing.JButton JavaDoc jButtonSrcLocation;
749     private javax.swing.JComboBox JavaDoc jComboBoxEnterprise;
750     private javax.swing.JLabel JavaDoc jLabelContextPath;
751     private javax.swing.JLabel JavaDoc jLabelEnterprise;
752     private javax.swing.JLabel JavaDoc jLabelPrjLocation;
753     private javax.swing.JLabel JavaDoc jLabelPrjLocationDesc;
754     private javax.swing.JLabel JavaDoc jLabelPrjName;
755     private javax.swing.JLabel JavaDoc jLabelSrcLocation;
756     private javax.swing.JLabel JavaDoc jLabelSrcLocationDesc;
757     private javax.swing.JPanel JavaDoc jPanel1;
758     private javax.swing.JPanel JavaDoc jPanelOptions;
759     private javax.swing.JSeparator JavaDoc jSeparator1;
760     protected javax.swing.JTextField JavaDoc jTextFieldContextPath;
761     private javax.swing.JButton JavaDoc manageServersButton;
762     public javax.swing.JTextField JavaDoc moduleLocationTextField;
763     public javax.swing.JTextField JavaDoc projectLocationTextField;
764     public javax.swing.JTextField JavaDoc projectNameTextField;
765     private javax.swing.JComboBox JavaDoc serverInstanceComboBox;
766     private javax.swing.JLabel JavaDoc serverInstanceLabel;
767     private javax.swing.JCheckBox JavaDoc setAsMainCheckBox;
768     private javax.swing.JPanel JavaDoc warningPlaceHolderPanel;
769     // End of variables declaration//GEN-END:variables
770

771     private String JavaDoc lastComputedPrjName = null;
772     private String JavaDoc computeProjectName() {
773         String JavaDoc cPrjName = null;
774         FileObject fo = FileUtil.toFileObject(getProjectLocation());
775         if (fo != null) {
776             cPrjName = fo.getName();
777         }
778         return cPrjName;
779     }
780     
781     private String JavaDoc lastComputedPrjFolder = null;
782     private String JavaDoc computeProjectFolder() {
783         return getProjectLocation().getAbsolutePath();
784     }
785     
786     private String JavaDoc lastComputedContextPath = null;
787     private String JavaDoc computeContextPath() {
788         return Utils.createDefaultContext(projectNameTextField.getText());
789     }
790     
791     boolean ignoreLocEvent = false;
792     // handles changes in Location
793
private void locationDataChanged(DocumentEvent JavaDoc de) {
794         if (!ignoreLocEvent) {
795             ignoreLocEvent = true;
796             if (de.getDocument() == moduleDocument) {
797                 updateProjectName();
798                 updateProjectFolder();
799             }
800             ignoreLocEvent = false;
801         }
802         fireChanges();
803     }
804     
805     boolean ignoreNameEvent = false;
806     // handles changes in Project Name
807
private void nameDataChanged(DocumentEvent JavaDoc de) {
808         if (!ignoreNameEvent) {
809             ignoreNameEvent = true;
810             if (de.getDocument() == nameDocument) {
811                 updateProjectFolder();
812                 updateContextPath();
813             }
814             ignoreNameEvent = false;
815         }
816         fireChanges();
817     }
818     
819     private void updateProjectName() {
820         String JavaDoc prjName = computeProjectName();
821         if ((lastComputedPrjName != null) && (!lastComputedPrjName.equals(projectNameTextField.getText().trim()))) {
822             return;
823         }
824         lastComputedPrjName = prjName;
825         if (prjName != null) {
826             projectNameTextField.setText(prjName);
827         }
828     }
829     
830     private void updateProjectFolder() {
831         String JavaDoc prjFolder = computeProjectFolder();
832         if ((lastComputedPrjFolder != null) && (!lastComputedPrjFolder.equals(projectLocationTextField.getText().trim()))) {
833             return;
834         }
835         lastComputedPrjFolder = prjFolder;
836         if (prjFolder != null) {
837             projectLocationTextField.setText(prjFolder);
838         } else {
839             projectLocationTextField.setText(""); // NOI18N
840
}
841     }
842     
843     private void updateContextPath() {
844         String JavaDoc ctxPath = computeContextPath();
845         if ((lastComputedContextPath != null) && (!lastComputedContextPath.equals(jTextFieldContextPath.getText().trim()))) {
846             return;
847         }
848         lastComputedContextPath = ctxPath;
849         if (ctxPath != null) {
850             jTextFieldContextPath.setText(ctxPath);
851         }
852     }
853     
854     private void fireChanges() {
855         panel.fireChangeEvent();
856     }
857     
858     /** Help context where to find more about the paste type action.
859      * @return the help context for this action
860      */

861     public HelpCtx getHelpCtx() {
862         return new HelpCtx(ImportLocationVisual.class);
863     }
864     
865     /**
866      * Init servers model
867      * @param selectedServerInstanceID preselected instance or null if non is preselected
868      */

869     private void initServers(String JavaDoc selectedServerInstanceID) {
870         // init the list of server instances
871
serversModel.removeAllElements();
872         Set JavaDoc<ServerInstanceWrapper> servers = new TreeSet JavaDoc<ServerInstanceWrapper>();
873         ServerInstanceWrapper selectedItem = null;
874         boolean sjasFound = false;
875         for (String JavaDoc serverInstanceID : Deployment.getDefault().getServerInstanceIDs()) {
876             String JavaDoc displayName = Deployment.getDefault().getServerInstanceDisplayName(serverInstanceID);
877             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID);
878             if (displayName != null && j2eePlatform != null && j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.WAR)) {
879                 ServerInstanceWrapper serverWrapper = new ServerInstanceWrapper(serverInstanceID, displayName);
880                 // decide whether this server should be preselected
881
if (selectedItem == null || !sjasFound) {
882                     if (selectedServerInstanceID != null) {
883                         if (selectedServerInstanceID.equals(serverInstanceID)) {
884                             selectedItem = serverWrapper;
885                         }
886                     } else {
887                         // preselect the best server ;)
888
String JavaDoc shortName = Deployment.getDefault().getServerID(serverInstanceID);
889                         if ("J2EE".equals(shortName)) { // NOI18N
890
selectedItem = serverWrapper;
891                             sjasFound = true;
892                         }
893                         else
894                         if ("JBoss4".equals(shortName)) { // NOI18N
895
selectedItem = serverWrapper;
896                         }
897                     }
898                 }
899                 servers.add(serverWrapper);
900             }
901         }
902         for (ServerInstanceWrapper item : servers) {
903             serversModel.addElement(item);
904         }
905         if (selectedItem != null) {
906             // set the preselected item
907
serversModel.setSelectedItem(selectedItem);
908         } else if (serversModel.getSize() > 0) {
909             // set the first item
910
serversModel.setSelectedItem(serversModel.getElementAt(0));
911         }
912     }
913
914     private Project getSelectedEarApplication() {
915         int idx = jComboBoxEnterprise.getSelectedIndex();
916         return (idx <= 0) ? null : (Project) earProjects.get(idx - 1);
917     }
918     
919     private void initEnterpriseApplications() {
920         jComboBoxEnterprise.addItem(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_AddToEnterprise_None"));
921         jComboBoxEnterprise.setSelectedIndex(0);
922         
923         Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
924         earProjects = new ArrayList JavaDoc();
925         for (int i = 0; i < allProjects.length; i++) {
926             J2eeModuleContainer container = (J2eeModuleContainer) allProjects[i].getLookup().lookup(J2eeModuleContainer.class);
927             ProjectInformation projectInfo = ProjectUtils.getInformation(allProjects[i]);
928             if (container != null) {
929                 earProjects.add(projectInfo.getProject());
930                 jComboBoxEnterprise.addItem(projectInfo.getDisplayName());
931             }
932         }
933         if (earProjects.size() <= 0) {
934             jComboBoxEnterprise.setEnabled(false);
935         }
936     }
937
938     private String JavaDoc getSelectedJ2eeSpec() {
939         Object JavaDoc item = j2eeSpecComboBox.getSelectedItem();
940         String JavaDoc value = null;
941         if (item != null){
942             if (item.equals(JAVA_EE_5_LABEL)) value = J2eeModule.JAVA_EE_5;
943             else if (item.equals(J2EE_SPEC_14_LABEL)) value = J2eeModule.J2EE_14;
944             else if (item.equals(J2EE_SPEC_13_LABEL)) value = J2eeModule.J2EE_13;
945         }
946         return value;
947     }
948     
949     private String JavaDoc getSelectedServer() {
950         ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
951         if (serverInstanceWrapper == null) {
952             return null;
953         }
954         return serverInstanceWrapper.getServerInstanceID();
955     }
956
957     private String JavaDoc validFreeProjectName (final File JavaDoc parentFolder, final String JavaDoc formater, final int index) {
958         String JavaDoc name = MessageFormat.format (formater, new Object JavaDoc[]{Integer.valueOf(index)});
959         File JavaDoc file = new File JavaDoc (parentFolder, name);
960         return file.exists() ? null : name;
961     }
962     
963     private void setJ2eeVersionWarningPanel() {
964         String JavaDoc j2ee = getSelectedJ2eeSpec();
965         if (j2ee == null)
966             return;
967         String JavaDoc warningType = J2eeVersionWarningPanel.findWarningType(j2ee);
968         if (warningType == null && warningPanel == null)
969             return;
970         if (warningPanel == null) {
971             warningPanel = new J2eeVersionWarningPanel(warningType);
972             warningPlaceHolderPanel.add(warningPanel, java.awt.BorderLayout.CENTER);
973             warningPanel.setWarningType(warningType);
974         } else {
975             warningPanel.setWarningType(warningType);
976         }
977     }
978     
979     public File JavaDoc getProjectLocation() {
980         return getAsFile(moduleLocationTextField.getText());
981     }
982     
983     private File JavaDoc getAsFile(String JavaDoc filename) {
984         return FileUtil.normalizeFile(new File JavaDoc(filename));
985     }
986
987     /**
988      * Server instance wrapper represents server instances in the servers combobox.
989      * @author sherold
990      */

991     private static class ServerInstanceWrapper implements Comparable JavaDoc {
992
993         private final String JavaDoc serverInstanceID;
994         private final String JavaDoc displayName;
995
996         ServerInstanceWrapper(String JavaDoc serverInstanceID, String JavaDoc displayName) {
997             this.serverInstanceID = serverInstanceID;
998             this.displayName = displayName;
999         }
1000
1001        public String JavaDoc getServerInstanceID() {
1002            return serverInstanceID;
1003        }
1004
1005        public String JavaDoc toString() {
1006            return displayName;
1007        }
1008
1009        public int compareTo(Object JavaDoc o) {
1010            return toString().compareTo(o.toString());
1011        }
1012    }
1013}
1014
Popular Tags