KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.earproject.ui.wizards;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import java.util.Set JavaDoc;
26 import java.util.StringTokenizer JavaDoc;
27 import java.util.TreeSet JavaDoc;
28 import javax.swing.DefaultComboBoxModel JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30 import javax.swing.event.DocumentEvent JavaDoc;
31 import javax.swing.event.DocumentListener JavaDoc;
32 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
33 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
34 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
35 import org.netbeans.modules.j2ee.deployment.devmodules.api.ServerManager;
36 import org.netbeans.modules.j2ee.earproject.ui.FoldersListSettings;
37 import org.netbeans.modules.j2ee.earproject.ui.customizer.EarProjectProperties;
38 import org.openide.WizardDescriptor;
39 import org.openide.util.NbBundle;
40 import org.openide.util.Utilities;
41
42 public class PanelOptionsVisual extends JPanel JavaDoc implements PropertyChangeListener JavaDoc {
43     
44     private final PanelConfigureProject panel;
45     private final DefaultComboBoxModel JavaDoc serversModel = new DefaultComboBoxModel JavaDoc();
46     private J2eeVersionWarningPanel warningPanel;
47     private boolean valid;
48     
49     /** Creates new form PanelOptionsVisual */
50     public PanelOptionsVisual(PanelConfigureProject panel, boolean importStyle) {
51         panel.getProjectTypeFlag();
52         initComponents();
53         this.panel = panel;
54         setJ2eeVersionWarningPanel();
55         initServers(FoldersListSettings.getDefault().getLastUsedServer());
56         // preselect the first item in the j2ee spec combo
57
if (j2eeSpecComboBox.getModel().getSize() > 0) {
58             j2eeSpecComboBox.setSelectedIndex(0);
59         }
60         // if this panel is used during import there are lots of things we don't
61
// need to ask about -- hide them from the user.
62
if (importStyle) {
63             createEjbCheckBox.setSelected(!importStyle);
64             createWARCheckBox.setSelected(!importStyle);
65             createCarCheckBox.setSelected(!importStyle);
66             createEjbCheckBox.setVisible(!importStyle);
67             createWARCheckBox.setVisible(!importStyle);
68             createCarCheckBox.setVisible(!importStyle);
69             jTextFieldEjbModuleName.setVisible(!importStyle);
70             jTextFieldWebAppName.setVisible(!importStyle);
71             jTextFieldCarName.setVisible(!importStyle);
72             mainClassLabel.setVisible(!importStyle);
73             mainClassTextField.setVisible(!importStyle);
74         } else {
75             DocumentListener JavaDoc subProjectNameListener = new DocumentListener JavaDoc() {
76                 public void insertUpdate(DocumentEvent JavaDoc e) {
77                     projectNameChanged();
78                 }
79                 public void removeUpdate(DocumentEvent JavaDoc e) {
80                     projectNameChanged();
81                 }
82                 public void changedUpdate(DocumentEvent JavaDoc e) {
83                     projectNameChanged();
84                 }
85             };
86             jTextFieldEjbModuleName.getDocument().addDocumentListener(subProjectNameListener);
87             jTextFieldWebAppName.getDocument().addDocumentListener(subProjectNameListener);
88             jTextFieldCarName.getDocument().addDocumentListener(subProjectNameListener);
89             this.mainClassTextField.getDocument().addDocumentListener( new DocumentListener JavaDoc() {
90                 public void insertUpdate(DocumentEvent JavaDoc e) {
91                     mainClassChanged();
92                 }
93             
94                 public void removeUpdate(DocumentEvent JavaDoc e) {
95                     mainClassChanged();
96                 }
97             
98                 public void changedUpdate(DocumentEvent JavaDoc e) {
99                     mainClassChanged();
100                 }
101             
102             });
103         }
104         //j2eeSpecComboBox.setVisible(!importStyle);
105
//j2eeSpecLabel.setVisible(!importStyle);
106
}
107     
108     /** This method is called from within the constructor to
109      * initialize the form.
110      * WARNING: Do NOT modify this code. The content of this method is
111      * always regenerated by the Form Editor.
112      */

113     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
114
private void initComponents() {
115         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
116
117         setAsMainCheckBox = new javax.swing.JCheckBox JavaDoc();
118         createEjbCheckBox = new javax.swing.JCheckBox JavaDoc();
119         jTextFieldEjbModuleName = new javax.swing.JTextField JavaDoc();
120         createWARCheckBox = new javax.swing.JCheckBox JavaDoc();
121         jTextFieldWebAppName = new javax.swing.JTextField JavaDoc();
122         warningPlaceHolderPanel = new javax.swing.JPanel JavaDoc();
123         createCarCheckBox = new javax.swing.JCheckBox JavaDoc();
124         jTextFieldCarName = new javax.swing.JTextField JavaDoc();
125         mainClassLabel = new javax.swing.JLabel JavaDoc();
126         mainClassTextField = new javax.swing.JTextField JavaDoc();
127         serverAndVersionPanel = new javax.swing.JPanel JavaDoc();
128         serverInstanceLabel = new javax.swing.JLabel JavaDoc();
129         serverInstanceComboBox = new javax.swing.JComboBox JavaDoc();
130         manageServersButton = new javax.swing.JButton JavaDoc();
131         j2eeSpecLabel = new javax.swing.JLabel JavaDoc();
132         j2eeSpecComboBox = new javax.swing.JComboBox JavaDoc();
133
134         setLayout(new java.awt.GridBagLayout JavaDoc());
135
136         getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ASCN_ManageServers")); // NOI18N
137
getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ASCD_ManageServers")); // NOI18N
138
setAsMainCheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_SetAsMain_CheckBoxMnemonic").charAt(0));
139         setAsMainCheckBox.setSelected(true);
140         setAsMainCheckBox.setText(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_SetAsMain_CheckBox")); // NOI18N
141
setAsMainCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
142         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
143         gridBagConstraints.gridx = 0;
144         gridBagConstraints.gridy = 6;
145         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
146         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
147         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
148         gridBagConstraints.weighty = 1.0;
149         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 0, 0);
150         add(setAsMainCheckBox, gridBagConstraints);
151         setAsMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_NWP1_SetAsMain_A11YDesc")); // NOI18N
152

153         createEjbCheckBox.setSelected(true);
154         org.openide.awt.Mnemonics.setLocalizedText(createEjbCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_NEAP_CreateEjbModule")); // NOI18N
155
createEjbCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
156         createEjbCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
157             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
158                 createEjbCheckBox_action(evt);
159             }
160         });
161
162         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.gridx = 0;
164         gridBagConstraints.gridy = 1;
165         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
166         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 5, 11);
167         add(createEjbCheckBox, gridBagConstraints);
168         createEjbCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_CreateEJBModule")); // NOI18N
169

