KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > 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.clientproject.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.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29 import java.util.TreeSet JavaDoc;
30 import javax.swing.DefaultComboBoxModel JavaDoc;
31 import javax.swing.event.DocumentListener JavaDoc;
32 import javax.swing.event.DocumentEvent JavaDoc;
33 import org.netbeans.api.project.Project;
34 import org.netbeans.api.project.ProjectInformation;
35 import org.netbeans.api.project.ProjectUtils;
36 import org.netbeans.api.project.ui.OpenProjects;
37 import org.netbeans.modules.j2ee.clientproject.ui.FoldersListSettings;
38 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
39 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
40 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModuleContainer;
41 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
42 import org.netbeans.modules.j2ee.deployment.devmodules.api.ServerManager;
43 import org.openide.WizardDescriptor;
44 import org.openide.WizardValidationException;
45 import org.openide.util.NbBundle;
46 import org.openide.util.Utilities;
47
48 /**
49  * @author phrebejk
50  */

51 public class PanelOptionsVisual extends SettingsPanel implements PropertyChangeListener JavaDoc {
52     
53     private final PanelConfigureProject panel;
54     private boolean valid;
55     
56     private List JavaDoc<Project> earProjects;
57     private final DefaultComboBoxModel JavaDoc serversModel = new DefaultComboBoxModel JavaDoc();
58     private J2eeVersionWarningPanel warningPanel;
59     
60     private static final String JavaDoc J2EE_SPEC_15_LABEL = NbBundle.getMessage(PanelOptionsVisual.class, "J2EESpecLevel_15");
61     private static final String JavaDoc J2EE_SPEC_14_LABEL = NbBundle.getMessage(PanelOptionsVisual.class, "J2EESpecLevel_14");
62     
63     /** Creates new form PanelOptionsVisual */
64     public PanelOptionsVisual( PanelConfigureProject panel ) {
65         initComponents();
66         setJ2eeVersionWarningPanel();
67         initEnterpriseApplications();
68         this.panel = panel;
69         initServers(FoldersListSettings.getDefault().getLastUsedServer());
70         // preselect the first item in the j2ee spec combo
71
if (j2eeSpecComboBox.getModel().getSize() > 0) {
72             j2eeSpecComboBox.setSelectedIndex(0);
73         }
74         this.mainClassTextField.getDocument().addDocumentListener( new DocumentListener JavaDoc() {
75             
76             public void insertUpdate(DocumentEvent JavaDoc e) {
77                 mainClassChanged();
78             }
79             
80             public void removeUpdate(DocumentEvent JavaDoc e) {
81                 mainClassChanged();
82             }
83             
84             public void changedUpdate(DocumentEvent JavaDoc e) {
85                 mainClassChanged();
86             }
87             
88         });
89     }
90     
91     public void propertyChange(PropertyChangeEvent JavaDoc event) {
92         if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event.getPropertyName())) {
93             String JavaDoc newProjectName = NewAppClientProjectWizardIterator.getPackageName((String JavaDoc) event.getNewValue());
94             if (!Utilities.isJavaIdentifier(newProjectName)) {
95                 newProjectName = NbBundle.getMessage(PanelOptionsVisual.class, "TXT_PackageNameSuffix", newProjectName);
96             }
97             this.mainClassTextField.setText(MessageFormat.format(
98                     NbBundle.getMessage(PanelOptionsVisual.class,"TXT_ClassName"), new Object JavaDoc[] {newProjectName}
99             ));
100         }
101     }
102     
103     /** This method is called from within the constructor to
104      * initialize the form.
105      * WARNING: Do NOT modify this code. The content of this method is
106      * always regenerated by the Form Editor.
107      */

