KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > 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.ejbjarproject.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.dd.api.ejb.DDProvider;
45 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
46 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
47 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
48 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModuleContainer;
49 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
50 import org.netbeans.modules.j2ee.deployment.devmodules.api.ServerManager;
51 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProvider;
52 import org.netbeans.modules.j2ee.ejbjarproject.ui.FoldersListSettings;
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  * @author pb97924, Martin Adamek
68  */

69 public class ImportLocationVisual extends JPanel JavaDoc /*implements DocumentListener */{
70
71     private static final String JavaDoc J2EE_SPEC_15_LABEL = NbBundle.getMessage(ImportLocationVisual.class, "J2EESpecLevel_15");
72     private static final String JavaDoc J2EE_SPEC_14_LABEL = NbBundle.getMessage(ImportLocationVisual.class, "J2EESpecLevel_14");
73     private static final String JavaDoc J2EE_SPEC_13_LABEL = NbBundle.getMessage(ImportLocationVisual.class, "J2EESpecLevel_13");
74     
75     private final DefaultComboBoxModel JavaDoc serversModel = new DefaultComboBoxModel JavaDoc();
76     private final ImportLocation panel;
77     private final DocumentListener JavaDoc documentListener;
78     private List JavaDoc earProjects;
79     private BigDecimal JavaDoc ejbJarXmlVersion;
80     private WizardDescriptor wizardDescriptor;
81     private J2eeVersionWarningPanel warningPanel;
82         
83     /** Creates new form TestPanel */
84     public ImportLocationVisual (ImportLocation panel) {
85         this.panel = panel;
86         initComponents ();
87         setJ2eeVersionWarningPanel();
88         initServers(FoldersListSettings.getDefault().getLastUsedServer());
89         // preselect the first item in the j2ee spec combo
90
if (j2eeSpecComboBox.getModel().getSize() > 0) {
91             j2eeSpecComboBox.setSelectedIndex(0);
92         }
93         initEnterpriseApplications();
94         this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_NWP1_NamePanel_A11YDesc")); // NOI18N
95
setName(NbBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_IW_ImportTitle")); //NOI18N
96
putClientProperty ("NewProjectWizard_Title", NbBundle.getMessage(ImportLocationVisual.class, "TXT_ImportEJBModule")); //NOI18N
97
this.projectName.setText("");
98         
99         documentListener = new DocumentListener JavaDoc() {
100             public void insertUpdate(DocumentEvent JavaDoc e) {
101                 update(e);
102             }
103
104             public void removeUpdate(DocumentEvent JavaDoc e) {
105                 update(e);
106             }
107
108             public void changedUpdate(DocumentEvent JavaDoc e) {
109                 update(e);
110             }
111         };
112         this.projectName.getDocument().addDocumentListener(documentListener);
113         this.projectFolder.getDocument().addDocumentListener(documentListener);
114         this.projectLocation.getDocument().addDocumentListener(documentListener);
115         
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         setLayout(new java.awt.GridBagLayout JavaDoc());
150
151         setNextFocusableComponent(projectLocation);
152         getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("ACS_LBL_IW_ImportLocationVisual_A11Name"));
153         getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("ACS_LBL_IW_ImportLocationVisual_A11Desc"));
154         org.openide.awt.Mnemonics.setLocalizedText(jLabelSrcLocationDesc, NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_LocationSrcDesc"));
155         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
156         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
157         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
158         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
159         add(jLabelSrcLocationDesc, gridBagConstraints);
160
161         jLabelSrcLocation.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
162         jLabelSrcLocation.setLabelFor(projectLocation);
163         org.openide.awt.Mnemonics.setLocalizedText(jLabelSrcLocation, NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_LocationSrc_Label"));
164         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
165         gridBagConstraints.gridx = 0;
166         gridBagConstraints.gridy = 1;
167         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
168         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
169         add(jLabelSrcLocation, gridBagConstraints);
170         jLabelSrcLocation.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("ACS_LBL_IW_Location_A11Desc"));
171
172         projectLocation.setNextFocusableComponent(browseProjectLocation);
173         projectLocation.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
174             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
175                 projectLocationFocusLost(evt);
176             }
177         });
178
179         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
180         gridBagConstraints.gridx = 1;
181         gridBagConstraints.gridy = 1;
182         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
183         gridBagConstraints.weightx = 1.0;
184         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
185         add(projectLocation, gridBagConstraints);
186         projectLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_IW_ImportLocation_A11YDesc"));
187
188         org.openide.awt.Mnemonics.setLocalizedText(browseProjectLocation, NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_BrowseLocation_Button_w"));
189         browseProjectLocation.setNextFocusableComponent(projectName);
190         browseProjectLocation.addActionListener(new java.awt.event.ActionListener JavaDoc() {
191             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
192                 browseProjectLocationActionPerformed(evt);
193             }
194         });
195
196         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
197         gridBagConstraints.gridx = 2;
198         gridBagConstraints.gridy = 1;
199         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
200         add(browseProjectLocation, gridBagConstraints);
201         browseProjectLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_IW_ImportLocationBrowse_A11YDesc"));
202
203         org.openide.awt.Mnemonics.setLocalizedText(jLabelPrjLocationDesc, NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_LocationPrjDesc"));
204         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
205         gridBagConstraints.gridx = 0;
206         gridBagConstraints.gridy = 2;
207         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
208         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
209         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
210         add(jLabelPrjLocationDesc, gridBagConstraints);
211
212         jLabelPrjName.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
213         jLabelPrjName.setLabelFor(projectName);
214         org.openide.awt.Mnemonics.setLocalizedText(jLabelPrjName, org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_ProjectName_Label"));
215         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
216         gridBagConstraints.gridx = 0;
217         gridBagConstraints.gridy = 3;
218         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
219         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
220         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
221         add(jLabelPrjName, gridBagConstraints);
222         jLabelPrjName.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("ACS_LBL_IW_ProjectName_A11Desc"));
223
224         projectName.setNextFocusableComponent(projectFolder);
225         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
226         gridBagConstraints.gridx = 1;
227         gridBagConstraints.gridy = 3;
228         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
229         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
230         add(projectName, gridBagConstraints);
231         projectName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NWP1_ProjectName_A11YDesc"));
232
233         jLabelPrjLocation.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
234         jLabelPrjLocation.setLabelFor(projectFolder);
235         org.openide.awt.Mnemonics.setLocalizedText(jLabelPrjLocation, NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_CreatedProjectFolder_Lablel"));
236         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
237         gridBagConstraints.gridx = 0;
238         gridBagConstraints.gridy = 4;
239         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
240         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
241         add(jLabelPrjLocation, gridBagConstraints);
242         jLabelPrjLocation.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("ACS_LBL_IW_ProjectFolder_A11Desc"));
243
244         projectFolder.setNextFocusableComponent(browseProjectFolder);
245         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
246         gridBagConstraints.gridx = 1;
247         gridBagConstraints.gridy = 4;
248         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
249         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
250         add(projectFolder, gridBagConstraints);
251         projectFolder.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NPW1_ProjectLocation_A11YDesc"));
252
253         org.openide.awt.Mnemonics.setLocalizedText(browseProjectFolder, NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_BrowseLocation_Button"));
254         browseProjectFolder.setNextFocusableComponent(addToAppComboBox);
255         browseProjectFolder.addActionListener(new java.awt.event.ActionListener JavaDoc() {
256             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
257                 browseProjectFolderActionPerformed(evt);
258             }
259         });
260
261         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
262         gridBagConstraints.gridx = 2;
263         gridBagConstraints.gridy = 4;
264         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
265         add(browseProjectFolder, gridBagConstraints);
266         browseProjectFolder.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ACS_LBL_NWP1_BrowseLocation_A11YDesc"));
267
268         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
269         gridBagConstraints.gridx = 0;
270         gridBagConstraints.gridy = 5;
271         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
272         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
273         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
274         gridBagConstraints.weightx = 1.0;
275         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
276         add(jSeparator1, gridBagConstraints);
277
278         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
279
280         jCheckBox1.setSelected(true);
281         org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_IW_SetAsMainProject_CheckBox"));
282         jCheckBox1.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
283         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
284         gridBagConstraints.gridx = 0;
285         gridBagConstraints.gridy = 4;
286         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
287         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
288         gridBagConstraints.weightx = 1.0;
289         gridBagConstraints.weighty = 1.0;
290         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
291         jPanel1.add(jCheckBox1, gridBagConstraints);
292         jCheckBox1.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("ACS_LBL_IW_SetAsMainProject_A11YDesc"));
293
294         serverInstanceLabel.setLabelFor(serverInstanceComboBox);
295         org.openide.awt.Mnemonics.setLocalizedText(serverInstanceLabel, org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Server"));
296         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
297         gridBagConstraints.gridx = 0;
298         gridBagConstraints.gridy = 1;
299         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
300         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 11);
301         jPanel1.add(serverInstanceLabel, gridBagConstraints);
302
303         serverInstanceComboBox.setModel(serversModel);
304         serverInstanceComboBox.setNextFocusableComponent(manageServersButton);
305         serverInstanceComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
306             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
307                 serverInstanceComboBoxActionPerformed(evt);
308             }
309         });
310
311         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
312         gridBagConstraints.gridx = 1;
313         gridBagConstraints.gridy = 1;
314         gridBagConstraints.gridwidth = 2;
315         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
316         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
317         gridBagConstraints.weightx = 1.0;
318         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
319         jPanel1.add(serverInstanceComboBox, gridBagConstraints);
320         serverInstanceComboBox.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("ACS_LBL_IW_SelectServerInstance_A11YDesc"));
321
322         jLabel7.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_SelectJ2EEVersion_LabelMnemonic").charAt(0));
323         jLabel7.setLabelFor(j2eeSpecComboBox);
324         jLabel7.setText(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_J2EESpecLevel_Label"));
325         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
326         gridBagConstraints.gridx = 0;
327         gridBagConstraints.gridy = 2;
328         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
329         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
330         jPanel1.add(jLabel7, gridBagConstraints);
331
332         j2eeSpecComboBox.setPrototypeDisplayValue("MMMMMMMMM" /* "Java EE 5" */);
333         j2eeSpecComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
334             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
335                 j2eeSpecComboBoxActionPerformed(evt);
336             }
337         });
338
339         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
340         gridBagConstraints.gridx = 1;
341         gridBagConstraints.gridy = 2;
342         gridBagConstraints.gridwidth = 2;
343         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
344         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
345         jPanel1.add(j2eeSpecComboBox, gridBagConstraints);
346         j2eeSpecComboBox.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("ACS_LBL_IW_SelectJ2EEVersion_A11YDesc"));
347
348         addToAppLabel.setLabelFor(addToAppComboBox);
349         org.openide.awt.Mnemonics.setLocalizedText(addToAppLabel, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_AddToEApp_CheckBox"));
350         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
351         gridBagConstraints.gridx = 0;
352         gridBagConstraints.gridy = 0;
353         gridBagConstraints.gridwidth = 2;
354         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
355         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
356         jPanel1.add(addToAppLabel, gridBagConstraints);
357
358         addToAppComboBox.setNextFocusableComponent(serverInstanceComboBox);
359         addToAppComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
360             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
361                 addToAppComboBoxActionPerformed(evt);
362             }
363         });
364
365         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
366         gridBagConstraints.gridx = 2;
367         gridBagConstraints.gridy = 0;
368         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
369         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
370         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
371         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
372         jPanel1.add(addToAppComboBox, gridBagConstraints);
373
374         warningPlaceHolderPanel.setLayout(new java.awt.BorderLayout JavaDoc());
375
376         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
377         gridBagConstraints.gridx = 0;
378         gridBagConstraints.gridy = 3;
379         gridBagConstraints.gridwidth = 3;
380         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
381         gridBagConstraints.weightx = 1.0;
382         jPanel1.add(warningPlaceHolderPanel, gridBagConstraints);
383
384         org.openide.awt.Mnemonics.setLocalizedText(manageServersButton, org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "LBL_ManageServers"));
385         manageServersButton.setNextFocusableComponent(j2eeSpecComboBox);
386         manageServersButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
387             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
388                 manageServersButtonActionPerformed(evt);
389             }
390         });
391
392         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
393         gridBagConstraints.gridx = 3;
394         gridBagConstraints.gridy = 1;
395         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
396         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 5, 0);
397         jPanel1.add(manageServersButton, gridBagConstraints);
398         manageServersButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ASCN_ManageServers"));
399         manageServersButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportLocationVisual.class, "ASCD_ManageServers"));
400
401         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
402         gridBagConstraints.gridx = 0;
403         gridBagConstraints.gridy = 6;
404         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
405         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
406         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
407         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
408         gridBagConstraints.weightx = 1.0;
409         gridBagConstraints.weighty = 1.0;
410         add(jPanel1, gridBagConstraints);
411
412     }// </editor-fold>//GEN-END:initComponents
413

