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-2007 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: * JPanel.java
043: *
044: * Created on May 5, 2004, 11:06 AM
045: */
046:
047: package org.netbeans.modules.visualweb.ejb.ui;
048:
049: import javax.swing.event.DocumentEvent;
050: import org.netbeans.modules.visualweb.ejb.datamodel.EjbContainerVendor;
051: import org.netbeans.modules.visualweb.ejb.datamodel.EjbDataModel;
052: import org.netbeans.modules.visualweb.ejb.datamodel.EjbGroup;
053: import java.io.File;
054: import java.util.*;
055: import javax.swing.JComboBox;
056: import javax.swing.JFileChooser;
057: import javax.swing.JFileChooser;
058: import javax.swing.event.ChangeEvent;
059: import javax.swing.event.ChangeListener;
060: import javax.swing.filechooser.FileFilter;
061: import org.openide.util.NbBundle;
062: import org.openide.modules.InstalledFileLocator;
063:
064: /**
065: * This class defines the panel for the user to input the Ejb Group data.
066: *
067: * @author cao
068: */
069: public class EjbGroupPanel extends javax.swing.JPanel {
070: // Pointing to the <INSTALL_DIR>/samples/ejb/client-jars dir by default
071: private static File DEFAULT_CURRENT_JAR_DIR_FILE = InstalledFileLocator
072: .getDefault()
073: .locate("samples/ejb/client-jars", null, false); // NOI18N
074:
075: private boolean isNewCreation = true;
076: private final ArrayList<ChangeListener> listeners = new ArrayList<ChangeListener>();
077:
078: public EjbGroupPanel(EjbGroup group) {
079: initComponents();
080: setName(NbBundle.getMessage(EjbGroupPanel.class,
081: "ADD_EJB_GROUP"));
082:
083: containerTypeCombo
084: .setModel(new javax.swing.DefaultComboBoxModel(
085: EjbContainerVendor.getContainerTypeNames()));
086: ClientJarFileListModel listModel = new ClientJarFileListModel();
087:
088: groupNameTextField.getDocument().addDocumentListener(
089: new javax.swing.event.DocumentListener() {
090:
091: public void insertUpdate(DocumentEvent e) {
092: for (ChangeListener listener : listeners) {
093: listener.stateChanged(new ChangeEvent(
094: EjbGroupPanel.this ));
095: }
096: }
097:
098: public void removeUpdate(DocumentEvent e) {
099: for (ChangeListener listener : listeners) {
100: listener.stateChanged(new ChangeEvent(
101: EjbGroupPanel.this ));
102: }
103: }
104:
105: public void changedUpdate(DocumentEvent e) {
106: for (ChangeListener listener : listeners) {
107: listener.stateChanged(new ChangeEvent(
108: EjbGroupPanel.this ));
109: }
110: }
111:
112: });
113:
114: if (group == null) {
115: String initName = EjbDataModel.getInstance()
116: .getAUniqueName("DeployedEjbApp"); // I18N???
117: groupNameTextField.setText(initName);
118: } else {
119: isNewCreation = false;
120:
121: groupNameTextField.setText(group.getName());
122: serverHostTextField.setText(group.getServerHost());
123: iiopPortTextField.setText(Integer.toString(group
124: .getIIOPPort()));
125: containerTypeCombo.setSelectedItem(group
126: .getAppServerVendor());
127: ddLocTextField.setText(group.getDDLocationFile());
128:
129: // Populate the client jar list
130: for (Iterator iter = group.getClientJarFiles().iterator(); iter
131: .hasNext();) {
132: listModel.addJarFile((String) iter.next());
133: }
134:
135: removeClientJarButton.setEnabled(true);
136: }
137:
138: clientJarsList.setModel(listModel);
139: }
140:
141: public EjbGroupPanel() {
142: this (null);
143: }
144:
145: public String getGroupName() {
146: return groupNameTextField.getText().trim();
147: }
148:
149: public void addChangeListener(ChangeListener listener) {
150: listeners.add(listener);
151: }
152:
153: public ArrayList getClientJars() {
154: //return clientJarTextField.getText().trim();
155: ArrayList fileNames = new ArrayList();
156: for (int i = 0; i < clientJarsList.getModel().getSize(); i++) {
157: fileNames.add(clientJarsList.getModel().getElementAt(i));
158: }
159:
160: return fileNames;
161: }
162:
163: public String getDDLocationFile() {
164: if (ddLocTextField.getText() != null
165: && ddLocTextField.getText().trim().length() != 0)
166: return ddLocTextField.getText().trim();
167: else
168: return null;
169: }
170:
171: public String getContainerType() {
172: return (String) containerTypeCombo.getSelectedItem();
173: }
174:
175: public String getServerHost() {
176: return serverHostTextField.getText().trim();
177: }
178:
179: public String getIIOPPort() {
180: return iiopPortTextField.getText().trim();
181: }
182:
183: public boolean validateData(StringBuffer errorMsg) {
184: // Make sure all the required fields are not empty and valid
185:
186: boolean valid = true;
187:
188: if (getGroupName() == null || getGroupName().length() == 0) {
189: if (valid) {
190: groupNameTextField.requestFocus();
191: valid = false;
192: }
193:
194: errorMsg.append(NbBundle.getMessage(
195: AddEjbGroupDialog.class, "EMPTY_GROUP_NAME"));
196: errorMsg.append("\n");
197: }
198: // Check uniqueness if modifying an existing group
199: else if (!isNewCreation
200: && EjbDataModel.getInstance().getEjbGroup(
201: getGroupName()) != null) {
202: if (valid) {
203: groupNameTextField.requestFocus();
204: groupNameTextField.selectAll();
205: valid = false;
206: }
207:
208: errorMsg.append(NbBundle.getMessage(
209: AddEjbGroupDialog.class, "NAME_NOT_UNIQUE", "\'"
210: + getGroupName() + "\'"));
211: errorMsg.append("\n");
212: }
213:
214: if (getContainerType() == null
215: || getContainerType().length() == 0) {
216: if (valid) {
217: containerTypeCombo.requestFocus();
218: valid = false;
219: }
220:
221: errorMsg.append(NbBundle.getMessage(
222: AddEjbGroupDialog.class, "EMPTY_APP_SERVER"));
223: errorMsg.append("\n");
224: }
225:
226: if (getServerHost() == null || getServerHost().length() == 0) {
227: if (valid) {
228: serverHostTextField.requestFocus();
229: valid = false;
230: }
231:
232: errorMsg.append(NbBundle.getMessage(
233: AddEjbGroupDialog.class, "EMPTY_SERVER_HOST"));
234: errorMsg.append("\n");
235: } else if (getServerHost().indexOf(' ') != -1) {
236: // Can not contain spaces
237: if (valid) {
238: serverHostTextField.requestFocus();
239: serverHostTextField.selectAll();
240: valid = false;
241: }
242:
243: errorMsg.append(NbBundle.getMessage(
244: AddEjbGroupDialog.class, "SPACES_IN_SERVER_HOST",
245: "\'" + getServerHost() + "\'"));
246: errorMsg.append("\n");
247: }
248:
249: if (getIIOPPort() == null || getIIOPPort().length() == 0) {
250: if (valid) {
251: iiopPortTextField.requestFocus();
252: valid = false;
253: }
254:
255: errorMsg.append(NbBundle.getMessage(
256: AddEjbGroupDialog.class, "EMPTY_IIOP_PORT"));
257: errorMsg.append("\n");
258: } else {
259: // Make it is a number
260: try {
261: int portNum = Integer.parseInt(getIIOPPort());
262: } catch (NumberFormatException ex) {
263: if (valid) {
264: iiopPortTextField.requestFocus();
265: iiopPortTextField.selectAll();
266: valid = false;
267: }
268:
269: errorMsg.append(NbBundle
270: .getMessage(AddEjbGroupDialog.class,
271: "IIOP_PORT_NOT_NUMBER"));
272: errorMsg.append("\n");
273: }
274: }
275:
276: if (getClientJars() == null || getClientJars().size() == 0) {
277: if (valid) {
278: clientJarsList.requestFocus();
279: valid = false;
280: }
281:
282: errorMsg.append(NbBundle.getMessage(
283: AddEjbGroupDialog.class, "EMPTY_CLIENT_JAR"));
284: errorMsg.append("\n");
285: } else {
286: // Make sure they are existed
287: for (Iterator iter = getClientJars().iterator(); iter
288: .hasNext();) {
289: String jar = (String) iter.next();
290: if (!(new File(jar)).exists()) {
291: if (valid) {
292: clientJarsList.requestFocus();
293: valid = false;
294: }
295:
296: errorMsg.append(NbBundle.getMessage(
297: AddEjbGroupDialog.class,
298: "CLIENT_JAR_NOT_EXIST", jar));
299: errorMsg.append("\n");
300: }
301: }
302: }
303:
304: // Make sure the dd location file is existed if the user has specified one
305: if (getDDLocationFile() != null
306: && getDDLocationFile().length() != 0) {
307: if (!(new File(getDDLocationFile())).exists()) {
308: if (valid) {
309: ddLocTextField.requestFocus();
310: ddLocTextField.selectAll();
311: valid = false;
312: }
313:
314: errorMsg.append(NbBundle.getMessage(
315: AddEjbGroupDialog.class, "DD_FILE_NOT_EXIST",
316: getDDLocationFile()));
317: errorMsg.append("\n");
318: }
319: }
320:
321: return valid;
322: }
323:
324: /** This method is called from within the constructor to
325: * initialize the form.
326: * WARNING: Do NOT modify this code. The content of this method is
327: * always regenerated by the Form Editor.
328: */
329: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
330: private void initComponents() {
331: java.awt.GridBagConstraints gridBagConstraints;
332:
333: groupNameLabel = new javax.swing.JLabel();
334: groupNameTextField = new javax.swing.JTextField();
335: containerTypeLabel = new javax.swing.JLabel();
336: containerTypeCombo = new javax.swing.JComboBox();
337: serverHostLabel = new javax.swing.JLabel();
338: serverHostTextField = new javax.swing.JTextField();
339: iiopPortLabel = new javax.swing.JLabel();
340: iiopPortTextField = new javax.swing.JTextField();
341: ddLocLabel1 = new javax.swing.JLabel();
342: ddLocLabel2 = new javax.swing.JLabel();
343: ddLocTextField = new javax.swing.JTextField();
344: ddLocButton = new javax.swing.JButton();
345: clientJarsLabel = new javax.swing.JLabel();
346: clientJarScrollPane = new javax.swing.JScrollPane();
347: clientJarsList = new javax.swing.JList();
348: cleintJarButtonPanel = new javax.swing.JPanel();
349: addClientJarButton = new javax.swing.JButton();
350: removeClientJarButton = new javax.swing.JButton();
351:
352: setLayout(new java.awt.GridBagLayout());
353:
354: setMinimumSize(new java.awt.Dimension(510, 292));
355: getAccessibleContext().setAccessibleName(
356: org.openide.util.NbBundle.getMessage(
357: EjbGroupPanel.class, "ADD_EJB_GROUP"));
358: getAccessibleContext().setAccessibleDescription(
359: org.openide.util.NbBundle.getMessage(
360: EjbGroupPanel.class, "ADD_EJB_GROUP"));
361: groupNameLabel.setDisplayedMnemonic(org.openide.util.NbBundle
362: .getMessage(EjbGroupPanel.class,
363: "EJB_GROUP_NAME_MNEMONIC").charAt(0));
364: groupNameLabel.setLabelFor(groupNameTextField);
365: groupNameLabel.setText(java.util.ResourceBundle.getBundle(
366: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
367: .getString("EJB_GROUP_NAME_LABEL"));
368: groupNameLabel.setPreferredSize(new java.awt.Dimension(20, 15));
369: gridBagConstraints = new java.awt.GridBagConstraints();
370: gridBagConstraints.gridx = 0;
371: gridBagConstraints.gridy = 0;
372: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
373: gridBagConstraints.ipadx = 23;
374: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
375: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
376: add(groupNameLabel, gridBagConstraints);
377: groupNameLabel.getAccessibleContext().setAccessibleDescription(
378: java.util.ResourceBundle.getBundle(
379: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
380: .getString("EJB_GROUP_NAME_DESC"));
381:
382: groupNameTextField
383: .addActionListener(new java.awt.event.ActionListener() {
384: public void actionPerformed(
385: java.awt.event.ActionEvent evt) {
386: groupNameTextFieldActionPerformed(evt);
387: }
388: });
389:
390: gridBagConstraints = new java.awt.GridBagConstraints();
391: gridBagConstraints.gridx = 3;
392: gridBagConstraints.gridy = 0;
393: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
394: gridBagConstraints.ipadx = 159;
395: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
396: gridBagConstraints.weightx = 1.0;
397: gridBagConstraints.insets = new java.awt.Insets(12, 0, 2, 0);
398: add(groupNameTextField, gridBagConstraints);
399: groupNameTextField
400: .getAccessibleContext()
401: .setAccessibleDescription(
402: java.util.ResourceBundle
403: .getBundle(
404: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
405: .getString("EJB_GROUP_NAME_DESC"));
406:
407: containerTypeLabel
408: .setDisplayedMnemonic(org.openide.util.NbBundle
409: .getMessage(EjbGroupPanel.class,
410: "APP_SERVER_LABEL1_MNEMONIC").charAt(0));
411: containerTypeLabel.setLabelFor(containerTypeCombo);
412: containerTypeLabel.setText(java.util.ResourceBundle.getBundle(
413: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
414: .getString("APP_SERVER_LABEL1"));
415: gridBagConstraints = new java.awt.GridBagConstraints();
416: gridBagConstraints.gridx = 0;
417: gridBagConstraints.gridy = 2;
418: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
419: gridBagConstraints.ipadx = 8;
420: gridBagConstraints.ipady = 5;
421: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
422: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
423: add(containerTypeLabel, gridBagConstraints);
424: containerTypeLabel
425: .getAccessibleContext()
426: .setAccessibleDescription(
427: java.util.ResourceBundle
428: .getBundle(
429: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
430: .getString("APP_SERVER_DESC"));
431:
432: containerTypeCombo
433: .addActionListener(new java.awt.event.ActionListener() {
434: public void actionPerformed(
435: java.awt.event.ActionEvent evt) {
436: containerTypeComboActionPerformed(evt);
437: }
438: });
439:
440: gridBagConstraints = new java.awt.GridBagConstraints();
441: gridBagConstraints.gridx = 3;
442: gridBagConstraints.gridy = 2;
443: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
444: gridBagConstraints.ipadx = 159;
445: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
446: gridBagConstraints.weightx = 1.0;
447: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
448: add(containerTypeCombo, gridBagConstraints);
449: containerTypeCombo
450: .getAccessibleContext()
451: .setAccessibleDescription(
452: java.util.ResourceBundle
453: .getBundle(
454: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
455: .getString("APP_SERVER_DESC"));
456:
457: serverHostLabel
458: .setDisplayedMnemonic(org.openide.util.NbBundle
459: .getMessage(EjbGroupPanel.class,
460: "SERVER_HOST_MNEMONIC").charAt(0));
461: serverHostLabel.setLabelFor(serverHostTextField);
462: serverHostLabel.setText(java.util.ResourceBundle.getBundle(
463: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
464: .getString("SERVER_HOST_LABEL"));
465: gridBagConstraints = new java.awt.GridBagConstraints();
466: gridBagConstraints.gridx = 0;
467: gridBagConstraints.gridy = 4;
468: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
469: gridBagConstraints.ipadx = 49;
470: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
471: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
472: add(serverHostLabel, gridBagConstraints);
473: serverHostLabel
474: .getAccessibleContext()
475: .setAccessibleDescription(
476: java.util.ResourceBundle
477: .getBundle(
478: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
479: .getString("SERVER_HOST_DESC"));
480:
481: serverHostTextField.setText("localhost");
482: serverHostTextField
483: .addActionListener(new java.awt.event.ActionListener() {
484: public void actionPerformed(
485: java.awt.event.ActionEvent evt) {
486: serverHostTextFieldActionPerformed(evt);
487: }
488: });
489:
490: gridBagConstraints = new java.awt.GridBagConstraints();
491: gridBagConstraints.gridx = 3;
492: gridBagConstraints.gridy = 4;
493: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
494: gridBagConstraints.ipadx = 159;
495: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
496: gridBagConstraints.weightx = 1.0;
497: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
498: add(serverHostTextField, gridBagConstraints);
499: serverHostTextField
500: .getAccessibleContext()
501: .setAccessibleDescription(
502: java.util.ResourceBundle
503: .getBundle(
504: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
505: .getString("SERVER_HOST_DESC"));
506:
507: iiopPortLabel.setDisplayedMnemonic(org.openide.util.NbBundle
508: .getMessage(EjbGroupPanel.class, "IIOP_PORT_MNEMONIC")
509: .charAt(0));
510: iiopPortLabel.setLabelFor(iiopPortTextField);
511: iiopPortLabel.setText(java.util.ResourceBundle.getBundle(
512: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
513: .getString("IIOP_PORT_LABEL"));
514: gridBagConstraints = new java.awt.GridBagConstraints();
515: gridBagConstraints.gridx = 0;
516: gridBagConstraints.gridy = 6;
517: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
518: gridBagConstraints.ipadx = 36;
519: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
520: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
521: add(iiopPortLabel, gridBagConstraints);
522: iiopPortLabel.getAccessibleContext().setAccessibleDescription(
523: java.util.ResourceBundle.getBundle(
524: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
525: .getString("IIOP_PORT_DESC"));
526:
527: iiopPortTextField.setText("3700");
528: iiopPortTextField
529: .addActionListener(new java.awt.event.ActionListener() {
530: public void actionPerformed(
531: java.awt.event.ActionEvent evt) {
532: iiopPortTextFieldActionPerformed(evt);
533: }
534: });
535:
536: gridBagConstraints = new java.awt.GridBagConstraints();
537: gridBagConstraints.gridx = 3;
538: gridBagConstraints.gridy = 6;
539: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
540: gridBagConstraints.ipadx = 159;
541: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
542: gridBagConstraints.weightx = 1.0;
543: gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
544: add(iiopPortTextField, gridBagConstraints);
545: iiopPortTextField
546: .getAccessibleContext()
547: .setAccessibleDescription(
548: java.util.ResourceBundle
549: .getBundle(
550: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
551: .getString("IIOP_PORT_DESC"));
552:
553: ddLocLabel1.setDisplayedMnemonic(org.openide.util.NbBundle
554: .getMessage(EjbGroupPanel.class,
555: "DEPLOYMENT_DESCRIPTOR_LOCATION_MNEMONIC")
556: .charAt(0));
557: ddLocLabel1.setLabelFor(ddLocTextField);
558: ddLocLabel1.setText(java.util.ResourceBundle.getBundle(
559: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
560: .getString("DEPLOYMENT_DESCRIPTOR_LOCATION_LABEL1"));
561: ddLocLabel1.setDoubleBuffered(true);
562: gridBagConstraints = new java.awt.GridBagConstraints();
563: gridBagConstraints.gridx = 0;
564: gridBagConstraints.gridy = 14;
565: gridBagConstraints.gridwidth = 4;
566: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
567: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
568: add(ddLocLabel1, gridBagConstraints);
569: ddLocLabel1.getAccessibleContext().setAccessibleDescription(
570: java.util.ResourceBundle.getBundle(
571: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
572: .getString(
573: "DEPLOYMENT_DESCRIPTOR_LOCATION_DESC"));
574:
575: ddLocLabel2.setText(java.util.ResourceBundle.getBundle(
576: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
577: .getString("DEPLOYMENT_DESCRIPTOR_LOCATION_LABEL2"));
578: gridBagConstraints = new java.awt.GridBagConstraints();
579: gridBagConstraints.gridx = 0;
580: gridBagConstraints.gridy = 15;
581: gridBagConstraints.gridwidth = 4;
582: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
583: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
584: add(ddLocLabel2, gridBagConstraints);
585:
586: ddLocTextField
587: .addActionListener(new java.awt.event.ActionListener() {
588: public void actionPerformed(
589: java.awt.event.ActionEvent evt) {
590: ddLocTextFieldActionPerformed(evt);
591: }
592: });
593:
594: gridBagConstraints = new java.awt.GridBagConstraints();
595: gridBagConstraints.gridx = 0;
596: gridBagConstraints.gridy = 16;
597: gridBagConstraints.gridwidth = 4;
598: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
599: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
600: add(ddLocTextField, gridBagConstraints);
601: ddLocTextField.getAccessibleContext().setAccessibleDescription(
602: java.util.ResourceBundle.getBundle(
603: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
604: .getString(
605: "DEPLOYMENT_DESCRIPTOR_LOCATION_DESC"));
606:
607: ddLocButton.setMnemonic(org.openide.util.NbBundle.getMessage(
608: EjbGroupPanel.class, "BROWSE_DD_BUTTON_MNEMONIC")
609: .charAt(0));
610: ddLocButton.setText(java.util.ResourceBundle.getBundle(
611: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
612: .getString("BROWSE_DD_BUTTON_LABEL"));
613: ddLocButton.setActionCommand("Select");
614: ddLocButton
615: .addActionListener(new java.awt.event.ActionListener() {
616: public void actionPerformed(
617: java.awt.event.ActionEvent evt) {
618: ddLocButtonActionPerformed(evt);
619: }
620: });
621:
622: gridBagConstraints = new java.awt.GridBagConstraints();
623: gridBagConstraints.gridx = 4;
624: gridBagConstraints.gridy = 16;
625: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
626: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
627: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 10);
628: add(ddLocButton, gridBagConstraints);
629: ddLocButton.getAccessibleContext().setAccessibleDescription(
630: java.util.ResourceBundle.getBundle(
631: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
632: .getString("BROWSE_DD_BUTTON_DESC"));
633:
634: clientJarsLabel.setDisplayedMnemonic(org.openide.util.NbBundle
635: .getMessage(EjbGroupPanel.class,
636: "CLIENT_JAR_FILE_MNEMONIC").charAt(0));
637: clientJarsLabel.setLabelFor(clientJarsList);
638: clientJarsLabel.setText(java.util.ResourceBundle.getBundle(
639: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
640: .getString("CLIENT_JAR_FILE_LABEL"));
641: gridBagConstraints = new java.awt.GridBagConstraints();
642: gridBagConstraints.gridx = 0;
643: gridBagConstraints.gridy = 8;
644: gridBagConstraints.gridwidth = 4;
645: gridBagConstraints.ipadx = 53;
646: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
647: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
648: add(clientJarsLabel, gridBagConstraints);
649: clientJarsLabel
650: .getAccessibleContext()
651: .setAccessibleDescription(
652: java.util.ResourceBundle
653: .getBundle(
654: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
655: .getString("CLIENT_JAR_DESC"));
656:
657: clientJarScrollPane.setMinimumSize(new java.awt.Dimension(260,
658: 60));
659: clientJarScrollPane.setPreferredSize(new java.awt.Dimension(
660: 260, 60));
661: clientJarsList.setMaximumSize(new java.awt.Dimension(500, 500));
662: clientJarsList.setMinimumSize(new java.awt.Dimension(260, 132));
663: clientJarsList
664: .setPreferredSize(new java.awt.Dimension(100, 50));
665: clientJarScrollPane.setViewportView(clientJarsList);
666: clientJarsList.getAccessibleContext().setAccessibleDescription(
667: java.util.ResourceBundle.getBundle(
668: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
669: .getString("CLIENT_JAR_DESC"));
670:
671: gridBagConstraints = new java.awt.GridBagConstraints();
672: gridBagConstraints.gridx = 0;
673: gridBagConstraints.gridy = 9;
674: gridBagConstraints.gridwidth = 4;
675: gridBagConstraints.gridheight = 2;
676: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
677: gridBagConstraints.weightx = 1.0;
678: gridBagConstraints.weighty = 1.0;
679: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
680: add(clientJarScrollPane, gridBagConstraints);
681:
682: cleintJarButtonPanel.setLayout(new java.awt.GridLayout(2, 1, 0,
683: 5));
684:
685: addClientJarButton.setMnemonic(org.openide.util.NbBundle
686: .getMessage(EjbGroupPanel.class,
687: "ADD_CLIENT_JAR_BUTTON_MNEMONIC").charAt(0));
688: addClientJarButton.setText(java.util.ResourceBundle.getBundle(
689: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
690: .getString("ADD_CLIENT_JAR_BUTTON_LABEL"));
691: addClientJarButton.setActionCommand("Add");
692: addClientJarButton
693: .addActionListener(new java.awt.event.ActionListener() {
694: public void actionPerformed(
695: java.awt.event.ActionEvent evt) {
696: addClientJarButtonActionPerformed(evt);
697: }
698: });
699:
700: cleintJarButtonPanel.add(addClientJarButton);
701: addClientJarButton
702: .getAccessibleContext()
703: .setAccessibleDescription(
704: java.util.ResourceBundle
705: .getBundle(
706: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
707: .getString("ADD_CLIENT_JAR_BUTTON_DESC"));
708:
709: removeClientJarButton.setMnemonic(org.openide.util.NbBundle
710: .getMessage(EjbGroupPanel.class,
711: "REMOVE_CLIENT_JAR_BUTTON_MNEMONIC").charAt(0));
712: removeClientJarButton.setText(java.util.ResourceBundle
713: .getBundle(
714: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
715: .getString("REMOVE_CLIENT_JAR_BUTTON_LABEL"));
716: removeClientJarButton.setEnabled(false);
717: removeClientJarButton
718: .addActionListener(new java.awt.event.ActionListener() {
719: public void actionPerformed(
720: java.awt.event.ActionEvent evt) {
721: removeClientJarButtonActionPerformed(evt);
722: }
723: });
724:
725: cleintJarButtonPanel.add(removeClientJarButton);
726: removeClientJarButton
727: .getAccessibleContext()
728: .setAccessibleDescription(
729: java.util.ResourceBundle
730: .getBundle(
731: "org/netbeans/modules/visualweb/ejb/ui/Bundle")
732: .getString(
733: "REMOVE_CLIENT_JAR_BUTTON_DESC"));
734:
735: gridBagConstraints = new java.awt.GridBagConstraints();
736: gridBagConstraints.gridx = 4;
737: gridBagConstraints.gridy = 9;
738: gridBagConstraints.gridheight = 2;
739: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
740: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
741: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 10);
742: add(cleintJarButtonPanel, gridBagConstraints);
743:
744: }
745:
746: // </editor-fold>//GEN-END:initComponents
747:
748: private void removeClientJarButtonActionPerformed(
749: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeClientJarButtonActionPerformed
750: Object[] selectedFiles = clientJarsList.getSelectedValues();
751: for (int i = 0; i < selectedFiles.length; i++) {
752: ((ClientJarFileListModel) clientJarsList.getModel())
753: .removeElement(selectedFiles[i]);
754: }
755:
756: // Enable the remove button if there are jars in the list
757: if (clientJarsList.getModel().getSize() > 0)
758: removeClientJarButton.setEnabled(true);
759: else
760: removeClientJarButton.setEnabled(false);
761:
762: }//GEN-LAST:event_removeClientJarButtonActionPerformed
763:
764: private void addClientJarButtonActionPerformed(
765: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addClientJarButtonActionPerformed
766: // Pop up FileChooser to let the user select a .ear or .jar file where
767: // the EJB deployment descriptors are contained
768:
769: JFileChooser clientJarFileChooser = org.netbeans.modules.visualweb.extension.openide.awt.JFileChooser_RAVE
770: .getJFileChooser();
771: clientJarFileChooser.setMultiSelectionEnabled(true);
772: clientJarFileChooser.setFileFilter(new JarFileFilter(true));
773: clientJarFileChooser
774: .setFileSelectionMode(JFileChooser.FILES_ONLY);
775:
776: // Set the current directory -- WHERE ???
777: File curDir = DEFAULT_CURRENT_JAR_DIR_FILE;
778:
779: clientJarFileChooser.setCurrentDirectory(curDir);
780:
781: int returnVal = clientJarFileChooser.showOpenDialog(this );
782:
783: if (returnVal == JFileChooser.APPROVE_OPTION) {
784: File[] files = clientJarFileChooser.getSelectedFiles();
785:
786: for (int i = 0; i < files.length; i++) {
787: // Add the selected file to the client jars list
788: ClientJarFileListModel listModel = (ClientJarFileListModel) clientJarsList
789: .getModel();
790: listModel.addJarFile(files[i].getPath());
791:
792: // Default dir to the last selection
793: if (i == 0)
794: DEFAULT_CURRENT_JAR_DIR_FILE = files[i]
795: .getParentFile();
796: }
797: }
798:
799: // Enable the remove button if there are jars in the list
800: if (clientJarsList.getModel().getSize() > 0)
801: removeClientJarButton.setEnabled(true);
802: else
803: removeClientJarButton.setEnabled(false);
804: }//GEN-LAST:event_addClientJarButtonActionPerformed
805:
806: private void ddLocButtonActionPerformed(
807: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ddLocButtonActionPerformed
808: // Pop up FileChooser to let the user select a .ear or .jar file where
809: // the EJB deployment descriptors are contained
810:
811: JFileChooser ddFileChooser = new JFileChooser();
812: ddFileChooser.setMultiSelectionEnabled(false);
813: ddFileChooser.setFileFilter(new JarFileFilter(false));
814: ddFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
815:
816: // TODO what should the defualt current directory be?
817:
818: // Set the current directory
819: // If the user has a client file specified already, then we'll
820: // start from the that directory. Otherwise, use the default
821: // directory
822: File curDir = null;
823: if (getDDLocationFile() != null
824: && getDDLocationFile().length() != 0)
825: curDir = new File(getDDLocationFile());
826:
827: if (curDir == null)
828: curDir = DEFAULT_CURRENT_JAR_DIR_FILE;
829:
830: ddFileChooser.setCurrentDirectory(curDir);
831:
832: int returnVal = ddFileChooser.showOpenDialog(this );
833:
834: if (returnVal == JFileChooser.APPROVE_OPTION) {
835: File file = ddFileChooser.getSelectedFile();
836: ddLocTextField.setText(file.getAbsolutePath());
837:
838: // Default dir to the last selection
839: DEFAULT_CURRENT_JAR_DIR_FILE = file.getParentFile();
840: }
841: }//GEN-LAST:event_ddLocButtonActionPerformed
842:
843: private void ddLocTextFieldActionPerformed(
844: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ddLocTextFieldActionPerformed
845: // TODO add your handling code here:
846: }//GEN-LAST:event_ddLocTextFieldActionPerformed
847:
848: private void iiopPortTextFieldActionPerformed(
849: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iiopPortTextFieldActionPerformed
850: // TODO add your handling code here:
851: }//GEN-LAST:event_iiopPortTextFieldActionPerformed
852:
853: private void serverHostTextFieldActionPerformed(
854: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_serverHostTextFieldActionPerformed
855: // TODO add your handling code here:
856: }//GEN-LAST:event_serverHostTextFieldActionPerformed
857:
858: private void containerTypeComboActionPerformed(
859: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_containerTypeComboActionPerformed
860: // Display different default port for different app server
861: JComboBox cb = (JComboBox) evt.getSource();
862: String serverType = (String) cb.getSelectedItem();
863: int defaultPort = EjbContainerVendor.getDefaultPort(serverType);
864: iiopPortTextField.setText(Integer.toString(defaultPort));
865:
866: }//GEN-LAST:event_containerTypeComboActionPerformed
867:
868: private void groupNameTextFieldActionPerformed(
869: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groupNameTextFieldActionPerformed
870: // TODO add your handling code here:
871: }//GEN-LAST:event_groupNameTextFieldActionPerformed
872:
873: // Variables declaration - do not modify//GEN-BEGIN:variables
874: private javax.swing.JButton addClientJarButton;
875: private javax.swing.JPanel cleintJarButtonPanel;
876: private javax.swing.JScrollPane clientJarScrollPane;
877: private javax.swing.JLabel clientJarsLabel;
878: private javax.swing.JList clientJarsList;
879: private javax.swing.JComboBox containerTypeCombo;
880: private javax.swing.JLabel containerTypeLabel;
881: private javax.swing.JButton ddLocButton;
882: private javax.swing.JLabel ddLocLabel1;
883: private javax.swing.JLabel ddLocLabel2;
884: private javax.swing.JTextField ddLocTextField;
885: private javax.swing.JLabel groupNameLabel;
886: private javax.swing.JTextField groupNameTextField;
887: private javax.swing.JLabel iiopPortLabel;
888: private javax.swing.JTextField iiopPortTextField;
889: private javax.swing.JButton removeClientJarButton;
890: private javax.swing.JLabel serverHostLabel;
891: private javax.swing.JTextField serverHostTextField;
892: // End of variables declaration//GEN-END:variables
893:
894: }
895:
896: /**
897: * Filter file selection so only .jar files are shown
898: */
899: class JarFileFilter extends FileFilter {
900:
901: public final static String JAR_EXT = "jar"; // NOI18N
902: public final static String EAR_EXT = "ear"; // NOI18N
903:
904: private boolean jarOnly = true;
905:
906: public JarFileFilter(boolean jarOnly) {
907: this .jarOnly = jarOnly;
908: }
909:
910: /** Allow directories and jar files
911: */
912: public boolean accept(File file) {
913: if (file.isDirectory()) {
914: return true;
915: }
916:
917: String extension = getExtension(file);
918: if (extension != null) {
919: if (jarOnly && extension.equalsIgnoreCase(JAR_EXT)) {
920: return true;
921: } else if (!jarOnly
922: && (extension.equalsIgnoreCase(JAR_EXT) || extension
923: .equalsIgnoreCase(EAR_EXT))) {
924: return true;
925: } else
926: return false;
927: }
928:
929: return false;
930: }
931:
932: public String getExtension(File file) {
933: String ext = null;
934: String fileName = file.getName();
935: int index = fileName.lastIndexOf('.');
936:
937: if (index > 0 && index < fileName.length() - 1) {
938: ext = fileName.substring(index + 1).toLowerCase();
939: }
940: return ext;
941: }
942:
943: /** The description of this filter */
944: public String getDescription() {
945: if (jarOnly)
946: return "JAR Files (.jar)";
947: else
948: return "EAR or JAR Files (.ear or .jar)";
949: }
950: }
|