170         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
171         gridBagConstraints.gridx = 1;
172         gridBagConstraints.gridy = 1;
173         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
174         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
175         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
176         gridBagConstraints.weightx = 1.0;
177         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 5);
178         add(jTextFieldEjbModuleName, gridBagConstraints);
179         jTextFieldEjbModuleName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_EjbModuleName")); // NOI18N
180
jTextFieldEjbModuleName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_EjbModuleName")); // NOI18N
181

182         createWARCheckBox.setSelected(true);
183         org.openide.awt.Mnemonics.setLocalizedText(createWARCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_NEAP_CreatWebAppModule")); // NOI18N
184
createWARCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
185         createWARCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
186             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
187                 createWebAppCheckBox_action(evt);
188             }
189         });
190
191         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
192         gridBagConstraints.gridx = 0;
193         gridBagConstraints.gridy = 2;
194         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
195         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 5, 11);
196         add(createWARCheckBox, gridBagConstraints);
197         createWARCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_CreateWebModule")); // NOI18N
198

199         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
200         gridBagConstraints.gridx = 1;
201         gridBagConstraints.gridy = 2;
202         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
203         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
204         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
205         gridBagConstraints.weightx = 1.0;
206         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 5);
207         add(jTextFieldWebAppName, gridBagConstraints);
208         jTextFieldWebAppName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSN_WebAppName")); // NOI18N
209
jTextFieldWebAppName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_WebAppName")); // NOI18N
210