414     private void projectLocationFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_projectLocationFocusLost
415
File JavaDoc f = new File JavaDoc(projectLocation.getText().trim());
416         if (f.isDirectory()) {
417             updateJ2EEVersion();
418         }
419     }//GEN-LAST:event_projectLocationFocusLost
420

421     private void manageServersButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_manageServersButtonActionPerformed
422
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
423         String JavaDoc lastSelectedServerInstanceID = null;
424         if (serverInstanceWrapper != null) {
425             lastSelectedServerInstanceID = serverInstanceWrapper.getServerInstanceID();
426         }
427         ServerManager.showCustomizer(lastSelectedServerInstanceID);
428         String JavaDoc lastSelectedJ2eeSpecLevel = (String JavaDoc) j2eeSpecComboBox.getSelectedItem();
429         // refresh the list of servers
430
initServers(lastSelectedServerInstanceID);
431         if (lastSelectedJ2eeSpecLevel != null) {
432             j2eeSpecComboBox.setSelectedItem(lastSelectedJ2eeSpecLevel);
433         }
434     }//GEN-LAST:event_manageServersButtonActionPerformed
435

436     private void j2eeSpecComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_j2eeSpecComboBoxActionPerformed
437
panel.stateChanged(null);
438     }//GEN-LAST:event_j2eeSpecComboBoxActionPerformed
439

