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: package org.netbeans.modules.j2ee.websphere6.ui;
042:
043: import java.util.Vector;
044: import java.awt.event.*;
045: import javax.swing.*;
046: import org.openide.util.NbBundle;
047: import org.netbeans.modules.j2ee.websphere6.ui.InstancesModel;
048: import org.netbeans.modules.j2ee.websphere6.WSURIManager;
049: import org.netbeans.modules.j2ee.websphere6.j2ee.DeploymentManagerProperties;
050: import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
051: import org.openide.awt.Mnemonics;
052:
053: /**
054: *
055: * @author dlm198383
056: */
057: public class ConnectionTabVisualPanel extends javax.swing.JPanel {
058:
059: private final DeploymentManagerProperties targetData;
060:
061: /** Creates new form ConnectionTabVisualPanel */
062: public class TabServerProperties extends ServerProperties {
063: public TabServerProperties() {
064: super ();
065: }
066:
067: public TabServerProperties(JComboBox serverCombobox,
068: JComboBox localInstancesCombobox,
069: JTextField domainPathField, JTextField hostField,
070: JTextField portField) {
071: super (serverCombobox, localInstancesCombobox,
072: domainPathField, hostField, portField);
073: }
074:
075: public class TabServerTypeActionListener extends
076: ServerTypeActionListener {
077: public void actionPerformed(ActionEvent e) {
078: super .actionPerformed(e);
079: isValid();
080: }
081: }
082: }
083:
084: TabServerProperties tabServerProperties = null;
085:
086: public ConnectionTabVisualPanel(DeploymentManagerProperties data) {
087: this .targetData = data;
088: initComponents();
089: tabServerProperties = new TabServerProperties(serverTypeCombo,
090: localInstancesCombo, profilePathField, hostField,
091: portField);
092: InstanceProperties ips = targetData.getInstanceProperties();
093: ips.refreshServerInstance();
094: String url = ips.getProperty(InstanceProperties.URL_ATTR);
095: url = WSURIManager.getUrlWithoutPrefix(url);
096:
097: localInstancesCombo.setModel(new InstancesModel(
098: tabServerProperties.getServerInstances(targetData
099: .getServerRoot())));
100: for (int i = 0; i < localInstancesCombo.getModel().getSize(); i++) {
101: if (((Instance) localInstancesCombo.getItemAt(i))
102: .getDomainPath().equals(targetData.getDomainRoot())) {
103: localInstancesCombo.setSelectedIndex(i);
104: break;
105: }
106: }
107:
108: //localInstancesCombo.addActionListener(tabServerProperties.getInstanceSelectionListener());
109:
110: int index = url.indexOf(":");
111: String host = null;
112: if (index > -1) {
113: host = url.substring(0, index);
114: }
115:
116: hostField.setText(host);
117:
118: userNameField.setText(targetData.getUserName());
119: userNameField.addKeyListener(new java.awt.event.KeyAdapter() {
120: public void keyReleased(java.awt.event.KeyEvent evt) {
121: String userName = userNameField.getText();
122: targetData.setUserName(userName);
123: }
124: });
125:
126: passwordField.setText(targetData.getPassword());
127: passwordField.addKeyListener(new java.awt.event.KeyAdapter() {
128: public void keyReleased(java.awt.event.KeyEvent evt) {
129: String password = new String(passwordField
130: .getPassword());
131: targetData.setPassword(password);
132: }
133: });
134:
135: //domainField.setText(targetData.getDomainName());
136: profilePathField.setText(targetData.getDomainRoot());
137: portField.setText(targetData.getPort());
138: //portField.setModel(new SpinnerNumberModel(0,0,65535,1));
139: //portField.setValue(new Integer(targetData.getPort()));
140: /*
141: portField.addChangeListener(new javax.swing.event.ChangeListener() {
142: public void stateChanged(javax.swing.event.ChangeEvent e) {
143: String port = portField.getValue().toString();
144:
145: if(!port.trim().matches("[0-9]+")){
146: portField.setValue(new Integer(targetData.getPort()));
147: } else {
148: targetData.setPort(port);
149: }
150: }
151: });
152: */
153: /*
154: portField.addKeyListener(new java.awt.event.KeyAdapter() {
155: public void keyReleased(java.awt.event.KeyEvent evt) {
156: //String port = portField.getValue().toString();
157: String port = portField.getText();
158: if(!port.trim().matches("[0-9]+")){
159: //portField.setValue(new Integer(targetData.getPort()));
160: portField.setText(targetData.getPort());
161: } else if((new java.lang.Integer(port)).intValue() > 65535) {
162: portField.setText(targetData.getPort());
163: } else {
164: targetData.setPort(port);
165: }
166: }
167: public void keyPressed(java.awt.event.KeyEvent evt) {
168: //String port = portField.getValue().toString();
169: String port = portField.getText();
170: if(!port.trim().matches("[0-9]+")){
171: //portField.setValue(new Integer(targetData.getPort()));
172: portField.setText(targetData.getPort());
173: } else if((new java.lang.Integer(port)).intValue() > 65535) {
174: portField.setText(targetData.getPort());
175: } else {
176: targetData.setPort(port);
177: }
178: }
179: });
180: */
181:
182: /*serverTypeCombo.addItem(NbBundle.getMessage(ConnectionTabVisualPanel.class, "TXT_serverTypeLocal"));
183: serverTypeCombo.addItem(NbBundle.getMessage(ConnectionTabVisualPanel.class,"TXT_serverTypeRemote"));
184: */
185: Vector types = new Vector();
186: types.add(NbBundle.getMessage(ConnectionTabVisualPanel.class,
187: "TXT_ServerTypeLocal"));
188: types.add(NbBundle.getMessage(ConnectionTabVisualPanel.class,
189: "TXT_ServerTypeRemote"));
190: serverTypeCombo.setModel(new InstancesModel(types));
191:
192: //serverTypeCombo.addActionListener(tabServerProperties.getServerTypeActionListener());
193:
194: /*
195: serverTypeCombo.addItemListener(new java.awt.event.ItemListener() {
196: public void itemStateChanged(java.awt.event.ItemEvent e) {
197: if (serverTypeCombo.getSelectedItem().equals(NbBundle.
198: getMessage(ServerProperties.class,
199: "TXT_serverTypeLocal"))) {
200: targetData.setIsLocal(targetData.getIsLocal().equals("true")?"false":"true");
201: }
202: }
203:
204: }
205: );*/
206:
207: portField.setEditable(false);
208: //portField.setEnabled(false);
209: hostField.setEditable(false);
210:
211: serverTypeCombo
212: .setSelectedItem(targetData.isLocal() ? NbBundle
213: .getMessage(ConnectionTabVisualPanel.class,
214: "TXT_ServerTypeLocal") : NbBundle
215: .getMessage(ConnectionTabVisualPanel.class,
216: "TXT_ServerTypeRemote"));
217:
218: //setName(NbBundle.getMessage(ConnectionTabVisualPanel.class, "TITLE_AddUserDefinedLocalServerPanel"));
219:
220: setMnemonics(jLabel1);
221: setMnemonics(jLabel2);
222: setMnemonics(jLabel3);
223: setMnemonics(jLabel4);
224: setMnemonics(jLabel5);
225: setMnemonics(jLabel6);
226: setMnemonics(jLabel7);
227:
228: }
229:
230: private void setMnemonics(JLabel label) {
231: String name = label.getText();
232: int index = Mnemonics.findMnemonicAmpersand(name);
233: if (index < 0) {
234: Mnemonics.setLocalizedText(label, name);
235: label.setDisplayedMnemonic(name.charAt(0));
236: } else {
237: Mnemonics.setLocalizedText(label, name.substring(0, index)
238: + name.substring(index + 1));
239: label.setDisplayedMnemonic(name.charAt(index + 1));
240: }
241: }
242:
243: /**
244: * Checks whether the specified path is the valid domain root directory.
245: *
246: * @return true if the path is the valid domain root, false otherwise
247: */
248: public boolean isValid() {
249:
250: // if the server instance is local, then check the profile root
251: // directory for validity
252: if (serverTypeCombo.getSelectedItem().equals(
253: NbBundle.getMessage(ConnectionTabVisualPanel.class,
254: "TXT_ServerTypeLocal"))) { // NOI18N
255: if (!tabServerProperties.isValidDomainRoot(profilePathField
256: .getText())) {
257: JOptionPane.showMessageDialog(null, NbBundle
258: .getMessage(ConnectionTabVisualPanel.class,
259: "ERR_InvalidDomainRoot")); // NOI18N
260: return false;
261: }
262: }
263:
264: // check the host field (not empty)
265: if (hostField.getText().trim().equals("")) {
266: JOptionPane.showMessageDialog(null, NbBundle.getMessage(
267: ConnectionTabVisualPanel.class, "ERR_InvalidHost")); // NOI18N
268: return false;
269: }
270:
271: // check the port field (not empty and a positive integer)
272: //if (!portField.getText().trim().matches("[0-9]+")) {
273: //if (!portField.getValue().toString().trim().matches("[0-9]+")) {
274: if (!portField.getText().trim().matches("[0-9]+")) {
275: JOptionPane.showMessageDialog(null, NbBundle.getMessage(
276: ConnectionTabVisualPanel.class, "ERR_InvalidPort")); // NOI18N
277: return false;
278: }
279:
280: // no checks for username & password as they may be intentionally blank
281:
282: // save the data to the parent instantiating iterator
283:
284: targetData.setDomainRoot(profilePathField.getText());
285: targetData.setHost(hostField.getText());
286: //targetData.setPort(portField.getValue().toString());
287: targetData.setPort(portField.getText());
288: targetData.setUserName(userNameField.getText());
289: targetData.setPassword(new String(passwordField.getPassword()));
290:
291: targetData.setIsLocal(serverTypeCombo.getSelectedItem().equals(
292: NbBundle.getMessage(ConnectionTabVisualPanel.class,
293: "TXT_ServerTypeLocal")) ? "true" : "false"); // NOI18N
294:
295: targetData.setServerName(((Instance) localInstancesCombo
296: .getSelectedItem()).getName());
297: targetData.setConfigXmlPath(((Instance) localInstancesCombo
298: .getSelectedItem()).getConfigXmlPath());
299:
300: targetData.getInstanceProperties().refreshServerInstance();
301: // everything seems ok
302: return true;
303: }
304:
305: /** This method is called from within the constructor to
306: * initialize the form.
307: * WARNING: Do NOT modify this code. The content of this method is
308: * always regenerated by the Form Editor.
309: */
310: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
311: private void initComponents() {
312:
313: jLabel2 = new javax.swing.JLabel();
314: serverTypeCombo = new javax.swing.JComboBox();
315: jLabel3 = new javax.swing.JLabel();
316: localInstancesCombo = new javax.swing.JComboBox();
317: jLabel4 = new javax.swing.JLabel();
318: jLabel5 = new javax.swing.JLabel();
319: hostField = new javax.swing.JTextField();
320: jLabel6 = new javax.swing.JLabel();
321: jLabel7 = new javax.swing.JLabel();
322: userNameField = new javax.swing.JTextField();
323: passwordField = new javax.swing.JPasswordField();
324: profilePathField = new javax.swing.JTextField();
325: jLabel1 = new javax.swing.JLabel();
326: portField = new javax.swing.JTextField();
327:
328: jLabel2.setLabelFor(serverTypeCombo);
329: java.util.ResourceBundle bundle = java.util.ResourceBundle
330: .getBundle("org/netbeans/modules/j2ee/websphere6/ui/Bundle"); // NOI18N
331: org.openide.awt.Mnemonics.setLocalizedText(jLabel2, bundle
332: .getString("LBL_LocalRemote")); // NOI18N
333:
334: serverTypeCombo.setEnabled(false);
335:
336: jLabel3.setLabelFor(localInstancesCombo);
337: jLabel3.setText(bundle.getString("LBL_LocalInstances")); // NOI18N
338:
339: localInstancesCombo.setEnabled(false);
340:
341: jLabel4.setLabelFor(hostField);
342: jLabel4.setText(bundle.getString("LBL_Host")); // NOI18N
343:
344: jLabel5.setLabelFor(portField);
345: jLabel5.setText(bundle.getString("LBL_Port")); // NOI18N
346:
347: hostField.setEditable(false);
348:
349: jLabel6.setLabelFor(userNameField);
350: jLabel6.setText(bundle.getString("LBL_Username")); // NOI18N
351:
352: jLabel7.setLabelFor(passwordField);
353: jLabel7.setText(bundle.getString("LBL_Password")); // NOI18N
354:
355: profilePathField.setEditable(false);
356:
357: jLabel1.setLabelFor(profilePathField);
358: jLabel1.setText(bundle.getString("LBL_ProfilePath")); // NOI18N
359:
360: portField.setEditable(false);
361: portField.addFocusListener(new java.awt.event.FocusAdapter() {
362: public void focusLost(java.awt.event.FocusEvent evt) {
363: portFieldFocusLost(evt);
364: }
365: });
366:
367: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
368: this );
369: this .setLayout(layout);
370: layout
371: .setHorizontalGroup(layout
372: .createParallelGroup(
373: org.jdesktop.layout.GroupLayout.LEADING)
374: .add(
375: layout
376: .createSequentialGroup()
377: .add(
378: layout
379: .createParallelGroup(
380: org.jdesktop.layout.GroupLayout.LEADING)
381: .add(
382: layout
383: .createSequentialGroup()
384: .add(
385: layout
386: .createParallelGroup(
387: org.jdesktop.layout.GroupLayout.LEADING)
388: .add(
389: layout
390: .createSequentialGroup()
391: .addContainerGap()
392: .add(
393: jLabel3))
394: .add(
395: layout
396: .createSequentialGroup()
397: .addContainerGap()
398: .add(
399: jLabel1))
400: .add(
401: layout
402: .createSequentialGroup()
403: .addContainerGap()
404: .add(
405: jLabel4))
406: .add(
407: layout
408: .createSequentialGroup()
409: .addContainerGap()
410: .add(
411: jLabel5))
412: .add(
413: layout
414: .createSequentialGroup()
415: .addContainerGap()
416: .add(
417: jLabel6))
418: .add(
419: layout
420: .createSequentialGroup()
421: .addContainerGap()
422: .add(
423: jLabel7)))
424: .add(
425: 12,
426: 12,
427: 12)
428: .add(
429: layout
430: .createParallelGroup(
431: org.jdesktop.layout.GroupLayout.LEADING)
432: .add(
433: serverTypeCombo,
434: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
435: 90,
436: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
437: .add(
438: profilePathField,
439: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
440: 387,
441: Short.MAX_VALUE)
442: .add(
443: hostField,
444: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
445: 387,
446: Short.MAX_VALUE)
447: .add(
448: localInstancesCombo,
449: 0,
450: 387,
451: Short.MAX_VALUE)
452: .add(
453: layout
454: .createParallelGroup(
455: org.jdesktop.layout.GroupLayout.TRAILING,
456: false)
457: .add(
458: org.jdesktop.layout.GroupLayout.LEADING,
459: portField)
460: .add(
461: org.jdesktop.layout.GroupLayout.LEADING,
462: passwordField)
463: .add(
464: org.jdesktop.layout.GroupLayout.LEADING,
465: userNameField,
466: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
467: 117,
468: Short.MAX_VALUE))))
469: .add(
470: layout
471: .createSequentialGroup()
472: .addContainerGap()
473: .add(
474: jLabel2)))
475: .addContainerGap()));
476: layout
477: .setVerticalGroup(layout
478: .createParallelGroup(
479: org.jdesktop.layout.GroupLayout.LEADING)
480: .add(
481: layout
482: .createSequentialGroup()
483: .addContainerGap()
484: .add(
485: layout
486: .createParallelGroup(
487: org.jdesktop.layout.GroupLayout.BASELINE)
488: .add(jLabel2)
489: .add(
490: serverTypeCombo,
491: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
492: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
493: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
494: .addPreferredGap(
495: org.jdesktop.layout.LayoutStyle.RELATED)
496: .add(
497: layout
498: .createParallelGroup(
499: org.jdesktop.layout.GroupLayout.BASELINE)
500: .add(jLabel3)
501: .add(
502: localInstancesCombo,
503: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
504: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
505: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
506: .addPreferredGap(
507: org.jdesktop.layout.LayoutStyle.RELATED)
508: .add(
509: layout
510: .createParallelGroup(
511: org.jdesktop.layout.GroupLayout.BASELINE)
512: .add(jLabel1)
513: .add(
514: profilePathField,
515: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
516: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
517: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
518: .addPreferredGap(
519: org.jdesktop.layout.LayoutStyle.RELATED)
520: .add(
521: layout
522: .createParallelGroup(
523: org.jdesktop.layout.GroupLayout.BASELINE)
524: .add(jLabel4)
525: .add(
526: hostField,
527: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
528: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
529: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
530: .addPreferredGap(
531: org.jdesktop.layout.LayoutStyle.RELATED)
532: .add(
533: layout
534: .createParallelGroup(
535: org.jdesktop.layout.GroupLayout.BASELINE)
536: .add(jLabel5)
537: .add(
538: portField,
539: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
540: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
541: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
542: .addPreferredGap(
543: org.jdesktop.layout.LayoutStyle.RELATED)
544: .add(
545: layout
546: .createParallelGroup(
547: org.jdesktop.layout.GroupLayout.BASELINE)
548: .add(jLabel6)
549: .add(
550: userNameField,
551: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
552: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
553: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
554: .addPreferredGap(
555: org.jdesktop.layout.LayoutStyle.RELATED)
556: .add(
557: layout
558: .createParallelGroup(
559: org.jdesktop.layout.GroupLayout.BASELINE)
560: .add(jLabel7)
561: .add(
562: passwordField,
563: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
564: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
565: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
566: .addContainerGap()));
567:
568: serverTypeCombo.getAccessibleContext().setAccessibleName(
569: bundle.getString("TTL_AccessMethod")); // NOI18N
570: serverTypeCombo
571: .getAccessibleContext()
572: .setAccessibleDescription(
573: bundle.getString("MSG_AccessMethodDescription")); // NOI18N
574: jLabel3.getAccessibleContext().setAccessibleName(
575: "Local Instances Label");
576: localInstancesCombo.getAccessibleContext().setAccessibleName(
577: bundle.getString("TTL_LocalInstances")); // NOI18N
578: localInstancesCombo.getAccessibleContext()
579: .setAccessibleDescription(
580: bundle.getString("MSG_LocalInstances")); // NOI18N
581: jLabel4.getAccessibleContext().setAccessibleName("Host Label");
582: jLabel5.getAccessibleContext().setAccessibleName("Port Label");
583: hostField.getAccessibleContext().setAccessibleName(
584: bundle.getString("TTL_Host")); // NOI18N
585: hostField.getAccessibleContext().setAccessibleDescription(
586: bundle.getString("MSG_Host")); // NOI18N
587: jLabel6.getAccessibleContext().setAccessibleName(
588: "Username Label");
589: jLabel7.getAccessibleContext().setAccessibleName(
590: "Password Label");
591: userNameField.getAccessibleContext().setAccessibleName(
592: bundle.getString("TTL_Username")); // NOI18N
593: userNameField.getAccessibleContext().setAccessibleDescription(
594: bundle.getString("MSG_Username")); // NOI18N
595: passwordField.getAccessibleContext().setAccessibleName(
596: bundle.getString("TTL_Password")); // NOI18N
597: passwordField.getAccessibleContext().setAccessibleDescription(
598: bundle.getString("MSG_Password")); // NOI18N
599: profilePathField.getAccessibleContext().setAccessibleName(
600: bundle.getString("TTL_ProfilePath")); // NOI18N
601: profilePathField.getAccessibleContext()
602: .setAccessibleDescription(
603: bundle.getString("MSG_ProfilePath")); // NOI18N
604: portField.getAccessibleContext().setAccessibleName(
605: bundle.getString("TTL_Port")); // NOI18N
606: portField.getAccessibleContext().setAccessibleDescription(
607: bundle.getString("MSG_Port")); // NOI18N
608: }// </editor-fold>//GEN-END:initComponents
609:
610: private void portFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_portFieldFocusLost
611: String port = portField.getText();
612: if (!port.trim().matches("[0-9]+")) {
613: JOptionPane.showMessageDialog(portField, NbBundle
614: .getMessage(ConnectionTabVisualPanel.class,
615: "ERR_InvalidPort"));
616: } else if ((new java.lang.Integer(port)).intValue() > 65535) {
617: JOptionPane.showMessageDialog(portField, NbBundle
618: .getMessage(ConnectionTabVisualPanel.class,
619: "ERR_InvalidPort"));
620: } else {
621: targetData.setPort(port);
622: }
623: }//GEN-LAST:event_portFieldFocusLost
624:
625: // Variables declaration - do not modify//GEN-BEGIN:variables
626: private javax.swing.JTextField hostField;
627: private javax.swing.JLabel jLabel1;
628: private javax.swing.JLabel jLabel2;
629: private javax.swing.JLabel jLabel3;
630: private javax.swing.JLabel jLabel4;
631: private javax.swing.JLabel jLabel5;
632: private javax.swing.JLabel jLabel6;
633: private javax.swing.JLabel jLabel7;
634: private javax.swing.JComboBox localInstancesCombo;
635: private javax.swing.JPasswordField passwordField;
636: private javax.swing.JTextField portField;
637: private javax.swing.JTextField profilePathField;
638: private javax.swing.JComboBox serverTypeCombo;
639: private javax.swing.JTextField userNameField;
640:
641: // End of variables declaration//GEN-END:variables
642:
643: /**
644: * A listener that reacts to the change of the server type combobox,
645: * is the local server type is selected we should disable several fields
646: * and enable some others instead.
647: *
648: * @author Kirill Sorokin, edited by Dmitry Lipin
649: */
650: private class ServerTypeActionListener implements ActionListener {
651: /**
652: * The main action handler. This method is called when the combobox
653: * value changes
654: */
655:
656: public void actionPerformed(ActionEvent e) {
657: // if the selected type is local
658: if (serverTypeCombo.getSelectedItem().equals(
659: NbBundle.getMessage(ServerProperties.class,
660: "TXT_ServerTypeLocal"))) { // NOI18N
661: Instance instance = (Instance) localInstancesCombo
662: .getSelectedItem();
663:
664: // enable the local instances combo
665: localInstancesCombo.setEnabled(true);
666:
667: // enable and set as read-only the domain path field
668: profilePathField.setEnabled(true);
669: profilePathField.setEditable(false);
670:
671: // enable and set as read-only the host field
672: hostField.setEnabled(true);
673: hostField.setEditable(false);
674: hostField.setText(instance.getHost());
675:
676: // enable and set as read-only the port field
677: //portField.setEnabled(true);
678: //portField.setEditable(false);
679: //portField.setText(instance.getPort());
680: portField.setEnabled(true);
681: portField.setEditable(false);
682: //portField.setValue(new Integer(instance.getPort()));
683: portField.setText(instance.getPort());
684:
685: } else {
686: // disable the local instances combo
687: localInstancesCombo.setEnabled(false);
688:
689: // disable the domain path field
690: profilePathField.setEnabled(false);
691: profilePathField.setEditable(false);
692:
693: // enable and set as read-write the host field
694: hostField.setEnabled(true);
695: hostField.setEditable(false);
696:
697: // enable and set as read-write the port field
698: portField.setEnabled(true);
699: portField.setEditable(true);
700: //portField.setEditable(true);
701: }
702:
703: isValid();
704: }
705: }
706:
707: /**
708: * Updates the local instances combobox model with the fresh local
709: * instances list
710: */
711: public void updateInstancesList() {
712: localInstancesCombo.setModel(new InstancesModel(
713: tabServerProperties.getServerInstances(targetData
714: .getServerRoot())));
715: updateInstanceInfo();
716: }
717:
718: /**
719: * Updates the selected local instance information, i.e. profile path,
720: * host, port.
721: */
722: private void updateInstanceInfo() {
723: // get the selected local instance
724: Instance instance = (Instance) localInstancesCombo
725: .getSelectedItem();
726:
727: // set the fields' values
728: profilePathField.setText(instance.getDomainPath());
729: hostField.setText(instance.getHost());
730: //portField.setValue(new Integer(instance.getPort()));
731: portField.setText(instance.getPort());
732: }
733:
734: /**
735: * A simple listeners that reacts to user's selectin a local instance. It
736: * updates the selected instance info.
737: *
738: * @author Kirill Sorokin
739: */
740: private class InstanceSelectionListener implements ActionListener {
741: /**
742: * The main action handler. This method is called when a new local
743: * instance is selected
744: */
745: public void actionPerformed(ActionEvent e) {
746: updateInstanceInfo();
747: }
748: }
749:
750: }
|