211         warningPlaceHolderPanel.setLayout(new java.awt.BorderLayout JavaDoc());
212
213         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
214         gridBagConstraints.gridx = 0;
215         gridBagConstraints.gridy = 5;
216         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
217         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
218         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 0, 5);
219         add(warningPlaceHolderPanel, gridBagConstraints);
220
221         org.openide.awt.Mnemonics.setLocalizedText(createCarCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_NEAP_CreateCarModule")); // NOI18N
222
createCarCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
223         createCarCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
224             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
225                 createCarCheckBox_action(evt);
226             }
227         });
228
229         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
230         gridBagConstraints.gridx = 0;
231         gridBagConstraints.gridy = 3;
232         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
233         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 5, 11);
234         add(createCarCheckBox, gridBagConstraints);
235         createCarCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_CreateAppClientModule")); // NOI18N
236

237         jTextFieldCarName.setEnabled(false);
238         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
239         gridBagConstraints.gridx = 1;
240         gridBagConstraints.gridy = 3;
241         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
242         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
243         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
244         gridBagConstraints.weightx = 1.0;
245         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 5);
246         add(jTextFieldCarName, gridBagConstraints);
247         jTextFieldCarName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSN_AppClientName")); // NOI18N
248
jTextFieldCarName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_AppClientName")); // NOI18N
249

250         mainClassLabel.setLabelFor(mainClassTextField);
251         org.openide.awt.Mnemonics.setLocalizedText(mainClassLabel, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_NWP1_MainClass_Label")); // NOI18N
252
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
253         gridBagConstraints.gridx = 0;
254         gridBagConstraints.gridy = 4;
255         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
256         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
257         add(mainClassLabel, gridBagConstraints);
258
259         mainClassTextField.setEnabled(false);
260         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
261         gridBagConstraints.gridx = 1;
262         gridBagConstraints.gridy = 4;
263         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
264         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
265         gridBagConstraints.weightx = 1.0;
266         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 5);
267         add(mainClassTextField, gridBagConstraints);
268         mainClassTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCN_mainClassTextFiled")); // NOI18N
269
mainClassTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCD_mainClassTextFiled")); // NOI18N
270

271         serverAndVersionPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
272
273         serverInstanceLabel.setLabelFor(serverInstanceComboBox);
274         org.openide.awt.Mnemonics.setLocalizedText(serverInstanceLabel, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_Server_Label")); // NOI18N
275
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
276         gridBagConstraints.gridx = 0;
277         gridBagConstraints.gridy = 0;
278         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
279         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 5, 11);
280         serverAndVersionPanel.add(serverInstanceLabel, gridBagConstraints);
281
282         serverInstanceComboBox.setModel(serversModel);
283         serverInstanceComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
284             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
285                 serverInstanceComboBoxActionPerformed(evt);
286             }
287         });
288
289         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
290         gridBagConstraints.gridx = 1;
291         gridBagConstraints.gridy = 0;
292         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
293         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
294         gridBagConstraints.weightx = 1.0;
295         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 5, 6);
296         serverAndVersionPanel.add(serverInstanceComboBox, gridBagConstraints);
297         serverInstanceComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_NWP1_Server_ComboBox_A11YDesc")); // NOI18N
298

