KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > 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.web.project.ui.wizards;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.TreeSet JavaDoc;
26 import javax.swing.DefaultComboBoxModel JavaDoc;
27 import org.netbeans.api.project.Project;
28 import org.netbeans.api.project.ProjectInformation;
29 import org.netbeans.api.project.ProjectUtils;
30 import org.netbeans.api.project.ui.OpenProjects;
31 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
32 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
33 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModuleContainer;
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.web.project.api.WebProjectUtilities;
37 import org.netbeans.modules.web.project.ui.FoldersListSettings;
38 import org.openide.WizardDescriptor;
39 import org.openide.util.NbBundle;
40
41 public class PanelOptionsVisual extends javax.swing.JPanel JavaDoc {
42     
43     private PanelConfigureProject panel;
44     private String JavaDoc sourceStructure;
45     private boolean contextModified = false;
46     private final DefaultComboBoxModel JavaDoc serversModel = new DefaultComboBoxModel JavaDoc();
47     
48     private J2eeVersionWarningPanel warningPanel;
49     
50     private static final String JavaDoc J2EE_SPEC_13_LABEL = NbBundle.getMessage(PanelOptionsVisual.class, "J2EESpecLevel_13"); //NOI18N
51
private static final String JavaDoc J2EE_SPEC_14_LABEL = NbBundle.getMessage(PanelOptionsVisual.class, "J2EESpecLevel_14"); //NOI18N
52
private static final String JavaDoc JAVA_EE_SPEC_50_LABEL = NbBundle.getMessage(PanelOptionsVisual.class, "JavaEESpecLevel_50"); //NOI18N
53

54     private List JavaDoc earProjects;
55     
56     /** Creates new form PanelOptionsVisual */
57     public PanelOptionsVisual(PanelConfigureProject panel) {
58         initComponents();
59         setJ2eeVersionWarningPanel();
60         this.panel = panel;
61         initServers(FoldersListSettings.getDefault().getLastUsedServer());
62         // preselect the first item in the j2ee spec combo
63
if (j2eeSpecComboBox.getModel().getSize() > 0) {
64             j2eeSpecComboBox.setSelectedIndex(0);
65         }
66         initJSrcStructureSpecs();
67         initEnterpriseApplications();
68     }
69     
70     protected int computeHeight() {
71         return srcStructComboBox.getFontMetrics(srcStructComboBox.getFont()).getHeight() * 9 + 100;
72     }
73     
74     /** This method is called from within the constructor to
75      * initialize the form.
76      * WARNING: Do NOT modify this code. The content of this method is
77      * always regenerated by the Form Editor.
78      */

79     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
80
private void initComponents() {
81         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
82
83         srcStructLabel = new javax.swing.JLabel JavaDoc();
84         srcStructComboBox = new javax.swing.JComboBox JavaDoc();
85         jLabelEnterprise = new javax.swing.JLabel JavaDoc();
86         jComboBoxEnterprise = new javax.swing.JComboBox JavaDoc();
87         jPanel1 = new javax.swing.JPanel JavaDoc();
88         serverInstanceLabel = new javax.swing.JLabel JavaDoc();
89         serverInstanceComboBox = new javax.swing.JComboBox JavaDoc();
90         j2eeSpecLabel = new javax.swing.JLabel JavaDoc();
91         j2eeSpecComboBox = new javax.swing.JComboBox JavaDoc();
92         jLabelContextPath = new javax.swing.JLabel JavaDoc();
93         jTextFieldContextPath = new javax.swing.JTextField JavaDoc();
94         manageServersButton = new javax.swing.JButton JavaDoc();
95         warningPlaceHolderPanel = new javax.swing.JPanel JavaDoc();
96         setAsMainCheckBox = new javax.swing.JCheckBox JavaDoc();
97
98         setLayout(new java.awt.GridBagLayout JavaDoc());
99
100         srcStructLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_SourceStructure_CheckBoxMnemonic").charAt(0));
101         srcStructLabel.setLabelFor(srcStructComboBox);
102         srcStructLabel.setText(NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_SourceStructure_Label"));
103         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
104         gridBagConstraints.gridx = 0;
105         gridBagConstraints.gridy = 0;
106         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
107         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
108         add(srcStructLabel, gridBagConstraints);
109         srcStructLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_NWP1_SourceStructureComboBox_A11YDesc"));
110
111         srcStructComboBox.setPrototypeDisplayValue("MMMMMMMMMMMMMMM" /* "Java BluePrints" */);
112         srcStructComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
113             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
114                 srcStructComboBoxActionPerformed(evt);
115             }
116         });
117
118         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
119         gridBagConstraints.gridx = 1;
120         gridBagConstraints.gridy = 0;
121         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
122         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
123         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
124         add(srcStructComboBox, gridBagConstraints);
125
126         jLabelEnterprise.setDisplayedMnemonic(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_NWP1_AddToEnterprise_LabelMnemonic").charAt(0));
127         jLabelEnterprise.setLabelFor(jComboBoxEnterprise);
128         jLabelEnterprise.setText(NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_AddToEnterprise_Label"));
129         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
130         gridBagConstraints.gridx = 0;
131         gridBagConstraints.gridy = 1;
132         gridBagConstraints.gridwidth = 2;
133         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
134         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
135         add(jLabelEnterprise, gridBagConstraints);
136         jLabelEnterprise.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_NWP1_AddToEnterpriseComboBox_A11YDesc"));
137
138         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
139         gridBagConstraints.gridx = 2;
140         gridBagConstraints.gridy = 1;
141         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
142         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
143         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
144         add(jComboBoxEnterprise, gridBagConstraints);
145         jComboBoxEnterprise.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_NWP1_AddToEnterpriseComboBox_A11YDesc"));
146
147         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
148
149         serverInstanceLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_Server_LabelMnemonic").charAt(0));
150         serverInstanceLabel.setLabelFor(serverInstanceComboBox);
151         serverInstanceLabel.setText(NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_Server"));
152         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
153         gridBagConstraints.gridx = 0;
154         gridBagConstraints.gridy = 0;
155         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
156         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 11);
157         jPanel1.add(serverInstanceLabel, gridBagConstraints);
158
159         serverInstanceComboBox.setModel(serversModel);
160         serverInstanceComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
161             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
162                 serverInstanceComboBoxActionPerformed(evt);
163             }
164         });
165
166         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
167         gridBagConstraints.gridx = 1;
168         gridBagConstraints.gridy = 0;
169         gridBagConstraints.gridwidth = 2;
170         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
171         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
172         gridBagConstraints.weightx = 1.0;
173         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 6);
174         jPanel1.add(serverInstanceComboBox, gridBagConstraints);
175         serverInstanceComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_NWP1_Server_ComboBox_A11YDesc"));
176
177         j2eeSpecLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_J2EESpecLevel_CheckBoxMnemonic").charAt(0));
178         j2eeSpecLabel.setLabelFor(j2eeSpecComboBox);
179         j2eeSpecLabel.setText(NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_J2EESpecLevel_Label"));
180         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
181         gridBagConstraints.gridx = 0;
182         gridBagConstraints.gridy = 1;
183         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
184         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 11);
185         jPanel1.add(j2eeSpecLabel, gridBagConstraints);
186
187         j2eeSpecComboBox.setPrototypeDisplayValue("MMMMMMMMM" /* "Java EE 5" */);
188         j2eeSpecComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
189             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
190                 j2eeSpecComboBoxActionPerformed(evt);
191             }
192         });
193
194         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
195         gridBagConstraints.gridx = 1;
196         gridBagConstraints.gridy = 1;
197         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
198         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
199         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
200         jPanel1.add(j2eeSpecComboBox, gridBagConstraints);
201         j2eeSpecComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_NPW1_J2EESpecLevel_A11YDesc"));
202
203         jLabelContextPath.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_ContextPath_CheckBoxMnemonic").charAt(0));
204         jLabelContextPath.setLabelFor(jTextFieldContextPath);
205         jLabelContextPath.setText(NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_ContextPath_Label"));
206         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
207         gridBagConstraints.gridx = 0;
208         gridBagConstraints.gridy = 2;
209         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
210         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
211         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 11);
212         jPanel1.add(jLabelContextPath, gridBagConstraints);
213
214         jTextFieldContextPath.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
215             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
216                 jTextFieldContextPathKeyReleased(evt);
217             }
218         });
219
220         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
221         gridBagConstraints.gridx = 1;
222         gridBagConstraints.gridy = 2;
223         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
224         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
225         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
226         jPanel1.add(jTextFieldContextPath, gridBagConstraints);
227         jTextFieldContextPath.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_NWP1_ContextPath_A11YDesc"));
228
229         org.openide.awt.Mnemonics.setLocalizedText(manageServersButton, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_ManageServers"));
230         manageServersButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
231             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
232                 manageServersButtonActionPerformed(evt);
233             }
234         });
235
236         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
237         gridBagConstraints.gridx = 3;
238         gridBagConstraints.gridy = 0;
239         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
240         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
241         jPanel1.add(manageServersButton, gridBagConstraints);
242         manageServersButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ASCN_ManageServers"));
243         manageServersButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ASCD_ManageServers"));
244
245         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
246         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
247         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
248         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
249         add(jPanel1, gridBagConstraints);
250
251         warningPlaceHolderPanel.setLayout(new java.awt.BorderLayout JavaDoc());
252
253         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
254         gridBagConstraints.gridx = 0;
255         gridBagConstraints.gridy = 3;
256         gridBagConstraints.gridwidth = 3;
257         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
258         gridBagConstraints.weightx = 1.0;
259         add(warningPlaceHolderPanel, gridBagConstraints);
260
261         setAsMainCheckBox.setMnemonic(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_SetAsMain_CheckBoxMnemonic").charAt(0));
262         setAsMainCheckBox.setSelected(true);
263         setAsMainCheckBox.setText(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_SetAsMain_CheckBox"));
264         setAsMainCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
265         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
266         gridBagConstraints.gridx = 0;
267         gridBagConstraints.gridy = 4;
268         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
269         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
270         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
271         gridBagConstraints.weightx = 1.0;
272         gridBagConstraints.weighty = 1.0;
273         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
274         add(setAsMainCheckBox, gridBagConstraints);
275         setAsMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_NWP1_SetAsMain_A11YDesc"));
276
277     }// </editor-fold>//GEN-END:initComponents
278

279     private void manageServersButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_manageServersButtonActionPerformed
280
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
281         String JavaDoc lastSelectedServerInstanceID = null;
282         if (serverInstanceWrapper != null) {
283             lastSelectedServerInstanceID = serverInstanceWrapper.getServerInstanceID();
284         }
285         ServerManager.showCustomizer(lastSelectedServerInstanceID);
286         String JavaDoc lastSelectedJ2eeSpecLevel = (String JavaDoc) j2eeSpecComboBox.getSelectedItem();
287         // refresh the list of servers
288
initServers(lastSelectedServerInstanceID);
289         if (lastSelectedJ2eeSpecLevel != null) {
290             j2eeSpecComboBox.setSelectedItem(lastSelectedJ2eeSpecLevel);
291         }
292     }//GEN-LAST:event_manageServersButtonActionPerformed
293

