1 19 20 package org.netbeans.modules.j2ee.oc4j.customizer; 21 22 import java.awt.event.ItemEvent ; 23 import java.awt.event.ItemListener ; 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 32 public class OC4JCustomizerUserPanel extends javax.swing.JPanel { 33 34 private InstanceProperties ip; 35 36 37 public OC4JCustomizerUserPanel(final InstanceProperties ip) { 38 this.ip = ip; 39 40 initComponents(); 41 42 setInitValues(); 43 44 usersComboBox.addItemListener(new ItemListener () { 45 public void itemStateChanged(ItemEvent event) { 46 if(!ip.getProperty(InstanceProperties.USERNAME_ATTR).equals(event.getItem())) { 47 ip.setProperty(InstanceProperties.USERNAME_ATTR, (String ) event.getItem()); 48 changePassword(); 49 } 50 } 51 }); 52 } 53 54 private void setInitValues() { 55 String j2eeLocalHome = ip.getProperty(OC4JPluginProperties.PROPERTY_OC4J_HOME); 56 57 for (String 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 username = ip.getProperty(InstanceProperties.USERNAME_ATTR); 73 String password = OC4JPluginUtils.requestPassword(username); 74 75 if(password != null) 76 ip.setProperty(InstanceProperties.PASSWORD_ATTR, password); 77 } 78 79 84 private void initComponents() { 86 87 userLabel = new javax.swing.JLabel (); 88 usersComboBox = new javax.swing.JComboBox (); 89 changeButton = new javax.swing.JButton (); 90 91 userLabel.setText(org.openide.util.NbBundle.getMessage(OC4JCustomizerUserPanel.class, "LBL_UserPanel")); 93 changeButton.setText(org.openide.util.NbBundle.getMessage(OC4JCustomizerUserPanel.class, "LBL_UserChange")); changeButton.addActionListener(new java.awt.event.ActionListener () { 95 public void actionPerformed(java.awt.event.ActionEvent 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 } 127 private void changeButtonActionPerformed(java.awt.event.ActionEvent evt) { changePassword(); 129 } 131 private javax.swing.JButton changeButton; 133 private javax.swing.JLabel userLabel; 134 private javax.swing.JComboBox usersComboBox; 135 137 } 138 | Popular Tags |