299         org.openide.awt.Mnemonics.setLocalizedText(manageServersButton, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_ManageServers")); // NOI18N
300
manageServersButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
301             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
302                 manageServersButtonActionPerformed(evt);
303             }
304         });
305
306         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
307         gridBagConstraints.gridx = 2;
308         gridBagConstraints.gridy = 0;
309         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
310         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
311         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 5, 5);
312         serverAndVersionPanel.add(manageServersButton, gridBagConstraints);
313         manageServersButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_ManageButton")); // NOI18N
314

315         j2eeSpecLabel.setLabelFor(j2eeSpecComboBox);
316         org.openide.awt.Mnemonics.setLocalizedText(j2eeSpecLabel, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_J2EESpecLevel_Label")); // NOI18N
317
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
318         gridBagConstraints.gridx = 0;
319         gridBagConstraints.gridy = 1;
320         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
321         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 11, 11);
322         serverAndVersionPanel.add(j2eeSpecLabel, gridBagConstraints);
323
324         j2eeSpecComboBox.setPrototypeDisplayValue("MMMMMMMMM" /* "Java EE 5" */);
325         j2eeSpecComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
326             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
327                 j2eeSpecComboBoxActionPerformed(evt);
328             }
329         });
330
331         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
332         gridBagConstraints.gridx = 1;
333         gridBagConstraints.gridy = 1;
334         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
335         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
336         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 5);
337         serverAndVersionPanel.add(j2eeSpecComboBox, gridBagConstraints);
338         j2eeSpecComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_NPW1_J2EESpecLevel_A11YDesc")); // NOI18N
339

340         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
341         gridBagConstraints.gridx = 0;
342         gridBagConstraints.gridy = 0;
343         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
344         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
345         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
346         gridBagConstraints.weightx = 1.0;
347         add(serverAndVersionPanel, gridBagConstraints);
348
349     }// </editor-fold>//GEN-END:initComponents
350

351     private void manageServersButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_manageServersButtonActionPerformed
352
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
353         String JavaDoc lastSelectedServerInstanceID = null;
354         if (serverInstanceWrapper != null) {
355             lastSelectedServerInstanceID = serverInstanceWrapper.getServerInstanceID();
356         }
357         ServerManager.showCustomizer(lastSelectedServerInstanceID);
358         String JavaDoc lastSelectedJ2eeSpecLevel = (String JavaDoc) j2eeSpecComboBox.getSelectedItem();
359         // refresh the list of servers
360
initServers(lastSelectedServerInstanceID);
361         if (lastSelectedJ2eeSpecLevel != null) {
362             j2eeSpecComboBox.setSelectedItem(lastSelectedJ2eeSpecLevel);
363         }
364     }//GEN-LAST:event_manageServersButtonActionPerformed
365

366     private void createCarCheckBox_action(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_createCarCheckBox_action
367
jTextFieldCarName.setEnabled(createCarCheckBox.isSelected());
368         mainClassTextField.setEnabled(createCarCheckBox.isSelected());
369         this.panel.fireChangeEvent();
370     }//GEN-LAST:event_createCarCheckBox_action
371

372     private void createWebAppCheckBox_action(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_createWebAppCheckBox_action
373
jTextFieldWebAppName.setEnabled(createWARCheckBox.isSelected());
374         this.panel.fireChangeEvent();
375     }//GEN-LAST:event_createWebAppCheckBox_action
376

377     private void createEjbCheckBox_action(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_createEjbCheckBox_action
378
jTextFieldEjbModuleName.setEnabled(createEjbCheckBox.isSelected());
379         this.panel.fireChangeEvent();
380     }//GEN-LAST:event_createEjbCheckBox_action
381