294     private void j2eeSpecComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_j2eeSpecComboBoxActionPerformed
295
setJ2eeVersionWarningPanel();
296     }//GEN-LAST:event_j2eeSpecComboBoxActionPerformed
297

298     private void serverInstanceComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_serverInstanceComboBoxActionPerformed
299
String JavaDoc prevSelectedItem = (String JavaDoc) j2eeSpecComboBox.getSelectedItem();
300         // update the j2ee spec list according to the selected server
301
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
302         if (serverInstanceWrapper != null) {
303             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceWrapper.getServerInstanceID());
304             Set JavaDoc supportedVersions = j2eePlatform.getSupportedSpecVersions(J2eeModule.WAR);
305             j2eeSpecComboBox.removeAllItems();
306             if (supportedVersions.contains(J2eeModule.JAVA_EE_5)) {
307                 j2eeSpecComboBox.addItem(JAVA_EE_SPEC_50_LABEL);
308             }
309             if (supportedVersions.contains(J2eeModule.J2EE_14)) {
310                 j2eeSpecComboBox.addItem(J2EE_SPEC_14_LABEL);
311             }
312             if (supportedVersions.contains(J2eeModule.J2EE_13)) {
313                 j2eeSpecComboBox.addItem(J2EE_SPEC_13_LABEL);
314             }
315             if (prevSelectedItem != null) {
316                 j2eeSpecComboBox.setSelectedItem(prevSelectedItem);
317             }
318         } else {
319             j2eeSpecComboBox.removeAllItems();
320         }
321         // revalidate the form
322
panel.fireChangeEvent();
323     }//GEN-LAST:event_serverInstanceComboBoxActionPerformed
324

