1 19 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 20 21 import java.beans.PropertyChangeEvent ; 22 import java.beans.PropertyChangeListener ; 23 import javax.swing.DefaultComboBoxModel ; 24 import javax.swing.JComboBox ; 25 import org.netbeans.modules.j2ee.dd.api.common.SecurityRole; 26 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 27 28 32 public class RunAsPanel extends javax.swing.JPanel { 33 private WebApp webApp; 34 35 36 public RunAsPanel(final WebApp webApp) { 37 initComponents(); 38 39 this.webApp = webApp; 40 41 webApp.addPropertyChangeListener(new PropertyChangeListener () { 42 public void propertyChange(PropertyChangeEvent event) { 43 45 Object oldValue = event.getOldValue(); 46 Object newValue = event.getNewValue(); 47 48 51 String selectedItem = (String ) runAsCB.getSelectedItem(); 52 if (oldValue instanceof SecurityRole || 53 newValue instanceof SecurityRole) { 54 initModel(webApp.getSecurityRole()); 55 } 56 runAsCB.setSelectedItem(selectedItem); 57 } 58 }); 59 60 initModel(webApp.getSecurityRole()); 61 } 62 63 private void initModel(SecurityRole[] roles) { 64 String [] roleNames = new String [roles.length+1]; 65 roleNames[0] = ""; 67 for (int i = 0; i < roles.length; i++) { 68 roleNames[i+1] = roles[i].getRoleName(); 69 } 70 runAsCB.setModel(new DefaultComboBoxModel (roleNames)); 71 72 runAsCB.setSelectedIndex(0); 73 } 74 75 public String getRunAs() { 76 return (String ) runAsCB.getSelectedItem(); 77 } 78 79 public JComboBox getRunAsCB() { 80 return runAsCB; 81 } 82 83 88 private void initComponents() { 90 runAsLabel = new javax.swing.JLabel (); 91 runAsCB = new javax.swing.JComboBox (); 92 93 setOpaque(false); 94 runAsLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_runAs_mnem").charAt(0)); 95 runAsLabel.setLabelFor(runAsCB); 96 runAsLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_RunAs")); 97 98 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 99 this.setLayout(layout); 100 layout.setHorizontalGroup( 101 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 102 .add(layout.createSequentialGroup() 103 .add(runAsLabel) 104 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 105 .add(runAsCB, 0, 358, Short.MAX_VALUE)) 106 ); 107 layout.setVerticalGroup( 108 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 109 .add(layout.createSequentialGroup() 110 .addContainerGap() 111 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 112 .add(runAsLabel) 113 .add(runAsCB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 114 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 115 ); 116 } 118 119 private javax.swing.JComboBox runAsCB; 121 private javax.swing.JLabel runAsLabel; 122 124 } 125 | Popular Tags |