382     private void serverInstanceComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_serverInstanceComboBoxActionPerformed
383
String JavaDoc prevSelectedItem = (String JavaDoc) j2eeSpecComboBox.getSelectedItem();
384         // update the j2ee spec list according to the selected server
385
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
386         if (serverInstanceWrapper != null) {
387             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceWrapper.getServerInstanceID());
388             Set JavaDoc supportedVersions = j2eePlatform.getSupportedSpecVersions(J2eeModule.EAR);
389             j2eeSpecComboBox.removeAllItems();
390             if (supportedVersions.contains(J2eeModule.JAVA_EE_5)) {
391                 j2eeSpecComboBox.addItem(EarProjectProperties.JAVA_EE_SPEC_50_LABEL);
392             }
393             if (supportedVersions.contains(J2eeModule.J2EE_14)) {
394                 j2eeSpecComboBox.addItem(EarProjectProperties.J2EE_SPEC_14_LABEL);
395             }
396             if (prevSelectedItem != null) {
397                 j2eeSpecComboBox.setSelectedItem(prevSelectedItem);
398             }
399             boolean carSupported = j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.CLIENT);
400             createCarCheckBox.setEnabled(carSupported);
401             jTextFieldCarName.setEnabled(carSupported && createCarCheckBox.isSelected());
402             mainClassLabel.setEnabled(carSupported);
403             mainClassTextField.setEnabled(carSupported && createCarCheckBox.isSelected());
404         } else {
405             j2eeSpecComboBox.removeAllItems();
406         }
407         // revalidate the form
408
panel.fireChangeEvent();
409     }//GEN-LAST:event_serverInstanceComboBoxActionPerformed
410

411     private void j2eeSpecComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_j2eeSpecComboBoxActionPerformed
412
setJ2eeVersionWarningPanel();
413     }//GEN-LAST:event_j2eeSpecComboBoxActionPerformed
414

