KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > 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.j2ee.clientproject.ui.wizards;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.math.BigDecimal JavaDoc;
28 import java.text.MessageFormat JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Set JavaDoc;
32 import java.util.TreeSet JavaDoc;
33 import javax.swing.DefaultComboBoxModel JavaDoc;
34 import javax.swing.JButton JavaDoc;
35 import javax.swing.JFileChooser JavaDoc;
36 import javax.swing.JPanel JavaDoc;
37 import javax.swing.event.DocumentEvent JavaDoc;
38 import javax.swing.event.DocumentListener JavaDoc;
39 import org.netbeans.api.project.Project;
40 import org.netbeans.api.project.ProjectInformation;
41 import org.netbeans.api.project.ProjectManager;
42 import org.netbeans.api.project.ProjectUtils;
43 import org.netbeans.api.project.ui.OpenProjects;
44 import org.netbeans.modules.j2ee.clientproject.AppClientProvider;
45 import org.netbeans.modules.j2ee.clientproject.ui.FoldersListSettings;
46 import org.netbeans.modules.j2ee.dd.api.client.AppClient;
47 import org.netbeans.modules.j2ee.dd.api.client.DDProvider;
48 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
49 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
50 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModuleContainer;
51 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
52 import org.netbeans.modules.j2ee.deployment.devmodules.api.ServerManager;
53 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
54 import org.netbeans.spi.project.ui.support.ProjectChooser;
55 import org.netbeans.spi.project.ui.templates.support.Templates;
56 import org.openide.DialogDescriptor;
57 import org.openide.DialogDisplayer;
58 import org.openide.ErrorManager;
59 import org.openide.NotifyDescriptor;
60 import org.openide.WizardDescriptor;
61 import org.openide.WizardValidationException;
62 import org.openide.filesystems.FileObject;
63 import org.openide.filesystems.FileUtil;
64 import org.openide.util.NbBundle;
65
66 /**
67  *
68  * @author pb97924, Martin Adamek
69  */