440     private void addToAppComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addToAppComboBoxActionPerformed
441
// TODO add your handling code here:
442
}//GEN-LAST:event_addToAppComboBoxActionPerformed
443

444     private void serverInstanceComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_serverInstanceComboBoxActionPerformed
445
String JavaDoc prevSelectedItem = (String JavaDoc) j2eeSpecComboBox.getSelectedItem();
446         // update the j2ee spec list according to the selected server
447
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
448         if (serverInstanceWrapper != null) {
449             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceWrapper.getServerInstanceID());
450             Set JavaDoc supportedVersions = j2eePlatform.getSupportedSpecVersions(J2eeModule.EJB);
451             j2eeSpecComboBox.removeAllItems();
452             if (supportedVersions.contains(J2eeModule.JAVA_EE_5)) {
453                 j2eeSpecComboBox.addItem(J2EE_SPEC_15_LABEL);
454             }
455             if (supportedVersions.contains(J2eeModule.J2EE_14)) {
456                 j2eeSpecComboBox.addItem(J2EE_SPEC_14_LABEL);
457             }
458             if (prevSelectedItem != null) {
459                 j2eeSpecComboBox.setSelectedItem(prevSelectedItem);
460             }
461         } else {
462             j2eeSpecComboBox.removeAllItems();
463         }
464         // revalidate the form
465
panel.fireChangeEvent();
466     }//GEN-LAST:event_serverInstanceComboBoxActionPerformed
467