108     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
109
private void initComponents() {
110         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
111
112         setAsMainCheckBox = new javax.swing.JCheckBox JavaDoc();
113         mainClassTextField = new javax.swing.JTextField JavaDoc();
114         addToAppLabel = new javax.swing.JLabel JavaDoc();
115         serverInstanceLabel = new javax.swing.JLabel JavaDoc();
116         serverInstanceComboBox = new javax.swing.JComboBox JavaDoc();
117         addToAppComboBox = new javax.swing.JComboBox JavaDoc();
118         j2eeSpecComboBox = new javax.swing.JComboBox JavaDoc();
119         j2eeSpecLabel = new javax.swing.JLabel JavaDoc();
120         warningPlaceHolderPanel = new javax.swing.JPanel JavaDoc();
121         mainClassLabel = new javax.swing.JLabel JavaDoc();
122         manageServersButton = new javax.swing.JButton JavaDoc();
123
124         setLayout(new java.awt.GridBagLayout JavaDoc());
125
126         setAsMainCheckBox.setSelected(true);
127         org.openide.awt.Mnemonics.setLocalizedText(setAsMainCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_setAsMainCheckBox")); // NOI18N
128
setAsMainCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
129         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
130         gridBagConstraints.gridx = 0;
131         gridBagConstraints.gridy = 5;
132         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
133         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
134         gridBagConstraints.weightx = 1.0;
135         gridBagConstraints.weighty = 1.0;
136         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
137         add(setAsMainCheckBox, gridBagConstraints);
138         setAsMainCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_setAsMainCheckBox")); // NOI18N
139
setAsMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSD_setAsMainCheckBox")); // NOI18N
140

141         mainClassTextField.setText("com.myapp.Main");
142         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
143         gridBagConstraints.gridx = 1;
144         gridBagConstraints.gridy = 3;
145         gridBagConstraints.gridwidth = 2;
146         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
147         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
148         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
149         add(mainClassTextField, gridBagConstraints);
150         mainClassTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCN_mainClassTextField")); // NOI18N
151
mainClassTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCD_mainClassTextField")); // NOI18N
152

153         addToAppLabel.setLabelFor(addToAppComboBox);
154         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/clientproject/ui/wizards/Bundle"); // NOI18N
155
org.openide.awt.Mnemonics.setLocalizedText(addToAppLabel, bundle.getString("LBL_NWP1_AddToEApp_CheckBox")); // NOI18N
156
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
157         gridBagConstraints.gridx = 0;
158         gridBagConstraints.gridy = 0;
159         gridBagConstraints.gridwidth = 2;
160         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
161         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
162         add(addToAppLabel, gridBagConstraints);
163
164         serverInstanceLabel.setLabelFor(serverInstanceComboBox);
165         org.openide.awt.Mnemonics.setLocalizedText(serverInstanceLabel, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_NWP1_Server_Label")); // NOI18N
166
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
167         gridBagConstraints.gridx = 0;
168         gridBagConstraints.gridy = 1;
169         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
170         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
171         add(serverInstanceLabel, gridBagConstraints);
172
173         serverInstanceComboBox.setModel(serversModel);
174         serverInstanceComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
175             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
176                 serverInstanceComboBoxActionPerformed(evt);
177             }
178         });
179         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
180         gridBagConstraints.gridx = 1;
181         gridBagConstraints.gridy = 1;
182         gridBagConstraints.gridwidth = 2;
183         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
184         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
185         gridBagConstraints.weightx = 1.0;
186         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
187         add(serverInstanceComboBox, gridBagConstraints);
188         serverInstanceComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_IW_SelectServerInstance_A11YDesc")); // NOI18N
189

190         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
191         gridBagConstraints.gridx = 2;
192         gridBagConstraints.gridy = 0;
193         gridBagConstraints.gridwidth = 2;
194         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
195         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
196         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
197         add(addToAppComboBox, gridBagConstraints);
198
199         j2eeSpecComboBox.setPrototypeDisplayValue("MMMMMMMMM" /* "Java EE 5" */);
200         j2eeSpecComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
201             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
202                 j2eeSpecComboBoxActionPerformed(evt);
203             }
204         });
205         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
206         gridBagConstraints.gridx = 1;
207         gridBagConstraints.gridy = 2;
208         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
209         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
210         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
211         add(j2eeSpecComboBox, gridBagConstraints);
212         j2eeSpecComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACS_LBL_IW_SelectJ2EEVersion_A11YDesc")); // NOI18N
213

214         j2eeSpecLabel.setLabelFor(j2eeSpecComboBox);
215         org.openide.awt.Mnemonics.setLocalizedText(j2eeSpecLabel, NbBundle.getBundle("org/netbeans/modules/j2ee/clientproject/ui/wizards/Bundle").getString("LBL_NWP1_J2EESpecLevel_Label")); // NOI18N
216
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
217         gridBagConstraints.gridx = 0;
218         gridBagConstraints.gridy = 2;
219         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
220         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
221         add(j2eeSpecLabel, gridBagConstraints);
222
223         warningPlaceHolderPanel.setLayout(new java.awt.BorderLayout JavaDoc());
224         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
225         gridBagConstraints.gridx = 0;
226         gridBagConstraints.gridy = 4;
227         gridBagConstraints.gridwidth = 3;
228         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
229         gridBagConstraints.weightx = 1.0;
230         add(warningPlaceHolderPanel, gridBagConstraints);
231
232         mainClassLabel.setLabelFor(mainClassTextField);
233         org.openide.awt.Mnemonics.setLocalizedText(mainClassLabel, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_NWP1_MainClass_Label")); // NOI18N
234
mainClassLabel.setAlignmentX(0.5F);
235         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
236         gridBagConstraints.gridx = 0;
237         gridBagConstraints.gridy = 3;
238         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
239         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
240         add(mainClassLabel, gridBagConstraints);
241
242         org.openide.awt.Mnemonics.setLocalizedText(manageServersButton, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "LBL_ManageServers")); // NOI18N
243
manageServersButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
244             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
245                 manageServersButtonActionPerformed(evt);
246             }
247         });
248         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
249         gridBagConstraints.gridx = 3;
250         gridBagConstraints.gridy = 1;
251         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 11, 0);
252         add(manageServersButton, gridBagConstraints);
253         manageServersButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ASCN_ManageServers")); // NOI18N
254
manageServersButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ASCD_ManageServers")); // NOI18N
255