325     private void srcStructComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_srcStructComboBoxActionPerformed
326
switch (srcStructComboBox.getSelectedIndex()) {
327             case 0: sourceStructure = WebProjectUtilities.SRC_STRUCT_BLUEPRINTS;
328                     break;
329             case 1: sourceStructure = WebProjectUtilities.SRC_STRUCT_JAKARTA;
330         }
331     }//GEN-LAST:event_srcStructComboBoxActionPerformed
332

333     private void jTextFieldContextPathKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTextFieldContextPathKeyReleased
334
contextModified = true;
335     }//GEN-LAST:event_jTextFieldContextPathKeyReleased
336

337     boolean valid(WizardDescriptor wizardDescriptor) {
338         if (getSelectedServer() == null) {
339             String JavaDoc errMsg = NbBundle.getMessage(PanelOptionsVisual.class, "MSG_NoServer");
340             wizardDescriptor.putProperty( "WizardPanel_errorMessage", errMsg); // NOI18N
341
return false;
342         }
343         return true;
344     }
345
346     void store(WizardDescriptor d) {
347         d.putProperty(WizardProperties.SET_AS_MAIN, setAsMainCheckBox.isSelected() ? Boolean.TRUE : Boolean.FALSE );
348         d.putProperty(WizardProperties.SERVER_INSTANCE_ID, getSelectedServer());
349         d.putProperty(WizardProperties.SOURCE_STRUCTURE, sourceStructure);
350         d.putProperty(WizardProperties.J2EE_LEVEL, getSelectedJ2eeSpec());
351         d.putProperty(WizardProperties.CONTEXT_PATH, jTextFieldContextPath.getText().trim());
352         d.putProperty(WizardProperties.EAR_APPLICATION, getSelectedEarApplication());
353         // TODO: for Java EE 5.0, warningpanel is null,
354
// but we need some check for Java SE 5.0 and higher
355
if (warningPanel != null && warningPanel.getDowngradeAllowed()) {
356             d.putProperty(WizardProperties.JAVA_PLATFORM, warningPanel.getSuggestedJavaPlatformName());
357             
358             String JavaDoc j2ee = getSelectedJ2eeSpec();
359             if (j2ee != null) {
360                 String JavaDoc warningType = J2eeVersionWarningPanel.findWarningType(j2ee);
361                 FoldersListSettings fls = FoldersListSettings.getDefault();
362                 String JavaDoc srcLevel = "1.6"; //NOI18N
363
if ((warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_14) && fls.isAgreedSetSourceLevel14()) ||
364                         (warningType.equals(J2eeVersionWarningPanel.WARN_SET_JDK_14) && fls.isAgreedSetJdk14()))
365                     srcLevel = "1.4"; //NOI18N
366
else if ((warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_15) && fls.isAgreedSetSourceLevel15()) ||
367                         (warningType.equals(J2eeVersionWarningPanel.WARN_SET_JDK_15) && fls.isAgreedSetJdk15()))
368                     srcLevel = "1.5"; //NOI18N
369

370                 d.putProperty(WizardProperties.SOURCE_LEVEL, srcLevel);
371             }
372         } else
373             d.putProperty(WizardProperties.SOURCE_LEVEL, null);
374     }
375     
376     void read(WizardDescriptor d) {
377     }
378     
379     // Variables declaration - do not modify//GEN-BEGIN:variables
380
private javax.swing.JComboBox JavaDoc j2eeSpecComboBox;
381     private javax.swing.JLabel JavaDoc j2eeSpecLabel;
382     private javax.swing.JComboBox JavaDoc jComboBoxEnterprise;
383     private javax.swing.JLabel JavaDoc jLabelContextPath;
384     private javax.swing.JLabel JavaDoc jLabelEnterprise;
385     private javax.swing.JPanel JavaDoc jPanel1;
386     protected javax.swing.JTextField JavaDoc jTextFieldContextPath;
387     private javax.swing.JButton JavaDoc manageServersButton;
388     private javax.swing.JComboBox JavaDoc serverInstanceComboBox;
389     private javax.swing.JLabel JavaDoc serverInstanceLabel;
390     private javax.swing.JCheckBox JavaDoc setAsMainCheckBox;
391     private javax.swing.JComboBox JavaDoc srcStructComboBox;
392     private javax.swing.JLabel JavaDoc srcStructLabel;
393     private javax.swing.JPanel JavaDoc warningPlaceHolderPanel;
394     // End of variables declaration//GEN-END:variables
395