468     private void browseProjectFolderActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseProjectFolderActionPerformed
469
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
470         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
471         chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
472         if (projectFolder.getText().length() > 0 && getProjectFolder().exists()) {
473             chooser.setSelectedFile(getProjectFolder());
474         } else if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) {
475             chooser.setSelectedFile(getProjectLocation());
476         } else {
477             chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
478         }
479         chooser.setDialogTitle(NbBundle.getMessage(ImportLocationVisual.class, "LBL_SelectNewLocation")); // NOI18N
480
if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
481             File JavaDoc projectDir = FileUtil.normalizeFile(chooser.getSelectedFile());
482             projectFolder.setText(projectDir.getAbsolutePath());
483         }
484     }//GEN-LAST:event_browseProjectFolderActionPerformed
485

486     private void browseProjectLocationActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseProjectLocationActionPerformed
487
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
488         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
489         chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
490         if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) {
491             chooser.setSelectedFile(getProjectLocation());
492         } else {
493             // honor the contract in issue 58987
494
File JavaDoc currentDirectory = null;
495             FileObject existingSourcesFO = Templates.getExistingSourcesFolder(wizardDescriptor);
496             if (existingSourcesFO != null) {
497                 File JavaDoc existingSourcesFile = FileUtil.toFile(existingSourcesFO);
498                 if (existingSourcesFile != null && existingSourcesFile.isDirectory()) {
499                     currentDirectory = existingSourcesFile;
500                 }
501             }
502             if (currentDirectory != null) {
503                 chooser.setCurrentDirectory(currentDirectory);
504             } else {
505                 chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
506             }
507         }
508         
509         chooser.setDialogTitle(NbBundle.getMessage(ImportLocationVisual.class, "LBL_SelectExistingLocation")); // NOI18N
510
if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
511             projectLocation.setText(FileUtil.normalizeFile(chooser.getSelectedFile()).getAbsolutePath());
512             updateJ2EEVersion();
513             updateProjectName();
514             updateProjectFolder();
515             panel.stateChanged(null);
516         }
517     }//GEN-LAST:event_browseProjectLocationActionPerformed
518

519     // Variables declaration - do not modify//GEN-BEGIN:variables
520
private javax.swing.JComboBox JavaDoc addToAppComboBox;
521     private javax.swing.JLabel JavaDoc addToAppLabel;
522     private javax.swing.JButton JavaDoc browseProjectFolder;
523     private javax.swing.JButton JavaDoc browseProjectLocation;
524     private javax.swing.JComboBox JavaDoc j2eeSpecComboBox;
525     private javax.swing.JCheckBox JavaDoc jCheckBox1;
526     private javax.swing.JLabel JavaDoc jLabel7;
527     private javax.swing.JLabel JavaDoc jLabelPrjLocation;
528     private javax.swing.JLabel JavaDoc jLabelPrjLocationDesc;
529     private javax.swing.JLabel JavaDoc jLabelPrjName;
530     private javax.swing.JLabel JavaDoc jLabelSrcLocation;
531     private javax.swing.JLabel JavaDoc jLabelSrcLocationDesc;
532     private javax.swing.JPanel JavaDoc jPanel1;
533     private javax.swing.JSeparator JavaDoc jSeparator1;
534     private javax.swing.JButton JavaDoc manageServersButton;
535     public javax.swing.JTextField JavaDoc projectFolder;
536     public javax.swing.JTextField JavaDoc projectLocation;
537     public javax.swing.JTextField JavaDoc projectName;
538     private javax.swing.JComboBox JavaDoc serverInstanceComboBox;
539     private javax.swing.JLabel JavaDoc serverInstanceLabel;
540     private javax.swing.JPanel JavaDoc warningPlaceHolderPanel;
541     // End of variables declaration//GEN-END:variables
542