70 public class ImportLocationVisual extends JPanel JavaDoc /*implements DocumentListener */{
71     
72     private final DefaultComboBoxModel JavaDoc serversModel = new DefaultComboBoxModel JavaDoc();
73     private static final String JavaDoc J2EE_SPEC_15_LABEL = NbBundle.getMessage(ImportLocationVisual.class, "J2EESpecLevel_15"); //NOI18N
74
private static final String JavaDoc J2EE_SPEC_14_LABEL = NbBundle.getMessage(ImportLocationVisual.class, "J2EESpecLevel_14"); //NOI18N
75
private static final String JavaDoc J2EE_SPEC_13_LABEL = NbBundle.getMessage(ImportLocationVisual.class, "J2EESpecLevel_13"); //NOI18N
76
private final ImportLocation panel;
77     private final DocumentListener JavaDoc documentListener;
78     /** Was projectFolder property edited by user? */
79     private boolean projectFolderTouched;
80     /** Was projectName property edited by user? */
81     private boolean projectNameTouched;
82     private List JavaDoc<Project> earProjects;
83     private WizardDescriptor wizardDescriptor;
84     private J2eeVersionWarningPanel warningPanel;
85         
86     /** Creates new form TestPanel */
87     public ImportLocationVisual (ImportLocation panel) {
88         this.panel = panel;
89         initComponents ();
90         setJ2eeVersionWarningPanel();
91         initServers(FoldersListSettings.getDefault().getLastUsedServer());
92         // preselect the first item in the j2ee spec combo
93
if (j2eeSpecComboBox.getModel().getSize() > 0) {
94             j2eeSpecComboBox.setSelectedIndex(0);
95         }
96         initEnterpriseApplications();
97         this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_NWP1_NamePanel_A11YDesc")); // NOI18N
98
setName(NbBundle.getBundle("org/netbeans/modules/j2ee/clientproject/ui/wizards/Bundle").getString("LBL_IW_ImportTitle")); //NOI18N
99
putClientProperty ("NewProjectWizard_Title", NbBundle.getMessage(ImportLocationVisual.class, "TXT_ImportAppClientModule")); //NOI18N
100
this.projectName.setText("");
101         documentListener = new DocumentListener JavaDoc() {
102             public void insertUpdate(DocumentEvent JavaDoc e) {
103                 update(e);
104             }
105
106             public void removeUpdate(DocumentEvent JavaDoc e) {
107                 update(e);
108             }
109
110             public void changedUpdate(DocumentEvent JavaDoc e) {
111                 update(e);
112             }
113         };
114         this.projectName.getDocument().addDocumentListener(documentListener);
115         this.projectFolder.getDocument().addDocumentListener(documentListener);
116     }
117     
118     /** This method is called from within the constructor to
119      * initialize the form.
120      * WARNING: Do NOT modify this code. The content of this method is
121      * always regenerated by the Form Editor.
122      */

123     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
124
private void initComponents() {
125         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
126
127         jLabelSrcLocationDesc = new javax.swing.JLabel JavaDoc();
128         jLabelSrcLocation = new javax.swing.JLabel JavaDoc();
129         projectLocation = new javax.swing.JTextField JavaDoc();
130         browseProjectLocation = new javax.swing.JButton JavaDoc();
131         jLabelPrjLocationDesc = new javax.swing.JLabel JavaDoc();
132         jLabelPrjName = new javax.swing.JLabel JavaDoc();
133         projectName = new javax.swing.JTextField JavaDoc();
134         jLabelPrjLocation = new javax.swing.JLabel JavaDoc();
135         projectFolder = new javax.swing.JTextField JavaDoc();
136         browseProjectFolder = new javax.swing.JButton JavaDoc();
137         jSeparator1 = new javax.swing.JSeparator JavaDoc();
138         jPanel1 = new javax.swing.JPanel JavaDoc();
139         jCheckBox1 = new javax.swing.JCheckBox JavaDoc();
140         serverInstanceLabel = new javax.swing.JLabel JavaDoc();
141         serverInstanceComboBox = new javax.swing.JComboBox JavaDoc();
142         jLabel7 = new javax.swing.JLabel JavaDoc();
143         j2eeSpecComboBox = new javax.swing.JComboBox JavaDoc();
144         addToAppLabel = new javax.swing.JLabel JavaDoc();
145         addToAppComboBox = new javax.swing.JComboBox JavaDoc();
146         warningPlaceHolderPanel = new javax.swing.JPanel JavaDoc();
147         manageServersButton = new javax.swing.JButton JavaDoc();
148
149         setNextFocusableComponent(projectLocation);
150         setLayout(new java.awt.GridBagLayout JavaDoc());
151
152         org.openide.awt.Mnemonics.setLocalizedText(jLabelSrcLocationDesc, NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_LocationSrcDesc")); // NOI18N
153
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
154         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
155         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
156         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
157         add(jLabelSrcLocationDesc, gridBagConstraints);
158
159         jLabelSrcLocation.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
160         jLabelSrcLocation.setLabelFor(projectLocation);
161         org.openide.awt.Mnemonics.setLocalizedText(jLabelSrcLocation, NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_LocationSrc_Label")); // NOI18N
162
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.gridx = 0;
164         gridBagConstraints.gridy = 1;
165         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
166         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
167         add(jLabelSrcLocation, gridBagConstraints);
168         jLabelSrcLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_IW_Location_A11Desc")); // NOI18N
169

170         projectLocation.setNextFocusableComponent(browseProjectLocation);
171         projectLocation.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
172             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
173                 projectLocationFocusLost(evt);
174             }
175         });
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.gridx = 1;
178         gridBagConstraints.gridy = 1;
179         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
180         gridBagConstraints.weightx = 1.0;
181         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
182         add(projectLocation, gridBagConstraints);
183         projectLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_IW_ImportLocation_A11YDesc")); // NOI18N
184

185         org.openide.awt.Mnemonics.setLocalizedText(browseProjectLocation, NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_BrowseLocation_Button_w")); // NOI18N
186
browseProjectLocation.setNextFocusableComponent(projectName);
187         browseProjectLocation.addActionListener(new java.awt.event.ActionListener JavaDoc() {
188             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
189                 browseProjectLocationActionPerformed(evt);
190             }
191         });
192         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
193         gridBagConstraints.gridx = 2;
194         gridBagConstraints.gridy = 1;
195         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
196         add(browseProjectLocation, gridBagConstraints);
197         browseProjectLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_IW_ImportLocationBrowse_A11YDesc")); // NOI18N
198

199         org.openide.awt.Mnemonics.setLocalizedText(jLabelPrjLocationDesc, NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_LocationPrjDesc")); // NOI18N
200
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
201         gridBagConstraints.gridx = 0;
202         gridBagConstraints.gridy = 2;
203         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
204         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
205         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
206         add(jLabelPrjLocationDesc, gridBagConstraints);
207
208         jLabelPrjName.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
209         jLabelPrjName.setLabelFor(projectName);
210         org.openide.awt.Mnemonics.setLocalizedText(jLabelPrjName, org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_ProjectName_Label")); // NOI18N
211
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
212         gridBagConstraints.gridx = 0;
213         gridBagConstraints.gridy = 3;
214         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
215         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
216         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
217         add(jLabelPrjName, gridBagConstraints);
218         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/clientproject/ui/wizards/Bundle"); // NOI18N
219
jLabelPrjName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_LBL_IW_ProjectName_A11Desc")); // NOI18N
220

221         projectName.setNextFocusableComponent(projectFolder);
222         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
223         gridBagConstraints.gridx = 1;
224         gridBagConstraints.gridy = 3;
225         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
226         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
227         add(projectName, gridBagConstraints);
228         projectName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NWP1_ProjectName_A11YDesc")); // NOI18N
229

230         jLabelPrjLocation.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
231         jLabelPrjLocation.setLabelFor(projectFolder);
232         org.openide.awt.Mnemonics.setLocalizedText(jLabelPrjLocation, NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_CreatedProjectFolder_Label")); // NOI18N
233
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
234         gridBagConstraints.gridx = 0;
235         gridBagConstraints.gridy = 4;
236         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
237         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
238         add(jLabelPrjLocation, gridBagConstraints);
239         jLabelPrjLocation.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_LBL_IW_ProjectFolder_A11Desc")); // NOI18N
240

241         projectFolder.setNextFocusableComponent(browseProjectFolder);
242         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
243         gridBagConstraints.gridx = 1;
244         gridBagConstraints.gridy = 4;
245         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
246         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
247         add(projectFolder, gridBagConstraints);
248         projectFolder.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NPW1_ProjectLocation_A11YDesc")); // NOI18N
249

250         org.openide.awt.Mnemonics.setLocalizedText(browseProjectFolder, NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_BrowseLocation_Button")); // NOI18N
251
browseProjectFolder.addActionListener(new java.awt.event.ActionListener JavaDoc() {
252             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
253                 browseProjectFolderActionPerformed(evt);
254             }
255         });
256         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
257         gridBagConstraints.gridx = 2;
258         gridBagConstraints.gridy = 4;
259         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
260         add(browseProjectFolder, gridBagConstraints);
261         browseProjectFolder.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NWP1_BrowseLocation_A11YDesc")); // NOI18N
262

263         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
264         gridBagConstraints.gridx = 0;
265         gridBagConstraints.gridy = 5;
266         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
267         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
268         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
269         gridBagConstraints.weightx = 1.0;
270         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
271         add(jSeparator1, gridBagConstraints);
272
273         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
274
275         jCheckBox1.setSelected(true);
276         org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, bundle.getString("LBL_IW_SetAsMainProject_CheckBox")); // NOI18N
277
jCheckBox1.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
278         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
279         gridBagConstraints.gridx = 0;
280         gridBagConstraints.gridy = 4;
281         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
282         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
283         gridBagConstraints.weightx = 1.0;
284         gridBagConstraints.weighty = 1.0;
285         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
286         jPanel1.add(jCheckBox1, gridBagConstraints);
287         jCheckBox1.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_LBL_IW_SetAsMainProject_A11YDesc")); // NOI18N
288

289         serverInstanceLabel.setLabelFor(serverInstanceComboBox);
290         org.openide.awt.Mnemonics.setLocalizedText(serverInstanceLabel, org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Server")); // NOI18N
291
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
292         gridBagConstraints.gridx = 0;
293         gridBagConstraints.gridy = 1;
294         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
295         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 11);
296         jPanel1.add(serverInstanceLabel, gridBagConstraints);
297
298         serverInstanceComboBox.setModel(serversModel);
299         serverInstanceComboBox.setNextFocusableComponent(j2eeSpecComboBox);
300         serverInstanceComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
301             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
302                 serverInstanceComboBoxActionPerformed(evt);
303             }
304         });
305         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
306         gridBagConstraints.gridx = 1;
307         gridBagConstraints.gridy = 1;
308         gridBagConstraints.gridwidth = 2;
309         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
310         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
311         gridBagConstraints.weightx = 1.0;
312         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
313         jPanel1.add(serverInstanceComboBox, gridBagConstraints);
314         serverInstanceComboBox.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_LBL_IW_SelectServerInstance_A11YDesc")); // NOI18N
315