256         getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSN_PanelOptionsVisual")); // NOI18N
257
getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_PanelOptionsVisual")); // NOI18N
258
}// </editor-fold>//GEN-END:initComponents
259

260     private void manageServersButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_manageServersButtonActionPerformed
261
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
262         String JavaDoc lastSelectedServerInstanceID = null;
263         if (serverInstanceWrapper != null) {
264             lastSelectedServerInstanceID = serverInstanceWrapper.getServerInstanceID();
265         }
266         ServerManager.showCustomizer(lastSelectedServerInstanceID);
267         String JavaDoc lastSelectedJ2eeSpecLevel = (String JavaDoc) j2eeSpecComboBox.getSelectedItem();
268         // refresh the list of servers
269
initServers(lastSelectedServerInstanceID);
270         if (lastSelectedJ2eeSpecLevel != null) {
271             j2eeSpecComboBox.setSelectedItem(lastSelectedJ2eeSpecLevel);
272         }
273     }//GEN-LAST:event_manageServersButtonActionPerformed
274

275     private void serverInstanceComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_serverInstanceComboBoxActionPerformed
276
String JavaDoc prevSelectedItem = (String JavaDoc) j2eeSpecComboBox.getSelectedItem();
277         // update the j2ee spec list according to the selected server
278
ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel.getSelectedItem();
279         if (serverInstanceWrapper != null) {
280             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceWrapper.getServerInstanceID());
281             Set JavaDoc supportedVersions = j2eePlatform.getSupportedSpecVersions(J2eeModule.CLIENT);
282             j2eeSpecComboBox.removeAllItems();
283             if (supportedVersions.contains(J2eeModule.JAVA_EE_5)) {
284                 j2eeSpecComboBox.addItem(J2EE_SPEC_15_LABEL);
285             }
286             if (supportedVersions.contains(J2eeModule.J2EE_14)) {
287                 j2eeSpecComboBox.addItem(J2EE_SPEC_14_LABEL);
288             }
289             if (prevSelectedItem != null) {
290                 j2eeSpecComboBox.setSelectedItem(prevSelectedItem);
291             }
292         } else {
293             j2eeSpecComboBox.removeAllItems();
294         }
295         // revalidate the form
296
panel.fireChangeEvent();
297     }//GEN-LAST:event_serverInstanceComboBoxActionPerformed
298

299     private void j2eeSpecComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_j2eeSpecComboBoxActionPerformed
300
setJ2eeVersionWarningPanel();
301     }//GEN-LAST:event_j2eeSpecComboBoxActionPerformed
302