543     private void setJ2eeVersionWarning() {
544         String JavaDoc errorMessage;
545         String JavaDoc selectedItem = (String JavaDoc)j2eeSpecComboBox.getSelectedItem();
546         
547         if (J2EE_SPEC_14_LABEL.equals(selectedItem) && new BigDecimal JavaDoc(EjbJar.VERSION_2_0).equals(ejbJarXmlVersion)) {
548             errorMessage = NbBundle.getMessage(ImportLocationVisual.class, "MSG_EjbJarXMLNotSupported");
549         } else {
550             errorMessage = null;
551         }
552         if (wizardDescriptor != null) {
553             wizardDescriptor.putProperty("WizardPanel_errorMessage", errorMessage); //NOI18N
554
}
555         
556         setJ2eeVersionWarningPanel();
557     }
558     
559     private boolean ignoreEvent = false;
560     
561     private String JavaDoc lastComputedPrjName = null;
562     private String JavaDoc computeProjectName() {
563         String JavaDoc cPrjName = null;
564         FileObject fo = FileUtil.toFileObject(getProjectLocation());
565         if (fo != null) {
566             cPrjName = fo.getName();
567         }
568         return cPrjName;
569     }
570     
571     private String JavaDoc lastComputedPrjFolder = null;
572     private String JavaDoc computeProjectFolder() {
573         String JavaDoc cPrjFolder = null;
574         if (isValidProjectLocation()) {
575             cPrjFolder = getProjectLocation().getAbsolutePath();
576         }
577         return cPrjFolder;
578     }
579     
580     private void update(DocumentEvent JavaDoc e) {
581         if (ignoreEvent) {
582             // side-effect of changes done in this handler
583
return;
584         }
585
586         // start ignoring events
587
ignoreEvent = true;
588
589         if (projectLocation.getDocument() == e.getDocument()) {
590             updateProjectName();
591             updateProjectFolder();
592         }
593         
594         // stop ignoring events
595
ignoreEvent = false;
596         
597         panel.stateChanged(null);
598     }
599     
600     private void updateProjectName() {
601         String JavaDoc prjName = computeProjectName();
602         if ((lastComputedPrjName != null) && (!lastComputedPrjName.equals(projectName.getText().trim()))) {
603             return;
604         }
605         lastComputedPrjName = prjName;
606         if (prjName != null) {
607             projectName.setText(prjName);
608         }
609     }
610     
611     private void updateProjectFolder() {
612         String JavaDoc prjFolder = computeProjectFolder();
613         if ((lastComputedPrjFolder != null) && (!lastComputedPrjFolder.equals(projectFolder.getText().trim()))) {
614             return;
615         }
616         lastComputedPrjFolder = prjFolder;
617         if (prjFolder != null) {
618             projectFolder.setText(prjFolder);
619         } else {
620             projectFolder.setText(""); // NOI18N
621
}
622     }
623     
624     private void updateJ2EEVersion() {
625         File JavaDoc f = new File JavaDoc(projectLocation.getText().trim());
626         FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(f));
627         if (fo != null) {
628             FileObject configFilesPath = FileSearchUtility.guessConfigFilesPath(fo);
629             if (configFilesPath != null) {
630                 FileObject ejbJarXML = configFilesPath.getFileObject(EjbJarProvider.FILE_DD);
631                 checkEjbJarXmlJ2eeVersion(ejbJarXML);
632             } else {
633                 // suppose highest
634
j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_15_LABEL);
635             }
636         }
637     }
638     
639     private boolean isValidProjectLocation() {
640         return (getProjectLocation().exists() && getProjectLocation().isDirectory() &&
641                 projectLocation.getText().length() > 0 && (!projectLocation.getText().endsWith(":"))); // NOI18N
642
}
643     
644     public boolean valid(WizardDescriptor wizardDescriptor) {
645         File JavaDoc prjDir = new File JavaDoc(projectLocation.getText().trim());
646 // File prjFolder = new File(projectFolder.getText().trim());
647
String JavaDoc prjName = projectName.getText().trim();
648         
649         if (getSelectedServerInstanceID() == null) {
650             wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_NoServer")); //NOI18N
651
return false;
652         }
653             
654         if (!prjDir.isDirectory()) {
655             wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_ProvideExistingSourcesLocation")); //NOI18N
656
return false; //Existing sources location not specified
657
}
658         
659         //Do we need this check?
660
// if (!prjFolder.isDirectory()) {
661
// wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_ProjectFolderDoesNotExists")); //NOI18N
662
// return false; //Project folder not specified
663
// }
664

665         // we will leave it up to user if he provides project folder with sources or not
666
// if (FileSearchUtility.guessJavaRoots(FileUtil.toFileObject(FileUtil.normalizeFile(prjDir))) == null) {
667
// wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_NoEjbJarModule")); //NOI18N
668
// return false; // No java project location
669
// }
670

671         if (prjName == null || prjName.length() == 0) {
672             wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ImportLocationVisual.class,"MSG_ProvideProjectName")); //NOI18N
673
return false; //Project name not specified
674
}
675         
676         String JavaDoc result = checkValidity (this.projectName.getText(), this.projectFolder.getText());
677         if (result != null) {
678             wizardDescriptor.putProperty( "WizardPanel_errorMessage", result); //NOI18N
679
return false;
680         }
681
682         wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); //NOI18N
683

