KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > customizer > OC4JCustomizerUserPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.oc4j.customizer;
21
22 import java.awt.event.ItemEvent JavaDoc;
23 import java.awt.event.ItemListener JavaDoc;
24 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
25 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginProperties;
26 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginUtils;
27
28 /**
29  *
30  * @author Michal Mocnak
31  */

32 public class OC4JCustomizerUserPanel extends javax.swing.JPanel JavaDoc {
33     
34     private InstanceProperties ip;
35     
36     /** Creates new form OC4JCustomizerUserPanel */
37     public OC4JCustomizerUserPanel(final InstanceProperties ip) {
38         this.ip = ip;
39         
40         initComponents();
41         
42         setInitValues();
43         
44         usersComboBox.addItemListener(new ItemListener JavaDoc() {
45             public void itemStateChanged(ItemEvent JavaDoc event) {
46                 if(!ip.getProperty(InstanceProperties.USERNAME_ATTR).equals(event.getItem())) {
47                     ip.setProperty(InstanceProperties.USERNAME_ATTR, (String JavaDoc) event.getItem());
48                     changePassword();
49                 }
50             }
51         });
52     }
53     
54     private void setInitValues() {
55         String JavaDoc j2eeLocalHome = ip.getProperty(OC4JPluginProperties.PROPERTY_OC4J_HOME);
56         
57         for (String JavaDoc item : OC4JPluginUtils.getUsers(j2eeLocalHome)) {
58             usersComboBox.addItem(item);
59         }
60         
61         if (OC4JPluginUtils.isLocalServer(ip)) {
62             usersComboBox.setEditable(false);
63         } else {
64             usersComboBox.addItem(ip.getProperty(InstanceProperties.USERNAME_ATTR));
65             usersComboBox.setEditable(true);
66         }
67         
68         usersComboBox.setSelectedItem(ip.getProperty(InstanceProperties.USERNAME_ATTR));
69     }
70     
71     private void changePassword() {
72         String JavaDoc username = ip.getProperty(InstanceProperties.USERNAME_ATTR);
73         String JavaDoc password = OC4JPluginUtils.requestPassword(username);
74         
75         if(password != null)
76             ip.setProperty(InstanceProperties.PASSWORD_ATTR, password);
77     }
78     
79     /** This method is called from within the constructor to
80      * initialize the form.
81      * WARNING: Do NOT modify this code. The content of this method is
82      * always regenerated by the Form Editor.
83      */

84     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
85
private void initComponents() {
86
87         userLabel = new javax.swing.JLabel JavaDoc();
88         usersComboBox = new javax.swing.JComboBox JavaDoc();
89         changeButton = new javax.swing.JButton JavaDoc();
90
91         userLabel.setText(org.openide.util.NbBundle.getMessage(OC4JCustomizerUserPanel.class, "LBL_UserPanel")); // NOI18N
92

93         changeButton.setText(org.openide.util.NbBundle.getMessage(OC4JCustomizerUserPanel.class, "LBL_UserChange")); // NOI18N
94
changeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
95             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
96                 changeButtonActionPerformed(evt);
97             }
98         });
99
100         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
101         this.setLayout(layout);
102         layout.setHorizontalGroup(
103             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
104             .add(layout.createSequentialGroup()
105                 .addContainerGap()
106                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
107                     .add(userLabel)
108                     .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
109                         .add(usersComboBox, 0, 199, Short.MAX_VALUE)
110                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
111                         .add(changeButton)))
112                 .addContainerGap())
113         );
114         layout.setVerticalGroup(
115             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
116             .add(layout.createSequentialGroup()
117                 .addContainerGap()
118                 .add(userLabel)
119                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
120                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
121                     .add(changeButton)
122                     .add(usersComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
123                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
124         );
125     }// </editor-fold>//GEN-END:initComponents
126

127 private void changeButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_changeButtonActionPerformed
128
changePassword();
129 }//GEN-LAST:event_changeButtonActionPerformed
130

131     // Variables declaration - do not modify//GEN-BEGIN:variables
132
private javax.swing.JButton JavaDoc changeButton;
133     private javax.swing.JLabel JavaDoc userLabel;
134     private javax.swing.JComboBox JavaDoc usersComboBox;
135     // End of variables declaration//GEN-END:variables
136

137 }
138
Popular Tags