415     public void propertyChange(PropertyChangeEvent JavaDoc event) {
416         if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event.getPropertyName())) {
417             String JavaDoc newProjectName = (String JavaDoc) event.getNewValue();
418             if (newProjectName.trim().equals("")) {
419                 return;
420             }
421             this.jTextFieldEjbModuleName.setText(MessageFormat.format(
422                     NbBundle.getMessage(PanelOptionsVisual.class,"TXT_EJBProjectName"), new Object JavaDoc[] {newProjectName}));
423             this.jTextFieldWebAppName.setText(MessageFormat.format(
424                     NbBundle.getMessage(PanelOptionsVisual.class,"TXT_WebAppProjectName"), new Object JavaDoc[] {newProjectName}));
425             this.jTextFieldCarName.setText(MessageFormat.format(
426                     NbBundle.getMessage(PanelOptionsVisual.class,"TXT_AppClientProjectName"), new Object JavaDoc[] {newProjectName}));
427             newProjectName = getPackageName(newProjectName);
428             if (!Utilities.isJavaIdentifier(newProjectName)) {
429                 newProjectName = NbBundle.getMessage(PanelOptionsVisual.class, "TXT_PackageNameSuffix", newProjectName);
430             }
431             this.mainClassTextField.setText(MessageFormat.format(
432                     NbBundle.getMessage(PanelOptionsVisual.class,"TXT_ClassName"), new Object JavaDoc[] {newProjectName}));
433         }
434     }
435     
436     boolean valid(WizardDescriptor wizardDescriptor) {
437         if (getSelectedServer() == null) {
438             setErrorMessage("MSG_NoServer", wizardDescriptor); // NOI18N
439
return false;
440         }
441         
442         if (createWARCheckBox.isSelected()) {
443             String JavaDoc warName = jTextFieldWebAppName.getText();
444             if (warName.length() < 1) {
445                 setErrorMessage("MSG_NoWARName", wizardDescriptor); // NOI18N
446
return false;
447             }
448             if (!warName.endsWith("-war")) { // NOI18N
449
// this is really just a warning
450
setErrorMessage("MSG_WARNameNotBlueprints", wizardDescriptor); // NOI18N
451
}
452         }
453         
454         if (createEjbCheckBox.isSelected()) {
455             String JavaDoc jarName = jTextFieldEjbModuleName.getText();
456             if (jarName.length() < 1) {
457                 setErrorMessage("MSG_NoJARName", wizardDescriptor); // NOI18N
458
return false;
459             }
460             if (!jarName.endsWith("-ejb")) { //NOI18N
461
// this is really just a warning
462
setErrorMessage("MSG_JARNameNotBlueprints", wizardDescriptor); // NOI18N
463
}
464         }
465         
466         if (createCarCheckBox.isSelected()) {
467             String JavaDoc jarName = jTextFieldCarName.getText();
468             if (jarName.length() < 1) {
469                 setErrorMessage("MSG_NoCARName", wizardDescriptor); // NOI18N
470
return false;
471             }
472             if (!valid) {
473                 setErrorMessage("ERROR_IllegalMainClassName", wizardDescriptor); // NOI18N
474
return this.valid;
475             }
476             if (!jarName.endsWith("-app-client")) { //NOI18N
477
// this is really just a warning
478
setErrorMessage("MSG_CARNameNotBlueprints", wizardDescriptor); // NOI18N
479
}
480         }
481         
482         // check whether an application client is supported by the target server
483
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
484         if (serverInstanceWrapper != null) {
485             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceWrapper.getServerInstanceID());
486             if (!j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.CLIENT)) {
487                 // show warning/info
488
setErrorMessage("MSG_CARIsNotSupported", wizardDescriptor);
489             }
490         }
491         
492         String JavaDoc specVer = getSelectedJ2eeSpec();
493         if (null == specVer || specVer.equals(J2eeModule.J2EE_13)) {
494             setErrorMessage("MSG_UnsupportedSpec", wizardDescriptor); // NOI18N
495
return false;
496         }
497         return true;
498     }
499     
500     private static void setErrorMessage(
501             final String JavaDoc errMsgKey, final WizardDescriptor wizardDescriptor) {
502         wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
503
NbBundle.getMessage(PanelOptionsVisual.class, errMsgKey));
504     }
505     
506     void store(WizardDescriptor d) {
507         d.putProperty(WizardProperties.SET_AS_MAIN, setAsMainCheckBox.isSelected() ? Boolean.TRUE : Boolean.FALSE );
508         d.putProperty(WizardProperties.SERVER_INSTANCE_ID, getSelectedServer());
509         d.putProperty(WizardProperties.J2EE_LEVEL, getSelectedJ2eeSpec());
510         // d.putProperty(WizardProperties.CONTEXT_PATH, jTextFieldContextPath.getText().trim());
511
d.putProperty(WizardProperties.CREATE_WAR, createWARCheckBox.isSelected() ? Boolean.TRUE: Boolean.FALSE);
512         d.putProperty(WizardProperties.CREATE_JAR, createEjbCheckBox.isSelected() ? Boolean.TRUE: Boolean.FALSE);
513         d.putProperty(WizardProperties.CREATE_CAR, createCarCheckBox.isSelected() ? Boolean.TRUE: Boolean.FALSE);
514         d.putProperty(WizardProperties.WAR_NAME, jTextFieldWebAppName.getText());
515         d.putProperty(WizardProperties.JAR_NAME, jTextFieldEjbModuleName.getText());
516         d.putProperty(WizardProperties.CAR_NAME, jTextFieldCarName.getText());
517         d.putProperty(WizardProperties.MAIN_CLASS, mainClassTextField.getText().trim()); // NOI18N
518
if (warningPanel != null && warningPanel.getWarningType() != null && warningPanel.getDowngradeAllowed()) {
519             d.putProperty(WizardProperties.JAVA_PLATFORM, warningPanel.getSuggestedJavaPlatformName());
520             String JavaDoc j2ee = getSelectedJ2eeSpec();
521             if (j2ee != null) {
522                 String JavaDoc warningType = J2eeVersionWarningPanel.findWarningType(j2ee);
523                 FoldersListSettings fls = FoldersListSettings.getDefault();
524                 String JavaDoc srcLevel = "1.6"; // NOI18N
525
if ((warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_14)
526                         || warningType.equals(J2eeVersionWarningPanel.WARN_SET_JDK_14))
527                         && fls.isAgreedSetSourceLevel14()) {
528                     srcLevel = "1.4"; // NOI18N
529
} else if ((warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_15)
530                         || warningType.equals(J2eeVersionWarningPanel.WARN_SET_JDK_15))
531                         && fls.isAgreedSetSourceLevel15()) {
532                     srcLevel = "1.5"; // NOI18N
533
}
534                 d.putProperty(WizardProperties.SOURCE_LEVEL, srcLevel);
535             }
536         } else {
537             d.putProperty(WizardProperties.SOURCE_LEVEL, null);
538         }
539     }
540     
541     void read(WizardDescriptor d) {
542     }
543     
544     // Variables declaration - do not modify//GEN-BEGIN:variables
545
private javax.swing.JCheckBox JavaDoc createCarCheckBox;
546     private javax.swing.JCheckBox JavaDoc createEjbCheckBox;
547     private javax.swing.JCheckBox JavaDoc createWARCheckBox;
548     private javax.swing.JComboBox JavaDoc j2eeSpecComboBox;
549     private javax.swing.JLabel JavaDoc j2eeSpecLabel;
550     private javax.swing.JTextField JavaDoc jTextFieldCarName;
551     private javax.swing.JTextField JavaDoc jTextFieldEjbModuleName;
552     private javax.swing.JTextField JavaDoc jTextFieldWebAppName;
553     private javax.swing.JLabel JavaDoc mainClassLabel;
554     private javax.swing.JTextField JavaDoc mainClassTextField;
555     private javax.swing.JButton JavaDoc manageServersButton;
556     private javax.swing.JPanel JavaDoc serverAndVersionPanel;
557     private javax.swing.JComboBox JavaDoc serverInstanceComboBox;
558     private javax.swing.JLabel JavaDoc serverInstanceLabel;
559     private javax.swing.JCheckBox JavaDoc setAsMainCheckBox;
560     private javax.swing.JPanel JavaDoc warningPlaceHolderPanel;
561     // End of variables declaration//GEN-END:variables
562