303     boolean valid(WizardDescriptor settings) {
304         if (getSelectedServer() == null) {
305             String JavaDoc errMsg = NbBundle.getMessage(PanelOptionsVisual.class, "MSG_NoServer");
306             settings.putProperty( "WizardPanel_errorMessage", errMsg); // NOI18N
307
return false;
308         }
309         
310         if (!valid) {
311             settings.putProperty( "WizardPanel_errorMessage", // NOI18N
312
NbBundle.getMessage(PanelOptionsVisual.class,"ERROR_IllegalMainClassName"));
313             return this.valid;
314         }
315         return true;
316     }
317     
318     void read(WizardDescriptor d) {
319         //TODO:
320
}
321     
322     void validate(WizardDescriptor d) throws WizardValidationException {
323         // nothing to validate
324
}
325     
326     void store( WizardDescriptor d ) {
327         d.putProperty(WizardProperties.MAIN_CLASS, mainClassTextField.getText().trim());
328         d.putProperty(WizardProperties.SET_AS_MAIN, setAsMainCheckBox.isSelected() ? Boolean.TRUE : Boolean.FALSE );
329         d.putProperty(WizardProperties.SERVER_INSTANCE_ID, getSelectedServer());
330         d.putProperty(WizardProperties.J2EE_LEVEL, getSelectedJ2eeSpec());
331         d.putProperty(WizardProperties.EAR_APPLICATION, getSelectedEarApplication());
332         if (warningPanel != null && warningPanel.getWarningType() != null && warningPanel.getDowngradeAllowed()) {
333             d.putProperty(WizardProperties.JAVA_PLATFORM, warningPanel.getSuggestedJavaPlatformName());
334             String JavaDoc j2ee = getSelectedJ2eeSpec();
335             if (j2ee != null) {
336                 String JavaDoc warningType = J2eeVersionWarningPanel.findWarningType(j2ee);
337                 FoldersListSettings fls = FoldersListSettings.getDefault();
338                 String JavaDoc srcLevel = "1.6"; // NOI18N
339
if ((warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_14)
340                         || warningType.equals(J2eeVersionWarningPanel.WARN_SET_JDK_14))
341                         && fls.isAgreedSetSourceLevel14()) {
342                     srcLevel = "1.4"; // NOI18N
343
} else if ((warningType.equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_15)
344                         || warningType.equals(J2eeVersionWarningPanel.WARN_SET_JDK_15))
345                         && fls.isAgreedSetSourceLevel15()) {
346                     srcLevel = "1.5"; // NOI18N
347
}
348                 d.putProperty(WizardProperties.SOURCE_LEVEL, srcLevel);
349             }
350         } else {
351             d.putProperty(WizardProperties.SOURCE_LEVEL, null);
352         }
353     }
354     
355     // Variables declaration - do not modify//GEN-BEGIN:variables
356
private javax.swing.JComboBox JavaDoc addToAppComboBox;
357     private javax.swing.JLabel JavaDoc addToAppLabel;
358     private javax.swing.JComboBox JavaDoc j2eeSpecComboBox;
359     private javax.swing.JLabel JavaDoc j2eeSpecLabel;
360     private javax.swing.JLabel JavaDoc mainClassLabel;
361     private javax.swing.JTextField JavaDoc mainClassTextField;
362     private javax.swing.JButton JavaDoc manageServersButton;
363     private javax.swing.JComboBox JavaDoc serverInstanceComboBox;
364     private javax.swing.JLabel JavaDoc serverInstanceLabel;
365     private javax.swing.JCheckBox JavaDoc setAsMainCheckBox;
366     private javax.swing.JPanel JavaDoc warningPlaceHolderPanel;
367     // End of variables declaration//GEN-END:variables
368

369     private void mainClassChanged() {
370         String JavaDoc mainClassName = this.mainClassTextField.getText().trim();
371         StringTokenizer JavaDoc tk = new StringTokenizer JavaDoc(mainClassName, "."); //NOI18N
372
boolean valid = tk.countTokens() > 0;
373         while (tk.hasMoreTokens()) {
374             String JavaDoc token = tk.nextToken();
375             if (token.length() == 0 || !Utilities.isJavaIdentifier(token)) {
376                 valid = false;
377                 break;
378             }
379         }
380         this.valid = valid;
381         this.panel.fireChangeEvent();
382     }
383     
384     private void setJ2eeVersionWarningPanel() {
385         String JavaDoc j2ee = getSelectedJ2eeSpec();
386         if (j2ee == null) {
387             return;
388         }
389         String JavaDoc warningType = J2eeVersionWarningPanel.findWarningType(j2ee);
390         if (warningType == null && warningPanel == null) {
391             return;
392         }
393         if (warningPanel == null) {
394             warningPanel = new J2eeVersionWarningPanel(warningType);
395             warningPlaceHolderPanel.add(warningPanel, java.awt.BorderLayout.CENTER);
396         }
397         warningPanel.setWarningType(warningType);
398     }
399     
400     /**
401      * Initializes servers model.
402      * @param selectedServerInstanceID preselected instance or null if non is preselected
403      */

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

492     private static class ServerInstanceWrapper implements Comparable JavaDoc {
493
494         private final String JavaDoc serverInstanceID;
495         private final String JavaDoc displayName;
496
497         ServerInstanceWrapper(String JavaDoc serverInstanceID, String JavaDoc displayName) {
498             this.serverInstanceID = serverInstanceID;
499             this.displayName = displayName;
500         }
501
502         public String JavaDoc getServerInstanceID() {
503             return serverInstanceID;
504         }
505
506         public String JavaDoc toString() {
507             return displayName;
508         }
509
510         public int compareTo(Object JavaDoc o) {
511             return toString().compareTo(o.toString());
512         }
513     }
514 }
515
516
Popular Tags