316         jLabel7.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_SelectJ2EEVersion_LabelMnemonic").charAt(0));
317         jLabel7.setLabelFor(j2eeSpecComboBox);
318         jLabel7.setText(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_J2EESpecLevel_Label")); // NOI18N
319
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
320         gridBagConstraints.gridx = 0;
321         gridBagConstraints.gridy = 2;
322         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
323         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
324         jPanel1.add(jLabel7, gridBagConstraints);
325
326         j2eeSpecComboBox.setNextFocusableComponent(jCheckBox1);
327         j2eeSpecComboBox.setPrototypeDisplayValue("MMMMMMMMM" /* "Java EE 5" */);
328         j2eeSpecComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
329             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
330                 j2eeSpecComboBoxActionPerformed(evt);
331             }
332         });
333         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
334         gridBagConstraints.gridx = 1;
335         gridBagConstraints.gridy = 2;
336         gridBagConstraints.gridwidth = 2;
337         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
338         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
339         jPanel1.add(j2eeSpecComboBox, gridBagConstraints);
340         j2eeSpecComboBox.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_LBL_IW_SelectJ2EEVersion_A11YDesc")); // NOI18N
341

342         addToAppLabel.setLabelFor(addToAppComboBox);
343         org.openide.awt.Mnemonics.setLocalizedText(addToAppLabel, bundle.getString("LBL_NWP1_AddToEApp_CheckBox")); // NOI18N
344
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
345         gridBagConstraints.gridx = 0;
346         gridBagConstraints.gridy = 0;
347         gridBagConstraints.gridwidth = 2;
348         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
349         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
350         jPanel1.add(addToAppLabel, gridBagConstraints);
351
352         addToAppComboBox.setNextFocusableComponent(serverInstanceComboBox);
353         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
354         gridBagConstraints.gridx = 2;
355         gridBagConstraints.gridy = 0;
356         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
357         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
358         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
359         gridBagConstraints.weightx = 1.0;
360         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
361         jPanel1.add(addToAppComboBox, gridBagConstraints);
362
363         warningPlaceHolderPanel.setLayout(new java.awt.BorderLayout JavaDoc());
364         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
365         gridBagConstraints.gridx = 0;
366         gridBagConstraints.gridy = 3;
367         gridBagConstraints.gridwidth = 3;
368         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
369         gridBagConstraints.weightx = 1.0;
370         jPanel1.add(warningPlaceHolderPanel, gridBagConstraints);
371
372         org.openide.awt.Mnemonics.setLocalizedText(manageServersButton, org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_ManageServers")); // NOI18N
373
manageServersButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
374             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
375                 manageServersButtonActionPerformed(evt);
376             }
377         });
378         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
379         gridBagConstraints.gridx = 3;
380         gridBagConstraints.gridy = 1;
381         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
382         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 5, 0);
383         jPanel1.add(manageServersButton, gridBagConstraints);
384         manageServersButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ASCN_ManageServers")); // NOI18N
385
manageServersButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ASCD_ManageServers")); // NOI18N
386