563     /**
564      * Init servers model
565      * @param selectedServerInstanceID preselected instance or null if non is preselected
566      */

567     private void initServers(String JavaDoc selectedServerInstanceID) {
568         // init the list of server instances
569
serversModel.removeAllElements();
570         Set JavaDoc<ServerInstanceWrapper> servers = new TreeSet JavaDoc<ServerInstanceWrapper>();
571         ServerInstanceWrapper selectedItem = null;
572         boolean sjasFound = false;
573         for (String JavaDoc serverInstanceID : Deployment.getDefault().getServerInstanceIDs()) {
574             String JavaDoc displayName = Deployment.getDefault().getServerInstanceDisplayName(serverInstanceID);
575             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID);
576             if (displayName != null && j2eePlatform != null && j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.EAR)) {
577                 ServerInstanceWrapper serverWrapper = new ServerInstanceWrapper(serverInstanceID, displayName);
578                 // decide whether this server should be preselected
579
if (selectedItem == null || !sjasFound) {
580                     if (selectedServerInstanceID != null) {
581                         if (selectedServerInstanceID.equals(serverInstanceID)) {
582                             selectedItem = serverWrapper;
583                         }
584                     } else {
585                         // preselect the best server ;)
586
String JavaDoc shortName = Deployment.getDefault().getServerID(serverInstanceID);
587                         if ("J2EE".equals(shortName)) { // NOI18N
588
selectedItem = serverWrapper;
589                             sjasFound = true;
590                         }
591                         else
592                         if ("JBoss4".equals(shortName)) { // NOI18N
593
selectedItem = serverWrapper;
594                         }
595                     }
596                 }
597                 servers.add(serverWrapper);
598             }
599         }
600         for (ServerInstanceWrapper item : servers) {
601             serversModel.addElement(item);
602         }
603         if (selectedItem != null) {
604             // set the preselected item
605
serversModel.setSelectedItem(selectedItem);
606         } else if (serversModel.getSize() > 0) {
607             // set the first item
608
serversModel.setSelectedItem(serversModel.getElementAt(0));
609         }
610     }
611     
612     private String JavaDoc getSelectedJ2eeSpec() {
613         Object JavaDoc item = j2eeSpecComboBox.getSelectedItem();
614         return item == null ? null
615                 : item.equals(EarProjectProperties.JAVA_EE_SPEC_50_LABEL) ? J2eeModule.JAVA_EE_5 :
616                     ( item.equals(EarProjectProperties.J2EE_SPEC_14_LABEL) ? J2eeModule.J2EE_14 : J2eeModule.J2EE_13);
617     }
618     
619     private String JavaDoc getSelectedServer() {
620         ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
621         if (serverInstanceWrapper == null) {
622             return null;
623         }
624         return serverInstanceWrapper.getServerInstanceID();
625     }
626     
627     private void setJ2eeVersionWarningPanel() {
628         String JavaDoc j2ee = getSelectedJ2eeSpec();
629         if (j2ee == null) {
630             return;
631         }
632         String JavaDoc warningType = J2eeVersionWarningPanel.findWarningType(j2ee);
633         if (warningType == null && warningPanel == null) {
634             return;
635         }
636         if (warningPanel == null) {
637             warningPanel = new J2eeVersionWarningPanel(warningType);
638             warningPlaceHolderPanel.add(warningPanel, java.awt.BorderLayout.CENTER);
639         }
640         warningPanel.setWarningType(warningType);
641     }
642     
643     private void mainClassChanged() {
644         String JavaDoc mainClassName = this.mainClassTextField.getText().trim();
645         StringTokenizer JavaDoc tk = new StringTokenizer JavaDoc(mainClassName, "."); //NOI18N
646
boolean valid = tk.countTokens() > 0;
647         while (tk.hasMoreTokens()) {
648             String JavaDoc token = tk.nextToken();
649             if (token.length() == 0 || !Utilities.isJavaIdentifier(token)) {
650                 valid = false;
651                 break;
652             }
653         }
654         this.valid = valid;
655         this.panel.fireChangeEvent();
656     }
657     
658     private void projectNameChanged() {
659         this.panel.fireChangeEvent();
660     }
661     
662     private String JavaDoc getPackageName(String JavaDoc displayName) {
663         StringBuffer JavaDoc builder = new StringBuffer JavaDoc();
664         boolean firstLetter = true;
665         for (int i=0; i< displayName.length(); i++) {
666             char c = displayName.charAt(i);
667             if ((!firstLetter && Character.isJavaIdentifierPart(c)) || (firstLetter && Character.isJavaIdentifierStart(c))) {
668                 firstLetter = false;
669                 if (Character.isUpperCase(c)) {
670                     c = Character.toLowerCase(c);
671                 }
672                 builder.append(c);
673             }
674         }
675         return builder.length() == 0 ? NbBundle.getMessage(PanelOptionsVisual.class,"TXT_DefaultPackageName") : builder.toString();
676     }
677     
678     /**
679      * Server instance wrapper represents server instances in the servers combobox.
680      * @author sherold
681      */

682     private static class ServerInstanceWrapper implements Comparable JavaDoc {
683
684         private final String JavaDoc serverInstanceID;
685         private final String JavaDoc displayName;
686
687         ServerInstanceWrapper(String JavaDoc serverInstanceID, String JavaDoc displayName) {
688             this.serverInstanceID = serverInstanceID;
689             this.displayName = displayName;
690         }
691
692         public String JavaDoc getServerInstanceID() {
693             return serverInstanceID;
694         }
695
696         public String JavaDoc toString() {
697             return displayName;
698         }
699
700         public int compareTo(Object JavaDoc o) {
701             return toString().compareTo(o.toString());
702         }
703         
704     }
705     
706 }
707
708
Popular Tags