KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > web > multiview > RunAsPanel


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 package org.netbeans.modules.j2ee.ddloaders.web.multiview;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import javax.swing.DefaultComboBoxModel JavaDoc;
24 import javax.swing.JComboBox JavaDoc;
25 import org.netbeans.modules.j2ee.dd.api.common.SecurityRole;
26 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
27
28 /**
29  * Panel for display the run-as element of the servlet deployment descriptor.
30  * @author ptliu
31  */

32 public class RunAsPanel extends javax.swing.JPanel JavaDoc {
33     private WebApp webApp;
34     
35     /** Creates new form RunAsPanel */
36     public RunAsPanel(final WebApp webApp) {
37         initComponents();
38         
39         this.webApp = webApp;
40         
41         webApp.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
42             public void propertyChange(PropertyChangeEvent JavaDoc event) {
43                 //System.out.println("source = " + event.getSource());
44

45                 Object JavaDoc oldValue = event.getOldValue();
46                 Object JavaDoc newValue = event.getNewValue();
47                 
48                 //System.out.println("oldValue = " + oldValue);
49
//System.out.println("newValue = " + newValue);
50

51                 String JavaDoc selectedItem = (String JavaDoc) 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 JavaDoc[] roleNames = new String JavaDoc[roles.length+1];
65         roleNames[0] = ""; //NOI18N
66

67         for (int i = 0; i < roles.length; i++) {
68             roleNames[i+1] = roles[i].getRoleName();
69         }
70         runAsCB.setModel(new DefaultComboBoxModel JavaDoc(roleNames));
71         
72         runAsCB.setSelectedIndex(0);
73     }
74     
75     public String JavaDoc getRunAs() {
76         return (String JavaDoc) runAsCB.getSelectedItem();
77     }
78     
79     public JComboBox JavaDoc getRunAsCB() {
80         return runAsCB;
81     }
82     
83     /** This method is called from within the constructor to
84      * initialize the form.
85      * WARNING: Do NOT modify this code. The content of this method is
86      * always regenerated by the Form Editor.
87      */

88     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
89
private void initComponents() {
90         runAsLabel = new javax.swing.JLabel JavaDoc();
91         runAsCB = new javax.swing.JComboBox JavaDoc();
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     }// </editor-fold>//GEN-END:initComponents
117

118     
119     // Variables declaration - do not modify//GEN-BEGIN:variables
120
private javax.swing.JComboBox JavaDoc runAsCB;
121     private javax.swing.JLabel JavaDoc runAsLabel;
122     // End of variables declaration//GEN-END:variables
123

124 }
125
Popular Tags