387         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
388         gridBagConstraints.gridx = 0;
389         gridBagConstraints.gridy = 6;
390         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
391         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
392         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
393         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
394         gridBagConstraints.weightx = 1.0;
395         gridBagConstraints.weighty = 1.0;
396         add(jPanel1, gridBagConstraints);
397
398         getAccessibleContext().setAccessibleName(null);
399         getAccessibleContext().setAccessibleDescription(null);
400     }// </editor-fold>//GEN-END:initComponents
401

402     private void manageServersButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_manageServersButtonActionPerformed
403
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
404         String JavaDoc lastSelectedServerInstanceID = null;
405         if (serverInstanceWrapper != null) {
406             lastSelectedServerInstanceID = serverInstanceWrapper.getServerInstanceID();
407         }
408         ServerManager.showCustomizer(lastSelectedServerInstanceID);
409         String JavaDoc lastSelectedJ2eeSpecLevel = (String JavaDoc) j2eeSpecComboBox.getSelectedItem();
410         // refresh the list of servers
411
initServers(lastSelectedServerInstanceID);
412         if (lastSelectedJ2eeSpecLevel != null) {
413             j2eeSpecComboBox.setSelectedItem(lastSelectedJ2eeSpecLevel);
414         }
415     }//GEN-LAST:event_manageServersButtonActionPerformed
416

417     private void j2eeSpecComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_j2eeSpecComboBoxActionPerformed
418
setJ2eeVersionWarningPanel();
419     }//GEN-LAST:event_j2eeSpecComboBoxActionPerformed
420

421     private void projectLocationFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_projectLocationFocusLost
422
if (projectLocation.getText().trim().length() > 0) {
423             updateProjectName();
424             updateProjectFolder();
425             updateJ2EEVersion();
426             panel.stateChanged(null);
427         }
428     }//GEN-LAST:event_projectLocationFocusLost
429

430     private void serverInstanceComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_serverInstanceComboBoxActionPerformed
431
String JavaDoc prevSelectedItem = (String JavaDoc) j2eeSpecComboBox.getSelectedItem();
432         // update the j2ee spec list according to the selected server
433
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
434         if (serverInstanceWrapper != null) {
435             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceWrapper.getServerInstanceID());
436             Set JavaDoc supportedVersions = j2eePlatform.getSupportedSpecVersions(J2eeModule.CLIENT);
437             j2eeSpecComboBox.removeAllItems();
438             if (supportedVersions.contains(J2eeModule.JAVA_EE_5)) {
439                 j2eeSpecComboBox.addItem(J2EE_SPEC_15_LABEL);
440             }
441             if (supportedVersions.contains(J2eeModule.J2EE_14)) {
442                 j2eeSpecComboBox.addItem(J2EE_SPEC_14_LABEL);
443             }
444             if (prevSelectedItem != null) {
445                 j2eeSpecComboBox.setSelectedItem(prevSelectedItem);
446             }
447         } else {
448             j2eeSpecComboBox.removeAllItems();
449         }
450         // revalidate the form
451
panel.fireChangeEvent();
452     }//GEN-LAST:event_serverInstanceComboBoxActionPerformed
453

454     private void browseProjectFolderActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseProjectFolderActionPerformed
455
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
456         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
457         chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
458         if (projectFolder.getText().length() > 0 && getProjectFolder().exists()) {
459             chooser.setSelectedFile(getProjectFolder());
460         } else if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) {
461             chooser.setSelectedFile(getProjectLocation());
462         } else {
463             chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
464         }
465         chooser.setDialogTitle(NbBundle.getMessage(ImportLocationVisual.class, "LBL_SelectNewLocation")); // NOI18N
466
if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
467             File JavaDoc projectDir = FileUtil.normalizeFile(chooser.getSelectedFile());
468             projectFolder.setText(projectDir.getAbsolutePath());
469         }
470     }//GEN-LAST:event_browseProjectFolderActionPerformed
471

472     private void browseProjectLocationActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseProjectLocationActionPerformed
473
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
474         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
475         chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
476         if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) {
477             chooser.setSelectedFile(getProjectLocation());
478         } else {
479             // honor the contract in issue 58987
480
File JavaDoc currentDirectory = null;
481             FileObject existingSourcesFO = Templates.getExistingSourcesFolder(wizardDescriptor);
482             if (existingSourcesFO != null) {
483                 File JavaDoc existingSourcesFile = FileUtil.toFile(existingSourcesFO);
484                 if (existingSourcesFile != null && existingSourcesFile.isDirectory()) {
485                     currentDirectory = existingSourcesFile;
486                 }
487             }
488             if (currentDirectory != null) {
489                 chooser.setCurrentDirectory(currentDirectory);
490             } else {
491                 chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
492             }
493         }
494         
495         chooser.setDialogTitle(NbBundle.getMessage(ImportLocationVisual.class, "LBL_SelectExistingLocation")); // NOI18N
496
if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
497             projectLocation.setText(FileUtil.normalizeFile(chooser.getSelectedFile()).getAbsolutePath());
498             updateJ2EEVersion();
499             updateProjectName();
500             updateProjectFolder();
501             panel.stateChanged(null);
502         }
503     }//GEN-LAST:event_browseProjectLocationActionPerformed
504