396     /**
397      * Init servers model
398      * @param selectedServerInstanceID preselected instance or null if non is preselected
399      */

400     private void initServers(String JavaDoc selectedServerInstanceID) {
401         // init the list of server instances
402
serversModel.removeAllElements();
403         Set JavaDoc<ServerInstanceWrapper> servers = new TreeSet JavaDoc<ServerInstanceWrapper>();
404         ServerInstanceWrapper selectedItem = null;
405         boolean sjasFound = false;
406         for (String JavaDoc serverInstanceID : Deployment.getDefault().getServerInstanceIDs()) {
407             String JavaDoc displayName = Deployment.getDefault().getServerInstanceDisplayName(serverInstanceID);
408             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID);
409             if (displayName != null && j2eePlatform != null && j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.WAR)) {
410                 ServerInstanceWrapper serverWrapper = new ServerInstanceWrapper(serverInstanceID, displayName);
411                 // decide whether this server should be preselected
412
if (selectedItem == null || !sjasFound) {
413                     if (selectedServerInstanceID != null) {
414                         if (selectedServerInstanceID.equals(serverInstanceID)) {
415                             selectedItem = serverWrapper;
416                         }
417                     } else {
418                         // preselect the best server ;)
419
String JavaDoc shortName = Deployment.getDefault().getServerID(serverInstanceID);
420                         if ("J2EE".equals(shortName)) { // NOI18N
421
selectedItem = serverWrapper;
422                             sjasFound = true;
423                         }
424                         else
425                         if ("JBoss4".equals(shortName)) { // NOI18N
426
selectedItem = serverWrapper;
427                         }
428                     }
429                 }
430                 servers.add(serverWrapper);
431             }
432         }
433         for (ServerInstanceWrapper item : servers) {
434             serversModel.addElement(item);
435         }
436         if (selectedItem != null) {
437             // set the preselected item
438
serversModel.setSelectedItem(selectedItem);
439         } else if (serversModel.getSize() > 0) {
440             // set the first item
441
serversModel.setSelectedItem(serversModel.getElementAt(0));
442         }
443     }
444     
445     private String JavaDoc getSelectedJ2eeSpec() {
446         Object JavaDoc item = j2eeSpecComboBox.getSelectedItem();
447         return item == null ? null
448                             : item.equals(JAVA_EE_SPEC_50_LABEL) ? J2eeModule.JAVA_EE_5 :
449                                 ( item.equals(J2EE_SPEC_14_LABEL) ? J2eeModule.J2EE_14 : J2eeModule.J2EE_13);
450     }
451     
452     private String JavaDoc getSelectedServer() {
453         ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
454         if (serverInstanceWrapper == null) {
455             return null;
456         }
457         return serverInstanceWrapper.getServerInstanceID();
458     }
459     
460     private void initJSrcStructureSpecs() {
461         srcStructComboBox.addItem(NbBundle.getMessage(PanelOptionsVisual.class, "SourceStructure_0")); //NOI18N
462
srcStructComboBox.addItem(NbBundle.getMessage(PanelOptionsVisual.class, "SourceStructure_1")); //NOI18N
463
srcStructComboBox.setSelectedIndex(0);
464     }
465
466     protected boolean isContextModified() {
467          return contextModified;
468     }
469
470     private Project getSelectedEarApplication() {
471         int idx = jComboBoxEnterprise.getSelectedIndex();
472         return (idx <= 0) ? null : (Project) earProjects.get(idx - 1);
473     }
474     
475     private void initEnterpriseApplications() {
476         jComboBoxEnterprise.addItem(NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_AddToEnterprise_None")); // TODO: AB: add to bundle
477
jComboBoxEnterprise.setSelectedIndex(0);
478         
479         Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
480         earProjects = new ArrayList JavaDoc();
481         for (int i = 0; i < allProjects.length; i++) {
482             J2eeModuleContainer container = (J2eeModuleContainer) allProjects[i].getLookup().lookup(J2eeModuleContainer.class);
483             ProjectInformation projectInfo = ProjectUtils.getInformation(allProjects[i]);
484             if (container != null) {
485                 earProjects.add(projectInfo.getProject());
486                 jComboBoxEnterprise.addItem(projectInfo.getDisplayName());
487             }
488         }
489         if (earProjects.size() <= 0) {
490             jComboBoxEnterprise.setEnabled(false);
491         }
492     }
493     
494     private void setJ2eeVersionWarningPanel() {
495         String JavaDoc j2ee = getSelectedJ2eeSpec();
496         if (j2ee == null)
497             return;
498         String JavaDoc warningType = J2eeVersionWarningPanel.findWarningType(j2ee);
499         if (warningType == null && warningPanel == null)
500             return;
501         if (warningPanel == null) {
502             warningPanel = new J2eeVersionWarningPanel(warningType);
503             warningPlaceHolderPanel.add(warningPanel, java.awt.BorderLayout.CENTER);
504             warningPanel.setWarningType(warningType);
505         } else {
506             warningPanel.setWarningType(warningType);
507         }
508     }
509
510     /**
511      * Server instance wrapper represents server instances in the servers combobox.
512      * @author sherold
513      */

514     private static class ServerInstanceWrapper implements Comparable JavaDoc {
515
516         private final String JavaDoc serverInstanceID;
517         private final String JavaDoc displayName;
518
519         ServerInstanceWrapper(String JavaDoc serverInstanceID, String JavaDoc displayName) {
520             this.serverInstanceID = serverInstanceID;
521             this.displayName = displayName;
522         }
523
524         public String JavaDoc getServerInstanceID() {
525             return serverInstanceID;
526         }
527
528         public String JavaDoc toString() {
529             return displayName;
530         }
531
532         public int compareTo(Object JavaDoc o) {
533             return toString().compareTo(o.toString());
534         }
535     }
536 }
537
Popular Tags