684         setJ2eeVersionWarning();
685         
686         return true;
687     }
688
689     static String JavaDoc checkValidity (final String JavaDoc projectName, final String JavaDoc projectLocation) {
690         File JavaDoc projLoc = new File JavaDoc (projectLocation).getAbsoluteFile();
691         
692         if (PanelProjectLocationVisual.getCanonicalFile(projLoc) == null) {
693             return NbBundle.getMessage(ImportLocationVisual.class, "MSG_IllegalProjectLocation");
694         }
695         
696         while (projLoc != null && !projLoc.exists()) {
697             projLoc = projLoc.getParentFile();
698         }
699         if (projLoc == null || !projLoc.canWrite()) {
700             return NbBundle.getMessage(ImportLocationVisual.class,"MSG_ProjectFolderReadOnly");
701         }
702
703         File JavaDoc destFolder = FileUtil.normalizeFile(new File JavaDoc( projectLocation ));
704         File JavaDoc[] kids = destFolder.listFiles();
705         if ( destFolder.exists() && kids != null && kids.length > 0) {
706             String JavaDoc file = null;
707             for (int i=0; i< kids.length; i++) {
708                 String JavaDoc childName = kids[i].getName();
709                 if ("nbproject".equals(childName)) { //NOI18N
710
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_NetBeansProject");
711                 }
712                 else if ("build".equals(childName)) { //NOI18N
713
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_BuildFolder");
714                 }
715                 else if ("dist".equals(childName)) { //NOI18N
716
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_DistFolder");
717                 }
718                 else if ("build.xml".equals(childName)) { //NOI18N
719
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_BuildXML");
720                 }
721                 else if ("manifest.mf".equals(childName)) { //NOI18N
722
file = NbBundle.getMessage (ImportLocationVisual.class,"TXT_Manifest");
723                 }
724                 if (file != null) {
725                     String JavaDoc format = NbBundle.getMessage (ImportLocationVisual.class,"MSG_ProjectFolderInvalid");
726                     return MessageFormat.format(format, new Object JavaDoc[] {file});
727                 }
728             }
729         }
730
731         if (destFolder.isDirectory()) {
732             FileObject destFO = FileUtil.toFileObject(destFolder);
733             assert destFO != null : "No FileObject for " + destFolder;
734             boolean clear;
735             try {
736                 clear = ProjectManager.getDefault().findProject(destFO) == null;
737             } catch (IOException JavaDoc e) {
738                 clear = false;
739             }
740             if (!clear) {
741                 return NbBundle.getMessage(ImportLocationVisual.class, "MSG_ProjectFolderHasDeletedProject");
742             }
743         }
744         return null;
745     }
746
747     void read (WizardDescriptor d) {
748         wizardDescriptor = d;
749     }
750     
751     void store( WizardDescriptor d ) {
752         String JavaDoc name = projectName.getText().trim();
753         String JavaDoc moduleLoc = projectLocation.getText().trim();
754
755         if (name.equals("") || moduleLoc.equals("")) {
756             return;
757         }
758         
759         d.putProperty(WizardProperties.PROJECT_DIR, new File JavaDoc(projectFolder.getText().trim()));
760         File JavaDoc moduleLocFile = new File JavaDoc(moduleLoc);
761         d.putProperty(WizardProperties.SOURCE_ROOT, moduleLocFile);
762         d.putProperty(WizardProperties.NAME, name);
763         d.putProperty(WizardProperties.JAVA_ROOT, FileSearchUtility.guessJavaRootsAsFiles(FileUtil.toFileObject(FileUtil.normalizeFile(moduleLocFile))));
764         d.putProperty(WizardProperties.SERVER_INSTANCE_ID, getSelectedServerInstanceID());
765         d.putProperty(WizardProperties.J2EE_LEVEL, getSelectedJ2eeSpec());
766         d.putProperty(WizardProperties.EAR_APPLICATION, getSelectedEarApplication());
767         if (warningPanel != null && warningPanel.getDowngradeAllowed()) {
768             d.putProperty(WizardProperties.JAVA_PLATFORM, warningPanel.getSuggestedJavaPlatformName());
769             
770             String JavaDoc j2ee = getSelectedJ2eeSpec();
771             if (j2ee != null) {
772                 String JavaDoc warningType = J2eeVersionWarningPanel.findWarningType(j2ee);
773                 FoldersListSettings fls = FoldersListSettings.getDefault();
774                 String JavaDoc srcLevel = "1.6"; //NOI18N
775
if (warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_14) && fls.isAgreedSetSourceLevel14())
776                     srcLevel = "1.4"; //NOI18N
777
else if (warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_15) && fls.isAgreedSetSourceLevel15())
778                     srcLevel = "1.5"; //NOI18N
779

780                 d.putProperty(WizardProperties.SOURCE_LEVEL, srcLevel);
781             }
782         } else
783             d.putProperty(WizardProperties.SOURCE_LEVEL, null);
784         
785         // TODO: ma154696: add also search for test roots
786
}
787     
788     //extra finish dialog
789
private Dialog JavaDoc dialog;
790     
791     void validate (WizardDescriptor d) throws WizardValidationException {
792         File JavaDoc dirF = new File JavaDoc(projectFolder.getText());
793         JButton JavaDoc ok = new JButton JavaDoc(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_OK")); //NOI18N
794
ok.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_IW_BuildFileDialog_OKButton_LabelMnemonic")); //NOI18N
795
ok.setMnemonic(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_BuildFileDialog_OK_LabelMnemonic").charAt(0)); //NOI18N
796
JButton JavaDoc cancel = new JButton JavaDoc(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_Cancel")); //NOI18N
797
cancel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportLocationVisual.class, "ACS_IW_BuildFileDialog_CancelButton_LabelMnemonic")); //NOI18N
798
cancel.setMnemonic(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_BuildFileDialog_Cancel_LabelMnemonic").charAt(0)); //NOI18N
799

800         final ImportBuildfile ibf = new ImportBuildfile(dirF.getAbsolutePath(), ok);
801         if ((new File JavaDoc(dirF, GeneratedFilesHelper.BUILD_XML_PATH)).exists()) {
802             ActionListener JavaDoc actionListener = new ActionListener JavaDoc() {
803                 public void actionPerformed(ActionEvent JavaDoc event) {
804                     Object JavaDoc src = event.getSource();
805                     if (src instanceof JButton JavaDoc) {
806                         String JavaDoc name = ((JButton JavaDoc) src).getText();
807                         if (name.equals(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_OK"))) { //NOI18N
808
closeDialog();
809                         } else if (name.equals(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_Cancel"))) { //NOI18N
810
NotifyDescriptor ndesc = new NotifyDescriptor.Confirmation(NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_Buildfile_CancelConfirmation"), NotifyDescriptor.YES_NO_OPTION); //NOI18N
811
Object JavaDoc ret = DialogDisplayer.getDefault().notify(ndesc);
812                             if (ret == NotifyDescriptor.YES_OPTION) {
813                                 closeDialog();
814                             }
815                         }
816                     }
817                 }
818             };
819             
820             DialogDescriptor descriptor = new DialogDescriptor(
821                     ibf,
822                     NbBundle.getMessage(ImportLocationVisual.class, "LBL_IW_BuildfileTitle"), //NOI18N
823
true,
824                     new Object JavaDoc[] {ok, cancel},
825                     DialogDescriptor.OK_OPTION,
826                             DialogDescriptor.DEFAULT_ALIGN,
827                             null,
828                             actionListener
829                             );
830                     
831                     dialog = DialogDisplayer.getDefault().createDialog(descriptor);
832                     dialog.setVisible(true);
833         } else {
834             return;
835         }
836     }
837
838     private void closeDialog() {
839         dialog.dispose();
840     }
841     
842     private boolean isParentOf(FileObject dir, FileObject[] fos) {
843         boolean result = true;
844         if (fos != null) {
845             for (int i = 0; i < fos.length; i++) {
846                 result = FileUtil.isParentOf(dir, fos[i]);
847                 if (!result) {
848                     return result;
849                 }
850             }
851         }
852         return result;
853     }
854     
855     /**
856      * Init servers model
857      * @param selectedServerInstanceID preselected instance or null if non is preselected
858      */

859     private void initServers(String JavaDoc selectedServerInstanceID) {
860         // init the list of server instances
861
serversModel.removeAllElements();
862         Set JavaDoc<ServerInstanceWrapper> servers = new TreeSet JavaDoc<ServerInstanceWrapper>();
863         ServerInstanceWrapper selectedItem = null;
864         boolean sjasFound = false;
865         for (String JavaDoc serverInstanceID : Deployment.getDefault().getServerInstanceIDs()) {
866             String JavaDoc displayName = Deployment.getDefault().getServerInstanceDisplayName(serverInstanceID);
867             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID);
868             if (displayName != null && j2eePlatform != null && j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.EJB)) {
869                 ServerInstanceWrapper serverWrapper = new ServerInstanceWrapper(serverInstanceID, displayName);
870                 // decide whether this server should be preselected
871
if (selectedItem == null || !sjasFound) {
872                     if (selectedServerInstanceID != null) {
873                         if (selectedServerInstanceID.equals(serverInstanceID)) {
874                             selectedItem = serverWrapper;
875                         }
876                     } else {
877                         // preselect the best server ;)
878
String JavaDoc shortName = Deployment.getDefault().getServerID(serverInstanceID);
879                         if ("J2EE".equals(shortName)) { // NOI18N
880
selectedItem = serverWrapper;
881                             sjasFound = true;
882                         }
883                         else
884                         if ("JBoss4".equals(shortName)) { // NOI18N
885
selectedItem = serverWrapper;
886                         }
887                     }
888                 }
889                 servers.add(serverWrapper);
890             }
891         }
892         for (ServerInstanceWrapper item : servers) {
893             serversModel.addElement(item);
894         }
895         if (selectedItem != null) {
896             // set the preselected item
897
serversModel.setSelectedItem(selectedItem);
898         } else if (serversModel.getSize() > 0) {
899             // set the first item
900
serversModel.setSelectedItem(serversModel.getElementAt(0));
901         }
902     }
903     
904     public String JavaDoc getSelectedServerInstanceID() {
905         ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
906         if (serverInstanceWrapper == null) {
907             return null;
908         }
909         return serverInstanceWrapper.getServerInstanceID();
910     }
911     
912     public String JavaDoc getSelectedJ2eeSpec() {
913         Object JavaDoc item = j2eeSpecComboBox.getSelectedItem();
914         return item == null ? null
915                 : item.equals(J2EE_SPEC_14_LABEL) ? J2eeModule.J2EE_14
916                 : item.equals(J2EE_SPEC_15_LABEL) ? J2eeModule.JAVA_EE_5 : J2eeModule.J2EE_13;
917     }
918     
919     private File JavaDoc getAsFile(String JavaDoc filename) {
920         return FileUtil.normalizeFile(new File JavaDoc(filename));
921     }
922
923     public File JavaDoc getProjectLocation() {
924         return getAsFile(projectLocation.getText());
925     }
926
927     public File JavaDoc getProjectFolder() {
928         return getAsFile(projectFolder.getText());
929     }
930
931     public String JavaDoc getProjectName() {
932         return projectName.getText();
933     }
934
935     private Project getSelectedEarApplication() {
936         int idx = addToAppComboBox.getSelectedIndex();
937         return (idx <= 0) ? null : (Project) earProjects.get(idx - 1);
938     }
939     
940     private void initEnterpriseApplications() {
941         addToAppComboBox.addItem(NbBundle.getMessage(ImportLocationVisual.class, "LBL_NWP1_AddToEApp_None"));
942         addToAppComboBox.setSelectedIndex(0);
943         
944         Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
945         earProjects = new ArrayList JavaDoc();
946         for (int i = 0; i < allProjects.length; i++) {
947             J2eeModuleContainer container = (J2eeModuleContainer) allProjects[i].getLookup().lookup(J2eeModuleContainer.class);
948             ProjectInformation projectInfo = ProjectUtils.getInformation(allProjects[i]);
949             if (container != null) {
950                 earProjects.add(projectInfo.getProject());
951                 addToAppComboBox.addItem(projectInfo.getDisplayName());
952             }
953         }
954         if (earProjects.size() <= 0) {
955             addToAppComboBox.setEnabled(false);
956         }
957     }
958     
959     private BigDecimal JavaDoc getEjbJarXmlVersion(FileObject ejbJarXml) throws IOException JavaDoc {
960         if (ejbJarXml != null) {
961             EjbJar ejbJar = null;
962             org.netbeans.modules.j2ee.api.ejbjar.EjbJar apiEjbJar = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(ejbJarXml);
963             if (apiEjbJar != null) {
964               ejbJar = DDProvider.getDefault().getMergedDDRoot(apiEjbJar.getMetadataUnit());
965             } else {
966               ejbJar = DDProvider.getDefault().getDDRoot(ejbJarXml);
967             }
968             if (ejbJar != null) {
969                 return ejbJar.getVersion();
970             }
971         }
972         return null;
973     }
974
975     private void checkEjbJarXmlJ2eeVersion(FileObject ejbJarXml) {
976         try {
977             BigDecimal JavaDoc version = getEjbJarXmlVersion(ejbJarXml);
978             ejbJarXmlVersion = version;
979             if (version == null) {
980                 return;
981             }
982             
983             if(new BigDecimal JavaDoc(EjbJar.VERSION_2_0).equals(version)) {
984                 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_13_LABEL);
985             } else if(new BigDecimal JavaDoc(EjbJar.VERSION_2_1).equals(version)) {
986                 j2eeSpecComboBox.setSelectedItem(J2EE_SPEC_14_LABEL);
987             }
988         } catch (IOException JavaDoc e) {
989             final ErrorManager errorManager = ErrorManager.getDefault();
990             String JavaDoc message = NbBundle.getMessage(ImportLocationVisual.class, "MSG_EjbJarXmlCorrupted"); // NOI18N
991
errorManager.notify(errorManager.annotate(e, message));
992         }
993     }
994     
995     private void setJ2eeVersionWarningPanel() {
996         String JavaDoc j2ee = getSelectedJ2eeSpec();
997         if (j2ee == null) {
998             return;
999         }
1000        String JavaDoc warningType = J2eeVersionWarningPanel.findWarningType(j2ee);
1001        if (warningType == null && warningPanel == null) {
1002            return;
1003        }
1004        if (warningPanel == null) {
1005            warningPanel = new J2eeVersionWarningPanel(warningType);
1006            warningPlaceHolderPanel.add(warningPanel, java.awt.BorderLayout.CENTER);
1007            warningPanel.setWarningType(warningType);
1008        } else {
1009            warningPanel.setWarningType(warningType);
1010        }
1011    }
1012    
1013    /**
1014     * Server instance wrapper represents server instances in the servers combobox.
1015     * @author sherold
1016     */

1017    private static class ServerInstanceWrapper implements Comparable JavaDoc {
1018
1019        private final String JavaDoc serverInstanceID;
1020        private final String JavaDoc displayName;
1021
1022        ServerInstanceWrapper(String JavaDoc serverInstanceID, String JavaDoc displayName) {
1023            this.serverInstanceID = serverInstanceID;
1024            this.displayName = displayName;
1025        }
1026
1027        public String JavaDoc getServerInstanceID() {
1028            return serverInstanceID;
1029        }
1030
1031        public String JavaDoc toString() {
1032            return displayName;
1033        }
1034
1035        public int compareTo(Object JavaDoc o) {
1036            return toString().compareTo(o.toString());
1037        }
1038    }
1039}
1040
Popular Tags