505     // Variables declaration - do not modify//GEN-BEGIN:variables
506
private javax.swing.JComboBox JavaDoc addToAppComboBox;
507     private javax.swing.JLabel JavaDoc addToAppLabel;
508     private javax.swing.JButton JavaDoc browseProjectFolder;
509     private javax.swing.JButton JavaDoc browseProjectLocation;
510     private javax.swing.JComboBox JavaDoc j2eeSpecComboBox;
511     private javax.swing.JCheckBox JavaDoc jCheckBox1;
512     private javax.swing.JLabel JavaDoc jLabel7;
513     private javax.swing.JLabel JavaDoc jLabelPrjLocation;
514     private javax.swing.JLabel JavaDoc jLabelPrjLocationDesc;
515     private javax.swing.JLabel JavaDoc jLabelPrjName;
516     private javax.swing.JLabel JavaDoc jLabelSrcLocation;
517     private javax.swing.JLabel JavaDoc jLabelSrcLocationDesc;
518     private javax.swing.JPanel JavaDoc jPanel1;
519     private javax.swing.JSeparator JavaDoc jSeparator1;
520     private javax.swing.JButton JavaDoc manageServersButton;
521     public javax.swing.JTextField JavaDoc projectFolder;
522     public javax.swing.JTextField JavaDoc projectLocation;
523     public javax.swing.JTextField JavaDoc projectName;
524     private javax.swing.JComboBox JavaDoc serverInstanceComboBox;
525     private javax.swing.JLabel JavaDoc serverInstanceLabel;
526     private javax.swing.JPanel JavaDoc warningPlaceHolderPanel;
527     // End of variables declaration//GEN-END:variables
528

529     private boolean ignoreEvent;
530
531     private void update(DocumentEvent JavaDoc e) {
532         if (ignoreEvent) {
533             // side-effect of changes done in this handler
534
return;
535         }
536
537         // start ignoring events
538
ignoreEvent = true;
539
540         if (projectLocation.getDocument() == e.getDocument()) {
541             updateProjectName();
542             updateProjectFolder();
543         }
544
545         // stop ignoring events
546
ignoreEvent = false;
547
548         if (projectFolder.getDocument() == e.getDocument()) {
549             projectFolderTouched = !"".equals(projectFolder.getText());
550         }
551         if (projectName.getDocument() == e.getDocument()) {
552             projectNameTouched = !"".equals(projectName.getText());
553         }
554         panel.stateChanged(null);
555     }
556
557     private void updateProjectName() {
558         if (projectNameTouched) {
559             return;
560         }
561         FileObject fo = FileUtil.toFileObject(getProjectLocation());
562         if (fo != null) {
563             projectName.setText(fo.getName()); // NOI18N
564
}
565     }
566     
567     private void updateJ2EEVersion() {
568         File JavaDoc f = new File JavaDoc(projectLocation.getText().trim());
569         FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(f));
570         if (fo != null) {
571             FileObject configFilesPath = FileSearchUtility.guessConfigFilesPath(fo);
572             if (configFilesPath != null) {
573                 FileObject appClientXML = configFilesPath.getFileObject(AppClientProvider.FILE_DD);
574                 checkACXmlJ2eeVersion(appClientXML);
575             } else {
576                 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_15_LABEL);
577             }
578         }
579     }
580     
581     private void updateProjectFolder() {
582         if (projectFolderTouched) {
583             return;
584         }
585         if (isValidProjectLocation()) {
586             projectFolder.setText(getProjectLocation().getAbsolutePath());
587         } else {
588             projectFolder.setText(""); // NOI18N
589
}
590     }
591
592     private boolean isValidProjectLocation() {
593         return (getProjectLocation().exists() && getProjectLocation().isDirectory() &&
594                 projectLocation.getText().length() > 0 && (!projectLocation.getText().endsWith(":"))); // NOI18N
595
}
596
597     public boolean valid(WizardDescriptor wizardDescriptor) {
598         File JavaDoc prjDir = new File JavaDoc(projectLocation.getText().trim());
599 // File prjFolder = new File(projectFolder.getText().trim());
600
String JavaDoc prjName = projectName.getText().trim();
601         
602         if (getSelectedServerInstanceID() == null) {
603             wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_NoServer")); //NOI18N
604
return false;
605         }
606             
607         if (!prjDir.isDirectory()) {
608             wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_ProvideExistingSourcesLocation")); //NOI18N
609
return false; //Existing sources location not specified
610
}
611         
612         //Do we need this check?
613
// if (!prjFolder.isDirectory()) {
614
// wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_ProjectFolderDoesNotExists")); //NOI18N
615
// return false; //Project folder not specified
616
// }
617

618         if (FileSearchUtility.guessJavaRoots(FileUtil.toFileObject(prjDir)) == null) {
619             wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_NoAppClientModule")); //NOI18N
620
return false; // No java project location
621
}
622
623         if (prjName == null || prjName.length() == 0) {
624             wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_ProvideProjectName")); //NOI18N
625
return false; //Project name not specified
626
}
627         
628         String JavaDoc result = checkValidity (this.projectName.getText(), this.projectFolder.getText());
629         if (result != null) {
630             wizardDescriptor.putProperty( "WizardPanel_errorMessage", result); //NOI18N
631
return false;
632         }
633
634         wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); //NOI18N
635

