001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.j2ee.earproject.ui.wizards;
043:
044: import java.beans.PropertyChangeEvent;
045: import java.beans.PropertyChangeListener;
046: import java.text.MessageFormat;
047: import java.util.Set;
048: import java.util.StringTokenizer;
049: import java.util.TreeSet;
050: import javax.swing.DefaultComboBoxModel;
051: import javax.swing.JPanel;
052: import javax.swing.event.DocumentEvent;
053: import javax.swing.event.DocumentListener;
054: import org.netbeans.modules.j2ee.common.project.ui.UserProjectSettings;
055: import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
056: import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
057: import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
058: import org.netbeans.modules.j2ee.deployment.devmodules.api.ServerManager;
059: import org.netbeans.modules.j2ee.earproject.ui.customizer.EarProjectProperties;
060: import org.openide.WizardDescriptor;
061: import org.openide.util.NbBundle;
062: import org.openide.util.Utilities;
063:
064: public class PanelOptionsVisual extends JPanel implements
065: PropertyChangeListener {
066: private static final long serialVersionUID = 1L;
067:
068: private final PanelConfigureProject panel;
069: private final DefaultComboBoxModel serversModel = new DefaultComboBoxModel();
070: private J2eeVersionWarningPanel warningPanel;
071: private boolean valid;
072:
073: /** Creates new form PanelOptionsVisual */
074: public PanelOptionsVisual(PanelConfigureProject panel,
075: boolean importStyle) {
076: panel.getProjectTypeFlag();
077: initComponents();
078: this .panel = panel;
079: setJ2eeVersionWarningPanel();
080: initServers(UserProjectSettings.getDefault()
081: .getLastUsedServer());
082: // preselect the first item in the j2ee spec combo
083: if (j2eeSpecComboBox.getModel().getSize() > 0) {
084: j2eeSpecComboBox.setSelectedIndex(0);
085: }
086: // if this panel is used during import there are lots of things we don't
087: // need to ask about -- hide them from the user.
088: if (importStyle) {
089: createEjbCheckBox.setSelected(!importStyle);
090: createWARCheckBox.setSelected(!importStyle);
091: createCarCheckBox.setSelected(!importStyle);
092: createEjbCheckBox.setVisible(!importStyle);
093: createWARCheckBox.setVisible(!importStyle);
094: createCarCheckBox.setVisible(!importStyle);
095: jTextFieldEjbModuleName.setVisible(!importStyle);
096: jTextFieldWebAppName.setVisible(!importStyle);
097: jTextFieldCarName.setVisible(!importStyle);
098: mainClassLabel.setVisible(!importStyle);
099: mainClassTextField.setVisible(!importStyle);
100: } else {
101: DocumentListener subProjectNameListener = new DocumentListener() {
102: public void insertUpdate(DocumentEvent e) {
103: projectNameChanged();
104: }
105:
106: public void removeUpdate(DocumentEvent e) {
107: projectNameChanged();
108: }
109:
110: public void changedUpdate(DocumentEvent e) {
111: projectNameChanged();
112: }
113: };
114: jTextFieldEjbModuleName.getDocument().addDocumentListener(
115: subProjectNameListener);
116: jTextFieldWebAppName.getDocument().addDocumentListener(
117: subProjectNameListener);
118: jTextFieldCarName.getDocument().addDocumentListener(
119: subProjectNameListener);
120: this .mainClassTextField.getDocument().addDocumentListener(
121: new DocumentListener() {
122: public void insertUpdate(DocumentEvent e) {
123: mainClassChanged();
124: }
125:
126: public void removeUpdate(DocumentEvent e) {
127: mainClassChanged();
128: }
129:
130: public void changedUpdate(DocumentEvent e) {
131: mainClassChanged();
132: }
133:
134: });
135: }
136: //j2eeSpecComboBox.setVisible(!importStyle);
137: //j2eeSpecLabel.setVisible(!importStyle);
138: }
139:
140: /** This method is called from within the constructor to
141: * initialize the form.
142: * WARNING: Do NOT modify this code. The content of this method is
143: * always regenerated by the Form Editor.
144: */
145: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
146: private void initComponents() {
147: java.awt.GridBagConstraints gridBagConstraints;
148:
149: setAsMainCheckBox = new javax.swing.JCheckBox();
150: createEjbCheckBox = new javax.swing.JCheckBox();
151: jTextFieldEjbModuleName = new javax.swing.JTextField();
152: createWARCheckBox = new javax.swing.JCheckBox();
153: jTextFieldWebAppName = new javax.swing.JTextField();
154: warningPlaceHolderPanel = new javax.swing.JPanel();
155: createCarCheckBox = new javax.swing.JCheckBox();
156: jTextFieldCarName = new javax.swing.JTextField();
157: mainClassLabel = new javax.swing.JLabel();
158: mainClassTextField = new javax.swing.JTextField();
159: serverAndVersionPanel = new javax.swing.JPanel();
160: serverInstanceLabel = new javax.swing.JLabel();
161: serverInstanceComboBox = new javax.swing.JComboBox();
162: addServerButton = new javax.swing.JButton();
163: j2eeSpecLabel = new javax.swing.JLabel();
164: j2eeSpecComboBox = new javax.swing.JComboBox();
165:
166: setLayout(new java.awt.GridBagLayout());
167:
168: setAsMainCheckBox.setMnemonic(org.openide.util.NbBundle
169: .getMessage(PanelOptionsVisual.class,
170: "LBL_NWP1_SetAsMain_CheckBoxMnemonic")
171: .charAt(0));
172: setAsMainCheckBox.setSelected(true);
173: setAsMainCheckBox.setText(org.openide.util.NbBundle
174: .getMessage(PanelOptionsVisual.class,
175: "LBL_NWP1_SetAsMain_CheckBox")); // NOI18N
176: gridBagConstraints = new java.awt.GridBagConstraints();
177: gridBagConstraints.gridx = 0;
178: gridBagConstraints.gridy = 6;
179: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
180: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
181: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
182: gridBagConstraints.weighty = 1.0;
183: gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
184: add(setAsMainCheckBox, gridBagConstraints);
185: setAsMainCheckBox.getAccessibleContext()
186: .setAccessibleDescription(
187: org.openide.util.NbBundle.getMessage(
188: PanelOptionsVisual.class,
189: "ACS_LBL_NWP1_SetAsMain_A11YDesc")); // NOI18N
190:
191: createEjbCheckBox.setSelected(true);
192: org.openide.awt.Mnemonics.setLocalizedText(createEjbCheckBox,
193: org.openide.util.NbBundle.getBundle(
194: PanelOptionsVisual.class).getString(
195: "LBL_NEAP_CreateEjbModule")); // NOI18N
196: createEjbCheckBox
197: .addActionListener(new java.awt.event.ActionListener() {
198: public void actionPerformed(
199: java.awt.event.ActionEvent evt) {
200: createEjbCheckBox_action(evt);
201: }
202: });
203: gridBagConstraints = new java.awt.GridBagConstraints();
204: gridBagConstraints.gridx = 0;
205: gridBagConstraints.gridy = 1;
206: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
207: gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 11);
208: add(createEjbCheckBox, gridBagConstraints);
209: createEjbCheckBox.getAccessibleContext()
210: .setAccessibleDescription(
211: org.openide.util.NbBundle.getMessage(
212: PanelOptionsVisual.class,
213: "ACSD_CreateEJBModule")); // NOI18N
214:
215: gridBagConstraints = new java.awt.GridBagConstraints();
216: gridBagConstraints.gridx = 1;
217: gridBagConstraints.gridy = 1;
218: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
219: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
220: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
221: gridBagConstraints.weightx = 1.0;
222: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
223: add(jTextFieldEjbModuleName, gridBagConstraints);
224: jTextFieldEjbModuleName.getAccessibleContext()
225: .setAccessibleName(
226: org.openide.util.NbBundle.getBundle(
227: PanelOptionsVisual.class).getString(
228: "ACSN_EjbModuleName")); // NOI18N
229: jTextFieldEjbModuleName.getAccessibleContext()
230: .setAccessibleDescription(
231: org.openide.util.NbBundle.getMessage(
232: PanelOptionsVisual.class,
233: "ACSD_EjbModuleName")); // NOI18N
234:
235: createWARCheckBox.setSelected(true);
236: org.openide.awt.Mnemonics.setLocalizedText(createWARCheckBox,
237: org.openide.util.NbBundle.getBundle(
238: PanelOptionsVisual.class).getString(
239: "LBL_NEAP_CreatWebAppModule")); // NOI18N
240: createWARCheckBox
241: .addActionListener(new java.awt.event.ActionListener() {
242: public void actionPerformed(
243: java.awt.event.ActionEvent evt) {
244: createWebAppCheckBox_action(evt);
245: }
246: });
247: gridBagConstraints = new java.awt.GridBagConstraints();
248: gridBagConstraints.gridx = 0;
249: gridBagConstraints.gridy = 2;
250: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
251: gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 11);
252: add(createWARCheckBox, gridBagConstraints);
253: createWARCheckBox.getAccessibleContext()
254: .setAccessibleDescription(
255: org.openide.util.NbBundle.getMessage(
256: PanelOptionsVisual.class,
257: "ACSD_CreateWebModule")); // NOI18N
258:
259: gridBagConstraints = new java.awt.GridBagConstraints();
260: gridBagConstraints.gridx = 1;
261: gridBagConstraints.gridy = 2;
262: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
263: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
264: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
265: gridBagConstraints.weightx = 1.0;
266: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
267: add(jTextFieldWebAppName, gridBagConstraints);
268: jTextFieldWebAppName.getAccessibleContext().setAccessibleName(
269: org.openide.util.NbBundle.getMessage(
270: PanelOptionsVisual.class, "ACSN_WebAppName")); // NOI18N
271: jTextFieldWebAppName.getAccessibleContext()
272: .setAccessibleDescription(
273: org.openide.util.NbBundle.getMessage(
274: PanelOptionsVisual.class,
275: "ACSD_WebAppName")); // NOI18N
276:
277: warningPlaceHolderPanel.setLayout(new java.awt.BorderLayout());
278: gridBagConstraints = new java.awt.GridBagConstraints();
279: gridBagConstraints.gridx = 0;
280: gridBagConstraints.gridy = 5;
281: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
282: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
283: gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
284: add(warningPlaceHolderPanel, gridBagConstraints);
285:
286: org.openide.awt.Mnemonics.setLocalizedText(createCarCheckBox,
287: org.openide.util.NbBundle.getBundle(
288: PanelOptionsVisual.class).getString(
289: "LBL_NEAP_CreateCarModule")); // NOI18N
290: createCarCheckBox
291: .addActionListener(new java.awt.event.ActionListener() {
292: public void actionPerformed(
293: java.awt.event.ActionEvent evt) {
294: createCarCheckBox_action(evt);
295: }
296: });
297: gridBagConstraints = new java.awt.GridBagConstraints();
298: gridBagConstraints.gridx = 0;
299: gridBagConstraints.gridy = 3;
300: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
301: gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 11);
302: add(createCarCheckBox, gridBagConstraints);
303: createCarCheckBox.getAccessibleContext()
304: .setAccessibleDescription(
305: org.openide.util.NbBundle.getMessage(
306: PanelOptionsVisual.class,
307: "ACSD_CreateAppClientModule")); // NOI18N
308:
309: jTextFieldCarName.setEnabled(false);
310: gridBagConstraints = new java.awt.GridBagConstraints();
311: gridBagConstraints.gridx = 1;
312: gridBagConstraints.gridy = 3;
313: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
314: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
315: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
316: gridBagConstraints.weightx = 1.0;
317: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
318: add(jTextFieldCarName, gridBagConstraints);
319: jTextFieldCarName.getAccessibleContext()
320: .setAccessibleName(
321: org.openide.util.NbBundle.getMessage(
322: PanelOptionsVisual.class,
323: "ACSN_AppClientName")); // NOI18N
324: jTextFieldCarName.getAccessibleContext()
325: .setAccessibleDescription(
326: org.openide.util.NbBundle.getMessage(
327: PanelOptionsVisual.class,
328: "ACSD_AppClientName")); // NOI18N
329:
330: mainClassLabel.setLabelFor(mainClassTextField);
331: org.openide.awt.Mnemonics.setLocalizedText(mainClassLabel,
332: org.openide.util.NbBundle.getBundle(
333: PanelOptionsVisual.class).getString(
334: "LBL_NWP1_MainClass_Label")); // NOI18N
335: gridBagConstraints = new java.awt.GridBagConstraints();
336: gridBagConstraints.gridx = 0;
337: gridBagConstraints.gridy = 4;
338: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
339: gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 11);
340: add(mainClassLabel, gridBagConstraints);
341:
342: mainClassTextField.setEnabled(false);
343: gridBagConstraints = new java.awt.GridBagConstraints();
344: gridBagConstraints.gridx = 1;
345: gridBagConstraints.gridy = 4;
346: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
347: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
348: gridBagConstraints.weightx = 1.0;
349: gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 5);
350: add(mainClassTextField, gridBagConstraints);
351: mainClassTextField.getAccessibleContext().setAccessibleName(
352: org.openide.util.NbBundle.getBundle(
353: PanelOptionsVisual.class).getString(
354: "ASCN_mainClassTextFiled")); // NOI18N
355: mainClassTextField.getAccessibleContext()
356: .setAccessibleDescription(
357: org.openide.util.NbBundle.getBundle(
358: PanelOptionsVisual.class).getString(
359: "ASCD_mainClassTextFiled")); // NOI18N
360:
361: serverAndVersionPanel.setLayout(new java.awt.GridBagLayout());
362:
363: serverInstanceLabel.setLabelFor(serverInstanceComboBox);
364: org.openide.awt.Mnemonics.setLocalizedText(serverInstanceLabel,
365: org.openide.util.NbBundle.getMessage(
366: PanelOptionsVisual.class,
367: "LBL_NWP1_Server_Label")); // NOI18N
368: gridBagConstraints = new java.awt.GridBagConstraints();
369: gridBagConstraints.gridx = 0;
370: gridBagConstraints.gridy = 0;
371: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
372: gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 11);
373: serverAndVersionPanel.add(serverInstanceLabel,
374: gridBagConstraints);
375:
376: serverInstanceComboBox.setModel(serversModel);
377: serverInstanceComboBox
378: .setPrototypeDisplayValue("The Gr8est Marvelous Nr. 1 Server");
379: serverInstanceComboBox
380: .addActionListener(new java.awt.event.ActionListener() {
381: public void actionPerformed(
382: java.awt.event.ActionEvent evt) {
383: serverInstanceComboBoxActionPerformed(evt);
384: }
385: });
386: gridBagConstraints = new java.awt.GridBagConstraints();
387: gridBagConstraints.gridx = 1;
388: gridBagConstraints.gridy = 0;
389: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
390: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
391: gridBagConstraints.weightx = 1.0;
392: gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 6);
393: serverAndVersionPanel.add(serverInstanceComboBox,
394: gridBagConstraints);
395: serverInstanceComboBox.getAccessibleContext()
396: .setAccessibleDescription(
397: org.openide.util.NbBundle.getMessage(
398: PanelOptionsVisual.class,
399: "ACS_NWP1_Server_ComboBox_A11YDesc")); // NOI18N
400:
401: org.openide.awt.Mnemonics.setLocalizedText(addServerButton,
402: org.openide.util.NbBundle.getMessage(
403: PanelOptionsVisual.class, "LBL_AddServer")); // NOI18N
404: addServerButton
405: .addActionListener(new java.awt.event.ActionListener() {
406: public void actionPerformed(
407: java.awt.event.ActionEvent evt) {
408: addServerButtonActionPerformed(evt);
409: }
410: });
411: gridBagConstraints = new java.awt.GridBagConstraints();
412: gridBagConstraints.gridx = 2;
413: gridBagConstraints.gridy = 0;
414: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
415: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
416: gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 5);
417: serverAndVersionPanel.add(addServerButton, gridBagConstraints);
418: addServerButton.getAccessibleContext().setAccessibleName(
419: "Add Server");
420: addServerButton.getAccessibleContext()
421: .setAccessibleDescription(
422: org.openide.util.NbBundle.getMessage(
423: PanelOptionsVisual.class,
424: "ACSD_ManageButton")); // NOI18N
425:
426: j2eeSpecLabel.setLabelFor(j2eeSpecComboBox);
427: org.openide.awt.Mnemonics.setLocalizedText(j2eeSpecLabel,
428: org.openide.util.NbBundle.getMessage(
429: PanelOptionsVisual.class,
430: "LBL_NWP1_J2EESpecLevel_Label")); // NOI18N
431: gridBagConstraints = new java.awt.GridBagConstraints();
432: gridBagConstraints.gridx = 0;
433: gridBagConstraints.gridy = 1;
434: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
435: gridBagConstraints.insets = new java.awt.Insets(0, 5, 11, 11);
436: serverAndVersionPanel.add(j2eeSpecLabel, gridBagConstraints);
437:
438: j2eeSpecComboBox
439: .setPrototypeDisplayValue("MMMMMMMMM" /* "Java EE 5" */);
440: j2eeSpecComboBox
441: .addActionListener(new java.awt.event.ActionListener() {
442: public void actionPerformed(
443: java.awt.event.ActionEvent evt) {
444: j2eeSpecComboBoxActionPerformed(evt);
445: }
446: });
447: gridBagConstraints = new java.awt.GridBagConstraints();
448: gridBagConstraints.gridx = 1;
449: gridBagConstraints.gridy = 1;
450: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
451: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
452: gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 5);
453: serverAndVersionPanel.add(j2eeSpecComboBox, gridBagConstraints);
454: j2eeSpecComboBox.getAccessibleContext()
455: .setAccessibleDescription(
456: org.openide.util.NbBundle.getMessage(
457: PanelOptionsVisual.class,
458: "ACS_LBL_NPW1_J2EESpecLevel_A11YDesc")); // NOI18N
459:
460: gridBagConstraints = new java.awt.GridBagConstraints();
461: gridBagConstraints.gridx = 0;
462: gridBagConstraints.gridy = 0;
463: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
464: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
465: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
466: gridBagConstraints.weightx = 1.0;
467: add(serverAndVersionPanel, gridBagConstraints);
468:
469: getAccessibleContext()
470: .setAccessibleName(
471: org.openide.util.NbBundle.getMessage(
472: PanelOptionsVisual.class,
473: "ASCN_ManageServers")); // NOI18N
474: getAccessibleContext()
475: .setAccessibleDescription(
476: org.openide.util.NbBundle.getMessage(
477: PanelOptionsVisual.class,
478: "ASCD_ManageServers")); // NOI18N
479: }// </editor-fold>//GEN-END:initComponents
480:
481: private void addServerButtonActionPerformed(
482: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addServerButtonActionPerformed
483: ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel
484: .getSelectedItem();
485: String selectedServerInstanceID = null;
486: if (serverInstanceWrapper != null) {
487: selectedServerInstanceID = serverInstanceWrapper
488: .getServerInstanceID();
489: }
490: String lastSelectedJ2eeSpecLevel = (String) j2eeSpecComboBox
491: .getSelectedItem();
492: String newServerInstanceID = ServerManager
493: .showAddServerInstanceWizard();
494: if (newServerInstanceID != null) {
495: selectedServerInstanceID = newServerInstanceID;
496: // clear the spec level selection
497: lastSelectedJ2eeSpecLevel = null;
498: j2eeSpecComboBox.setSelectedItem(null);
499: }
500: // refresh the list of servers
501: initServers(selectedServerInstanceID);
502: if (lastSelectedJ2eeSpecLevel != null) {
503: j2eeSpecComboBox.setSelectedItem(lastSelectedJ2eeSpecLevel);
504: }
505: }//GEN-LAST:event_addServerButtonActionPerformed
506:
507: private void createCarCheckBox_action(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createCarCheckBox_action
508: jTextFieldCarName.setEnabled(createCarCheckBox.isSelected());
509: mainClassTextField.setEnabled(createCarCheckBox.isSelected());
510: this .panel.fireChangeEvent();
511: }//GEN-LAST:event_createCarCheckBox_action
512:
513: private void createWebAppCheckBox_action(
514: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createWebAppCheckBox_action
515: jTextFieldWebAppName.setEnabled(createWARCheckBox.isSelected());
516: this .panel.fireChangeEvent();
517: }//GEN-LAST:event_createWebAppCheckBox_action
518:
519: private void createEjbCheckBox_action(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createEjbCheckBox_action
520: jTextFieldEjbModuleName.setEnabled(createEjbCheckBox
521: .isSelected());
522: this .panel.fireChangeEvent();
523: }//GEN-LAST:event_createEjbCheckBox_action
524:
525: private void serverInstanceComboBoxActionPerformed(
526: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_serverInstanceComboBoxActionPerformed
527: String prevSelectedItem = (String) j2eeSpecComboBox
528: .getSelectedItem();
529: // update the j2ee spec list according to the selected server
530: ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel
531: .getSelectedItem();
532: if (serverInstanceWrapper != null) {
533: J2eePlatform j2eePlatform = Deployment
534: .getDefault()
535: .getJ2eePlatform(
536: serverInstanceWrapper.getServerInstanceID());
537: Set supportedVersions = j2eePlatform
538: .getSupportedSpecVersions(J2eeModule.EAR);
539: j2eeSpecComboBox.removeAllItems();
540: if (supportedVersions.contains(J2eeModule.JAVA_EE_5)) {
541: j2eeSpecComboBox
542: .addItem(EarProjectProperties.JAVA_EE_SPEC_50_LABEL);
543: }
544: if (supportedVersions.contains(J2eeModule.J2EE_14)) {
545: j2eeSpecComboBox
546: .addItem(EarProjectProperties.J2EE_SPEC_14_LABEL);
547: }
548: if (prevSelectedItem != null) {
549: j2eeSpecComboBox.setSelectedItem(prevSelectedItem);
550: }
551: boolean carSupported = j2eePlatform
552: .getSupportedModuleTypes().contains(
553: J2eeModule.CLIENT);
554: createCarCheckBox.setEnabled(carSupported);
555: jTextFieldCarName.setEnabled(carSupported
556: && createCarCheckBox.isSelected());
557: mainClassLabel.setEnabled(carSupported);
558: mainClassTextField.setEnabled(carSupported
559: && createCarCheckBox.isSelected());
560: } else {
561: j2eeSpecComboBox.removeAllItems();
562: }
563: // revalidate the form
564: panel.fireChangeEvent();
565: }//GEN-LAST:event_serverInstanceComboBoxActionPerformed
566:
567: private void j2eeSpecComboBoxActionPerformed(
568: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_j2eeSpecComboBoxActionPerformed
569: setJ2eeVersionWarningPanel();
570: }//GEN-LAST:event_j2eeSpecComboBoxActionPerformed
571:
572: public void propertyChange(PropertyChangeEvent event) {
573: if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event
574: .getPropertyName())) {
575: String newProjectName = (String) event.getNewValue();
576: if (newProjectName.trim().equals("")) {
577: return;
578: }
579: this .jTextFieldEjbModuleName.setText(MessageFormat.format(
580: NbBundle.getMessage(PanelOptionsVisual.class,
581: "TXT_EJBProjectName"),
582: new Object[] { newProjectName }));
583: this .jTextFieldWebAppName.setText(MessageFormat.format(
584: NbBundle.getMessage(PanelOptionsVisual.class,
585: "TXT_WebAppProjectName"),
586: new Object[] { newProjectName }));
587: this .jTextFieldCarName.setText(MessageFormat.format(
588: NbBundle.getMessage(PanelOptionsVisual.class,
589: "TXT_AppClientProjectName"),
590: new Object[] { newProjectName }));
591: newProjectName = getPackageName(newProjectName);
592: if (!Utilities.isJavaIdentifier(newProjectName)) {
593: newProjectName = NbBundle.getMessage(
594: PanelOptionsVisual.class,
595: "TXT_PackageNameSuffix", newProjectName);
596: }
597: this .mainClassTextField.setText(MessageFormat.format(
598: NbBundle.getMessage(PanelOptionsVisual.class,
599: "TXT_ClassName"),
600: new Object[] { newProjectName }));
601: }
602: }
603:
604: boolean valid(WizardDescriptor wizardDescriptor) {
605: if (getSelectedServer() == null) {
606: setErrorMessage("MSG_NoServer", wizardDescriptor); // NOI18N
607: return false;
608: }
609:
610: if (createWARCheckBox.isSelected()) {
611: String warName = jTextFieldWebAppName.getText();
612: if (warName.length() < 1) {
613: setErrorMessage("MSG_NoWARName", wizardDescriptor); // NOI18N
614: return false;
615: }
616: if (!warName.endsWith("-war")) { // NOI18N
617: // this is really just a warning
618: setErrorMessage("MSG_WARNameNotBlueprints",
619: wizardDescriptor); // NOI18N
620: }
621: }
622:
623: if (createEjbCheckBox.isSelected()) {
624: String jarName = jTextFieldEjbModuleName.getText();
625: if (jarName.length() < 1) {
626: setErrorMessage("MSG_NoJARName", wizardDescriptor); // NOI18N
627: return false;
628: }
629: if (!jarName.endsWith("-ejb")) { //NOI18N
630: // this is really just a warning
631: setErrorMessage("MSG_JARNameNotBlueprints",
632: wizardDescriptor); // NOI18N
633: }
634: }
635:
636: if (createCarCheckBox.isSelected()) {
637: String jarName = jTextFieldCarName.getText();
638: if (jarName.length() < 1) {
639: setErrorMessage("MSG_NoCARName", wizardDescriptor); // NOI18N
640: return false;
641: }
642: if (!valid) {
643: setErrorMessage("ERROR_IllegalMainClassName",
644: wizardDescriptor); // NOI18N
645: return this .valid;
646: }
647: if (!jarName.endsWith("-app-client")) { //NOI18N
648: // this is really just a warning
649: setErrorMessage("MSG_CARNameNotBlueprints",
650: wizardDescriptor); // NOI18N
651: }
652: }
653:
654: // check whether an application client is supported by the target server
655: ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel
656: .getSelectedItem();
657: if (serverInstanceWrapper != null) {
658: J2eePlatform j2eePlatform = Deployment
659: .getDefault()
660: .getJ2eePlatform(
661: serverInstanceWrapper.getServerInstanceID());
662: if (!j2eePlatform.getSupportedModuleTypes().contains(
663: J2eeModule.CLIENT)) {
664: // show warning/info
665: setErrorMessage("MSG_CARIsNotSupported",
666: wizardDescriptor);
667: }
668: }
669:
670: String specVer = getSelectedJ2eeSpec();
671: if (null == specVer || specVer.equals(J2eeModule.J2EE_13)) {
672: setErrorMessage("MSG_UnsupportedSpec", wizardDescriptor); // NOI18N
673: return false;
674: }
675: return true;
676: }
677:
678: private static void setErrorMessage(final String errMsgKey,
679: final WizardDescriptor wizardDescriptor) {
680: wizardDescriptor
681: .putProperty("WizardPanel_errorMessage", // NOI18N
682: NbBundle.getMessage(PanelOptionsVisual.class,
683: errMsgKey));
684: }
685:
686: void store(WizardDescriptor d) {
687: d.putProperty(WizardProperties.SET_AS_MAIN, setAsMainCheckBox
688: .isSelected() ? Boolean.TRUE : Boolean.FALSE);
689: d.putProperty(WizardProperties.SERVER_INSTANCE_ID,
690: getSelectedServer());
691: d.putProperty(WizardProperties.J2EE_LEVEL,
692: getSelectedJ2eeSpec());
693: // d.putProperty(WizardProperties.CONTEXT_PATH, jTextFieldContextPath.getText().trim());
694: d.putProperty(WizardProperties.CREATE_WAR, createWARCheckBox
695: .isSelected() ? Boolean.TRUE : Boolean.FALSE);
696: d.putProperty(WizardProperties.CREATE_JAR, createEjbCheckBox
697: .isSelected() ? Boolean.TRUE : Boolean.FALSE);
698: d.putProperty(WizardProperties.CREATE_CAR, createCarCheckBox
699: .isEnabled()
700: && createCarCheckBox.isSelected() ? Boolean.TRUE
701: : Boolean.FALSE);
702: d.putProperty(WizardProperties.WAR_NAME, jTextFieldWebAppName
703: .getText());
704: d.putProperty(WizardProperties.JAR_NAME,
705: jTextFieldEjbModuleName.getText());
706: d.putProperty(WizardProperties.CAR_NAME, jTextFieldCarName
707: .getText());
708: d.putProperty(WizardProperties.MAIN_CLASS, mainClassTextField
709: .getText().trim()); // NOI18N
710: if (warningPanel != null
711: && warningPanel.getWarningType() != null
712: && warningPanel.getDowngradeAllowed()) {
713: d.putProperty(WizardProperties.JAVA_PLATFORM, warningPanel
714: .getSuggestedJavaPlatformName());
715: String j2ee = getSelectedJ2eeSpec();
716: if (j2ee != null) {
717: String warningType = J2eeVersionWarningPanel
718: .findWarningType(j2ee);
719: UserProjectSettings fls = UserProjectSettings
720: .getDefault();
721: String srcLevel = "1.6"; // NOI18N
722: if ((warningType
723: .equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_14) || warningType
724: .equals(J2eeVersionWarningPanel.WARN_SET_JDK_14))
725: && fls.isAgreedSetSourceLevel14()) {
726: srcLevel = "1.4"; // NOI18N
727: } else if ((warningType
728: .equals(J2eeVersionWarningPanel.WARN_SET_SOURCE_LEVEL_15) || warningType
729: .equals(J2eeVersionWarningPanel.WARN_SET_JDK_15))
730: && fls.isAgreedSetSourceLevel15()) {
731: srcLevel = "1.5"; // NOI18N
732: }
733: d.putProperty(WizardProperties.SOURCE_LEVEL, srcLevel);
734: }
735: } else {
736: d.putProperty(WizardProperties.SOURCE_LEVEL, null);
737: }
738: }
739:
740: void read(WizardDescriptor d) {
741: }
742:
743: // Variables declaration - do not modify//GEN-BEGIN:variables
744: private javax.swing.JButton addServerButton;
745: private javax.swing.JCheckBox createCarCheckBox;
746: private javax.swing.JCheckBox createEjbCheckBox;
747: private javax.swing.JCheckBox createWARCheckBox;
748: private javax.swing.JComboBox j2eeSpecComboBox;
749: private javax.swing.JLabel j2eeSpecLabel;
750: private javax.swing.JTextField jTextFieldCarName;
751: private javax.swing.JTextField jTextFieldEjbModuleName;
752: private javax.swing.JTextField jTextFieldWebAppName;
753: private javax.swing.JLabel mainClassLabel;
754: private javax.swing.JTextField mainClassTextField;
755: private javax.swing.JPanel serverAndVersionPanel;
756: private javax.swing.JComboBox serverInstanceComboBox;
757: private javax.swing.JLabel serverInstanceLabel;
758: private javax.swing.JCheckBox setAsMainCheckBox;
759: private javax.swing.JPanel warningPlaceHolderPanel;
760:
761: // End of variables declaration//GEN-END:variables
762:
763: /**
764: * Init servers model
765: * @param selectedServerInstanceID preselected instance or null if non is preselected
766: */
767: private void initServers(String selectedServerInstanceID) {
768: // init the list of server instances
769: serversModel.removeAllElements();
770: Set<ServerInstanceWrapper> servers = new TreeSet<ServerInstanceWrapper>();
771: ServerInstanceWrapper selectedItem = null;
772: boolean sjasFound = false;
773: for (String serverInstanceID : Deployment.getDefault()
774: .getServerInstanceIDs()) {
775: String displayName = Deployment.getDefault()
776: .getServerInstanceDisplayName(serverInstanceID);
777: J2eePlatform j2eePlatform = Deployment.getDefault()
778: .getJ2eePlatform(serverInstanceID);
779: if (displayName != null
780: && j2eePlatform != null
781: && j2eePlatform.getSupportedModuleTypes().contains(
782: J2eeModule.EAR)) {
783: ServerInstanceWrapper serverWrapper = new ServerInstanceWrapper(
784: serverInstanceID, displayName);
785: // decide whether this server should be preselected
786: if (selectedItem == null || !sjasFound) {
787: if (selectedServerInstanceID != null) {
788: if (selectedServerInstanceID
789: .equals(serverInstanceID)) {
790: selectedItem = serverWrapper;
791: }
792: } else {
793: // preselect the best server ;)
794: String shortName = Deployment.getDefault()
795: .getServerID(serverInstanceID);
796: if ("J2EE".equals(shortName)) { // NOI18N
797: selectedItem = serverWrapper;
798: sjasFound = true;
799: } else if ("JBoss4".equals(shortName)) { // NOI18N
800: selectedItem = serverWrapper;
801: }
802: }
803: }
804: servers.add(serverWrapper);
805: }
806: }
807: for (ServerInstanceWrapper item : servers) {
808: serversModel.addElement(item);
809: }
810: if (selectedItem != null) {
811: // set the preselected item
812: serversModel.setSelectedItem(selectedItem);
813: } else if (serversModel.getSize() > 0) {
814: // set the first item
815: serversModel.setSelectedItem(serversModel.getElementAt(0));
816: }
817: }
818:
819: private String getSelectedJ2eeSpec() {
820: Object item = j2eeSpecComboBox.getSelectedItem();
821: return item == null ? null
822: : item
823: .equals(EarProjectProperties.JAVA_EE_SPEC_50_LABEL) ? J2eeModule.JAVA_EE_5
824: : (item
825: .equals(EarProjectProperties.J2EE_SPEC_14_LABEL) ? J2eeModule.J2EE_14
826: : J2eeModule.J2EE_13);
827: }
828:
829: private String getSelectedServer() {
830: ServerInstanceWrapper serverInstanceWrapper = (ServerInstanceWrapper) serversModel
831: .getSelectedItem();
832: if (serverInstanceWrapper == null) {
833: return null;
834: }
835: return serverInstanceWrapper.getServerInstanceID();
836: }
837:
838: private void setJ2eeVersionWarningPanel() {
839: String j2ee = getSelectedJ2eeSpec();
840: if (j2ee == null) {
841: return;
842: }
843: String warningType = J2eeVersionWarningPanel
844: .findWarningType(j2ee);
845: if (warningType == null && warningPanel == null) {
846: return;
847: }
848: if (warningPanel == null) {
849: warningPanel = new J2eeVersionWarningPanel(warningType);
850: warningPlaceHolderPanel.add(warningPanel,
851: java.awt.BorderLayout.CENTER);
852: }
853: warningPanel.setWarningType(warningType);
854: }
855:
856: private void mainClassChanged() {
857: String mainClassName = this .mainClassTextField.getText().trim();
858: StringTokenizer tk = new StringTokenizer(mainClassName, "."); //NOI18N
859: boolean valid = tk.countTokens() > 0;
860: while (tk.hasMoreTokens()) {
861: String token = tk.nextToken();
862: if (token.length() == 0
863: || !Utilities.isJavaIdentifier(token)) {
864: valid = false;
865: break;
866: }
867: }
868: this .valid = valid;
869: this .panel.fireChangeEvent();
870: }
871:
872: private void projectNameChanged() {
873: this .panel.fireChangeEvent();
874: }
875:
876: private String getPackageName(String displayName) {
877: StringBuffer builder = new StringBuffer();
878: boolean firstLetter = true;
879: for (int i = 0; i < displayName.length(); i++) {
880: char c = displayName.charAt(i);
881: if ((!firstLetter && Character.isJavaIdentifierPart(c))
882: || (firstLetter && Character
883: .isJavaIdentifierStart(c))) {
884: firstLetter = false;
885: if (Character.isUpperCase(c)) {
886: c = Character.toLowerCase(c);
887: }
888: builder.append(c);
889: }
890: }
891: return builder.length() == 0 ? NbBundle.getMessage(
892: PanelOptionsVisual.class, "TXT_DefaultPackageName")
893: : builder.toString();
894: }
895:
896: /**
897: * Server instance wrapper represents server instances in the servers combobox.
898: * @author sherold
899: */
900: private static class ServerInstanceWrapper implements Comparable {
901:
902: private final String serverInstanceID;
903: private final String displayName;
904:
905: ServerInstanceWrapper(String serverInstanceID,
906: String displayName) {
907: this .serverInstanceID = serverInstanceID;
908: this .displayName = displayName;
909: }
910:
911: public String getServerInstanceID() {
912: return serverInstanceID;
913: }
914:
915: public String toString() {
916: return displayName;
917: }
918:
919: public int compareTo(Object o) {
920: return toString().compareTo(o.toString());
921: }
922:
923: }
924:
925: }
|