636         return true;
637     }
638
639     static String JavaDoc checkValidity (final String JavaDoc projectName, final String JavaDoc projectLocation) {
640         File JavaDoc projLoc = new File JavaDoc (projectLocation).getAbsoluteFile();
641
642         if (PanelProjectLocationVisual.getCanonicalFile(projLoc) == null) {
643             return NbBundle.getMessage (ImportLocationVisual.class,"MSG_IllegalProjectLocation");
644         }
645
646         while (projLoc != null && !projLoc.exists()) {
647             projLoc = projLoc.getParentFile();
648         }
649         if (projLoc == null || !projLoc.canWrite()) {
650             return NbBundle.getMessage(ImportLocationVisual.class,"MSG_ProjectFolderReadOnly");
651         }
652
653         File JavaDoc destFolder = FileUtil.normalizeFile(new File JavaDoc( projectLocation ));
654         File JavaDoc[] kids = destFolder.listFiles();
655         if ( destFolder.exists() && kids != null && kids.length > 0) {
656             String JavaDoc file = null;
657             for (int i=0; i< kids.length; i++) {
658                 String JavaDoc childName = kids[i].getName();
659                 if ("nbproject".equals(childName)) { //NOI18N
660
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_NetBeansProject");
661                 }
662                 else if ("build".equals(childName)) { //NOI18N
663
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_BuildFolder");
664                 }
665                 else if ("dist".equals(childName)) { //NOI18N
666
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_DistFolder");
667                 }
668                 else if ("build.xml".equals(childName)) { //NOI18N
669
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_BuildXML");
670                 }
671                 else if ("manifest.mf".equals(childName)) { //NOI18N
672
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_Manifest");
673                 }
674                 if (file != null) {
675                     String JavaDoc format = NbBundle.getMessage (ImportLocationVisual.class,"MSG_ProjectFolderInvalid");
676                     return MessageFormat.format(format, new Object JavaDoc[] {file});
677                 }
678             }
679         }
680
681         if (destFolder.isDirectory()) {
682             FileObject destFO = FileUtil.toFileObject(destFolder);
683             assert destFO != null : "No FileObject for " + destFolder;
684             boolean clear = false;
685             try {
686                 clear = ProjectManager.getDefault().findProject(destFO) == null;
687             } catch (IOException JavaDoc e) {
688                 // need not report here; clear remains false -> error
689
}
690             if (!clear) {
691                 return NbBundle.getMessage(ImportLocationVisual.class, "MSG_ProjectFolderHasDeletedProject");
692             }
693         }
694         return null;
695     }
696
697     void read (WizardDescriptor d) {
698         wizardDescriptor = d;
699     }
700     
701     void store( WizardDescriptor d ) {
702         String JavaDoc name = projectName.getText().trim();
703         String JavaDoc moduleLoc = projectLocation.getText().trim();
704
705         if (name.equals("") || moduleLoc.equals("")) {
706             return;
707         }
708         
709         d.putProperty(WizardProperties.PROJECT_DIR, new File JavaDoc(projectFolder.getText().trim()));
710         File JavaDoc moduleLocFile = new File JavaDoc(moduleLoc);
711         d.putProperty(WizardProperties.SOURCE_ROOT, moduleLocFile);
712         d.putProperty(WizardProperties.NAME, name);
713         d.putProperty(WizardProperties.JAVA_ROOT, FileSearchUtility.guessJavaRootsAsFiles(FileUtil.toFileObject(moduleLocFile)));
714         d.putProperty(WizardProperties.SERVER_INSTANCE_ID, getSelectedServerInstanceID());
715         d.putProperty(WizardProperties.J2EE_LEVEL, getSelectedJ2eeSpec());
716         d.putProperty(WizardProperties.EAR_APPLICATION, getSelectedEarApplication());
717         if (warningPanel != null && warningPanel.getDowngradeAllowed()) {
718             d.putProperty(WizardProperties.JAVA_PLATFORM, warningPanel.getSuggestedJavaPlatformName());
719             FoldersListSettings fls = FoldersListSettings.getDefault();
720             d.putProperty(WizardProperties.SOURCE_LEVEL, fls.isAgreedSetSourceLevel14()
721                     ? "1.4" : fls.isAgreedSetSourceLevel15() ? "1.5" : "1.6"); // NOI18N
722
}
723         
724         // TODO: ma154696: add also search for test roots
725
}
726     
727     //extra finish dialog
728
private Dialog JavaDoc dialog;
729     
730     void validate (WizardDescriptor d) throws WizardValidationException {
731         File JavaDoc dirF = new File JavaDoc(projectFolder.getText());
732         JButton JavaDoc ok = new JButton JavaDoc(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_OK")); //NOI18N
733
ok.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_IW_BuildFileDialog_OKButton_LabelMnemonic")); //NOI18N
734
ok.setMnemonic(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_BuildFileDialog_OK_LabelMnemonic").charAt(0)); //NOI18N
735
JButton JavaDoc cancel = new JButton JavaDoc(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_Cancel")); //NOI18N
736
cancel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_IW_BuildFileDialog_CancelButton_LabelMnemonic")); //NOI18N
737
cancel.setMnemonic(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_BuildFileDialog_Cancel_LabelMnemonic").charAt(0)); //NOI18N
738

739         final ImportBuildfile ibf = new ImportBuildfile(dirF.getAbsolutePath(), ok);
740         if ((new File JavaDoc(dirF, GeneratedFilesHelper.BUILD_XML_PATH)).exists()) {
741             ActionListener JavaDoc actionListener = new ActionListener JavaDoc() {
742                 public void actionPerformed(ActionEvent JavaDoc event) {
743                     Object JavaDoc src = event.getSource();
744                     if (src instanceof JButton JavaDoc) {
745                         String JavaDoc name = ((JButton JavaDoc) src).getText();
746                         if (name.equals(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_OK"))) { //NOI18N
747
closeDialog();
748                         } else if (name.equals(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_Cancel"))) { //NOI18N
749
NotifyDescriptor ndesc = new NotifyDescriptor.Confirmation(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_CancelConfirmation"), NotifyDescriptor.YES_NO_OPTION); //NOI18N
750
Object JavaDoc ret = DialogDisplayer.getDefault().notify(ndesc);
751                             if (ret == NotifyDescriptor.YES_OPTION) {
752                                 closeDialog();
753                             }
754                         }
755                     }
756                 }
757             };
758             
759             DialogDescriptor descriptor = new DialogDescriptor(
760                     ibf,
761                     NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_BuildfileTitle"), //NOI18N
762
true,
763                     new Object JavaDoc[] {ok, cancel},
764                     DialogDescriptor.OK_OPTION,
765                             DialogDescriptor.DEFAULT_ALIGN,
766                             null,
767                             actionListener
768                             );
769                     
770                     dialog = DialogDisplayer.getDefault().createDialog(descriptor);
771                     dialog.setVisible(true);
772         } else {
773             return;
774         }
775     }
776
777     private void closeDialog() {
778         dialog.dispose();
779     }
780
781     //use it as a project root iff it is not sources or document root
782
// NOTE: the order of the searches in kind of important in this method for
783
// performance reasons
784
public boolean isSuitableProjectRoot(FileObject dir) {
785         FileObject configFilesRoot = FileSearchUtility.guessConfigFilesPath(dir);
786         if (configFilesRoot != null && !FileUtil.isParentOf(dir, configFilesRoot)) {
787             return false;
788         }
789         FileObject[] srcRoots = FileSearchUtility.guessJavaRoots(dir);
790         if (srcRoots != null && !isParentOf(dir, srcRoots)) {
791             return false;
792         }
793         return true;
794     }
795     
796     private boolean isParentOf(FileObject dir, FileObject[] fos) {
797         boolean result = true;
798         if (fos != null) {
799             for (int i = 0; i < fos.length; i++) {
800                 result = FileUtil.isParentOf(dir, fos[i]);
801                 if (!result) {
802                     return result;
803                 }
804             }
805         }
806         return result;
807     }
808     
809     /**
810      * Init servers model
811      * @param selectedServerInstanceID preselected instance or null if non is preselected
812      */

813     private void initServers(String JavaDoc selectedServerInstanceID) {
814         // init the list of server instances
815
serversModel.removeAllElements();
816         Set JavaDoc<ServerInstanceWrapper> servers = new TreeSet JavaDoc<ServerInstanceWrapper>();
817         ServerInstanceWrapper selectedItem = null;
818         boolean sjasFound = false;
819         for (String JavaDoc serverInstanceID : Deployment.getDefault().getServerInstanceIDs()) {
820             String JavaDoc displayName = Deployment.getDefault().getServerInstanceDisplayName(serverInstanceID);
821             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID);
822             if (displayName != null && j2eePlatform != null && j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.CLIENT)) {
823                 ServerInstanceWrapper serverWrapper = new ServerInstanceWrapper(serverInstanceID, displayName);
824                 // decide whether this server should be preselected
825
if (selectedItem == null || !sjasFound) {
826                     if (selectedServerInstanceID != null) {
827                         if (selectedServerInstanceID.equals(serverInstanceID)) {
828                             selectedItem = serverWrapper;
829                         }
830                     } else {
831                         // preselect the best server ;)
832
String JavaDoc shortName = Deployment.getDefault().getServerID(serverInstanceID);
833                         if ("J2EE".equals(shortName)) { // NOI18N
834
selectedItem = serverWrapper;
835                             sjasFound = true;
836                         }
837                         else
838                         if ("JBoss4".equals(shortName)) { // NOI18N
839
selectedItem = serverWrapper;
840                         }
841                     }
842                 }
843                 servers.add(serverWrapper);
844             }
845         }
846         for (ServerInstanceWrapper item : servers) {
847             serversModel.addElement(item);
848         }
849         if (selectedItem != null) {
850             // set the preselected item
851
serversModel.setSelectedItem(selectedItem);
852         } else if (serversModel.getSize() > 0) {
853             // set the first item
854
serversModel.setSelectedItem(serversModel.getElementAt(0));
855         }
856     }
857     
858     public String JavaDoc getSelectedServerInstanceID() {
859         ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
860         if (serverInstanceWrapper == null) {
861             return null;
862         }
863         return serverInstanceWrapper.getServerInstanceID();
864     }
865     
866     public String JavaDoc getSelectedJ2eeSpec() {
867         Object JavaDoc item = j2eeSpecComboBox.getSelectedItem();
868         return item == null ? null
869                             : item.equals(J2EE_SPEC_14_LABEL) ? J2eeModule.J2EE_14
870                             : item.equals(J2EE_SPEC_15_LABEL) ? J2eeModule.JAVA_EE_5 : J2eeModule.J2EE_13;
871     }
872     
873     private File JavaDoc getAsFile(String JavaDoc filename) {
874         return FileUtil.normalizeFile(new File JavaDoc(filename));
875     }
876
877     public File JavaDoc getProjectLocation() {
878         return getAsFile(projectLocation.getText());
879     }
880
881     public File JavaDoc getProjectFolder() {
882         return getAsFile(projectFolder.getText());
883     }
884
885     public String JavaDoc getProjectName() {
886         return projectName.getText();
887     }
888
889     private Project getSelectedEarApplication() {
890         int idx = addToAppComboBox.getSelectedIndex();
891         return (idx <= 0) ? null : earProjects.get(idx - 1);
892     }
893     
894     private void initEnterpriseApplications() {
895         addToAppComboBox.addItem(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_AddToEApp_None"));
896         addToAppComboBox.setSelectedIndex(0);
897         
898         Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
899         earProjects = new ArrayList JavaDoc<Project>();
900         for (int i = 0; i < allProjects.length; i++) {
901             J2eeModuleContainer container = (J2eeModuleContainer) allProjects[i].getLookup().lookup(J2eeModuleContainer.class);
902             ProjectInformation projectInfo = ProjectUtils.getInformation(allProjects[i]);
903             if (container != null) {
904                 earProjects.add(projectInfo.getProject());
905                 addToAppComboBox.addItem(projectInfo.getDisplayName());
906             }
907         }
908         if (earProjects.size() <= 0) {
909             addToAppComboBox.setEnabled(false);
910         }
911     }
912     
913     private BigDecimal JavaDoc getACXmlVersion(FileObject appClientXML) throws IOException JavaDoc {
914         if (appClientXML != null) {
915             // TODO: possible NPE (will getEjbJar return something)?
916
return DDProvider.getDefault().getDDRoot(appClientXML).getVersion();
917         } else {
918             return null;
919         }
920     }
921
922     private void checkACXmlJ2eeVersion(FileObject appClientXML) {
923         try {
924             BigDecimal JavaDoc version = getACXmlVersion(appClientXML);
925             if (version == null) {
926                 return;
927             }
928             
929             if (new BigDecimal JavaDoc(AppClient.VERSION_1_3).equals(version)) {
930                 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_13_LABEL);
931             } else if(new BigDecimal JavaDoc(AppClient.VERSION_1_4).equals(version)) {
932                 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_14_LABEL);
933             } else if(new BigDecimal JavaDoc(AppClient.VERSION_5_0).equals(version)) {
934                 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_15_LABEL);
935             }
936         } catch (IOException JavaDoc e) {
937             final ErrorManager errorManager = ErrorManager.getDefault();
938             String JavaDoc message = NbBundle.getMessage(ImportLocationVisual.class, "MSG_AppClientXmlCorrupted"); // NOI18N
939
errorManager.notify(errorManager.annotate(e, message));
940         }
941     }
942     
943     private void setJ2eeVersionWarningPanel() {
944         String JavaDoc j2ee = getSelectedJ2eeSpec();
945         if (j2ee == null) {
946             return;
947         }
948         String JavaDoc warningType = J2eeVersionWarningPanel.findWarningType(j2ee);
949         if (warningType == null && warningPanel == null) {
950             return;
951         }
952         if (warningPanel == null) {
953             warningPanel = new J2eeVersionWarningPanel(warningType);
954             warningPlaceHolderPanel.add(warningPanel, java.awt.BorderLayout.CENTER);
955             warningPanel.setWarningType(warningType);
956         } else {
957             warningPanel.setWarningType(warningType);
958         }
959     }
960     
961     /**
962      * Server instance wrapper represents server instances in the servers combobox.
963      * @author sherold
964      */

965     private static class ServerInstanceWrapper implements Comparable JavaDoc {
966
967         private final String JavaDoc serverInstanceID;
968         private final String JavaDoc displayName;
969
970         ServerInstanceWrapper(String JavaDoc serverInstanceID, String JavaDoc displayName) {
971             this.serverInstanceID = serverInstanceID;
972             this.displayName = displayName;
973         }
974
975         public String JavaDoc getServerInstanceID() {
976             return serverInstanceID;
977         }
978
979         public String JavaDoc toString() {
980             return displayName;
981         }
982
983         public int compareTo(Object JavaDoc o) {
984             return toString().compareTo(o.toString());
985         }
986     }
987
988 }
989
Popular Tags