KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > other > AppRootCustomizer


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  * AppRootCustomizer.java
21  *
22  * Created on September 4, 2003, 5:28 PM
23  */

24 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.other;
25
26 import java.beans.Customizer JavaDoc;
27 import java.beans.PropertyVetoException JavaDoc;
28 import java.util.ResourceBundle JavaDoc;
29
30 import javax.swing.JPanel JavaDoc;
31 import javax.swing.DefaultComboBoxModel JavaDoc;
32
33 import org.netbeans.modules.j2ee.sun.share.configbean.AppRoot;
34 import org.netbeans.modules.j2ee.sun.share.configbean.ErrorMessageDB;
35 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.TextMapping;
36 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.CustomizerErrorPanel;
37 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.CustomizerTitlePanel;
38 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.BaseCustomizer;
39
40
41 /**
42  *
43  * @author Peter Williams
44  */

45 public class AppRootCustomizer extends BaseCustomizer {
46     
47     /** Resource bundle */
48     private static final ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(
49         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.other.Bundle"); // NOI18N
50

51     /** xml <--> ui mapping for pass by reference combo box */
52     private static final TextMapping [] passByReferenceValues = {
53         new TextMapping("", ""),
54         new TextMapping("true", commonBundle.getString("LBL_True")),
55         new TextMapping("false", commonBundle.getString("LBL_False"))
56     };
57     
58     private AppRoot theBean;
59     private DefaultComboBoxModel JavaDoc passByReferenceModel;
60     
61     /** Creates new form AppRootCustomizer */
62     public AppRootCustomizer() {
63         initComponents();
64         initUserComponents();
65     }
66     
67     public AppRoot getBean() {
68         return theBean;
69     }
70     
71     /** This method is called from within the constructor to
72      * initialize the form.
73      * WARNING: Do NOT modify this code. The content of this method is
74      * always regenerated by the Form Editor.
75      */

76     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
77
private void initComponents() {
78         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
79
80         jPnlGeneral = new javax.swing.JPanel JavaDoc();
81         jLblPassByReference = new javax.swing.JLabel JavaDoc();
82         jCbxPassByReference = new javax.swing.JComboBox JavaDoc();
83         jLblRealm = new javax.swing.JLabel JavaDoc();
84         jTxtRealm = new javax.swing.JTextField JavaDoc();
85         jLblSecurityHelpText = new javax.swing.JLabel JavaDoc();
86         jPnlModuleMaps = new javax.swing.JPanel JavaDoc();
87
88         setLayout(new java.awt.GridBagLayout JavaDoc());
89
90         jPnlGeneral.setLayout(new java.awt.GridBagLayout JavaDoc());
91
92         jLblPassByReference.setDisplayedMnemonic(bundle.getString("MNC_Pass_By_Reference").charAt(0));
93         jLblPassByReference.setLabelFor(jCbxPassByReference);
94         jLblPassByReference.setText(bundle.getString("LBL_PassByReference_1"));
95         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
96         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
97         jPnlGeneral.add(jLblPassByReference, gridBagConstraints);
98         jLblPassByReference.getAccessibleContext().setAccessibleName(bundle.getString("PassByReference_Acsbl_Name"));
99         jLblPassByReference.getAccessibleContext().setAccessibleDescription(bundle.getString("PassByReference_Acsbl_Desc"));
100
101         jCbxPassByReference.setPrototypeDisplayValue("");
102         jCbxPassByReference.addActionListener(new java.awt.event.ActionListener JavaDoc() {
103             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
104                 jCbxPassByReferenceActionPerformed(evt);
105             }
106         });
107
108         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
109         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
110         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
111         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
112         jPnlGeneral.add(jCbxPassByReference, gridBagConstraints);
113         jCbxPassByReference.getAccessibleContext().setAccessibleName(bundle.getString("PassByReference_Acsbl_Name"));
114         jCbxPassByReference.getAccessibleContext().setAccessibleDescription(bundle.getString("PassByReference_Acsbl_Desc"));
115
116         jLblRealm.setDisplayedMnemonic(bundle.getString("MNC_Realm").charAt(0));
117         jLblRealm.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
118         jLblRealm.setLabelFor(jTxtRealm);
119         jLblRealm.setText(bundle.getString("LBL_Realm_1"));
120         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
121         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
122         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
123         jPnlGeneral.add(jLblRealm, gridBagConstraints);
124         jLblRealm.getAccessibleContext().setAccessibleName(bundle.getString("Realm_Acsbl_Name"));
125         jLblRealm.getAccessibleContext().setAccessibleDescription(bundle.getString("Realm_Acsbl_Desc"));
126
127         jTxtRealm.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
128             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
129                 jTxtRealmKeyReleased(evt);
130             }
131         });
132
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
135         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
136         gridBagConstraints.weightx = 0.75;
137         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
138         jPnlGeneral.add(jTxtRealm, gridBagConstraints);
139         jTxtRealm.getAccessibleContext().setAccessibleName(bundle.getString("Realm_Acsbl_Name"));
140         jTxtRealm.getAccessibleContext().setAccessibleDescription(bundle.getString("Realm_Acsbl_Desc"));
141
142         jLblSecurityHelpText.setText(bundle.getString("LBL_SecurityRoleMappingHelp"));
143         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
144         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
145         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
147         jPnlGeneral.add(jLblSecurityHelpText, gridBagConstraints);
148
149         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
150         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
151         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
152         gridBagConstraints.weightx = 1.0;
153         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 5);
154         add(jPnlGeneral, gridBagConstraints);
155
156         jPnlModuleMaps.setLayout(new java.awt.GridBagLayout JavaDoc());
157
158         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
159         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
160         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
161         gridBagConstraints.weightx = 1.0;
162         gridBagConstraints.weighty = 1.0;
163         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
164         add(jPnlModuleMaps, gridBagConstraints);
165
166     }// </editor-fold>//GEN-END:initComponents
167

168     private void jTxtRealmKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtRealmKeyReleased
169
// Add your handling code here:
170
try {
171             theBean.setRealm(jTxtRealm.getText());
172         } catch(PropertyVetoException JavaDoc ex) {
173             jTxtRealm.setText(theBean.getRealm());
174         }
175     }//GEN-LAST:event_jTxtRealmKeyReleased
176

177     private void jCbxPassByReferenceActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jCbxPassByReferenceActionPerformed
178
// Add your handling code here:
179
TextMapping choice = (TextMapping) passByReferenceModel.getSelectedItem();
180         
181         if(theBean != null) {
182             try {
183                 theBean.setPassByReference(choice.getXMLString());
184             } catch(PropertyVetoException JavaDoc ex) {
185                 passByReferenceModel.setSelectedItem(
186                     getPassByReferenceMapping(theBean.getPassByReference()));
187             }
188         }
189     }//GEN-LAST:event_jCbxPassByReferenceActionPerformed
190

191     // Variables declaration - do not modify//GEN-BEGIN:variables
192
private javax.swing.JComboBox JavaDoc jCbxPassByReference;
193     private javax.swing.JLabel JavaDoc jLblPassByReference;
194     private javax.swing.JLabel JavaDoc jLblRealm;
195     private javax.swing.JLabel JavaDoc jLblSecurityHelpText;
196     private javax.swing.JPanel JavaDoc jPnlGeneral;
197     private javax.swing.JPanel JavaDoc jPnlModuleMaps;
198     private javax.swing.JTextField JavaDoc jTxtRealm;
199     // End of variables declaration//GEN-END:variables
200

201     private void initUserComponents() {
202         // Add title panel
203
addTitlePanel(bundle.getString("LBL_SunApplication")); //NOI18N
204

205         // Set up pass-by-reference combobox
206
passByReferenceModel = new DefaultComboBoxModel JavaDoc();
207         for(int i = 0; i < passByReferenceValues.length; i++) {
208             passByReferenceModel.addElement(passByReferenceValues[i]);
209         }
210         jCbxPassByReference.setModel(passByReferenceModel);
211         
212         // Add error panel
213
addErrorPanel();
214     }
215     
216     /** Initialization of all the fields in the customizer from the bean that
217      * was passed in.
218      */

219     protected void initFields() {
220         passByReferenceModel.setSelectedItem(
221             getPassByReferenceMapping(theBean.getPassByReference()));
222         jTxtRealm.setText(theBean.getRealm());
223     }
224     
225     private TextMapping getPassByReferenceMapping(String JavaDoc xmlKey) {
226         TextMapping result = null;
227         if(xmlKey == null) {
228             xmlKey = ""; // NOI18N
229
}
230         
231         for(int i = 0; i < passByReferenceValues.length; i++) {
232             if(passByReferenceValues[i].getXMLString().compareTo(xmlKey) == 0) {
233                 result = passByReferenceValues[i];
234                 break;
235             }
236         }
237         
238         return result;
239     }
240     
241     protected boolean setBean(Object JavaDoc bean) {
242         boolean result = super.setBean(bean);
243         
244         if(bean instanceof AppRoot) {
245             theBean = (AppRoot) bean;
246             result = true;
247         } else {
248             // if bean is not an AppRoot, then it shouldn't have passed Base either.
249
assert (result == false) :
250                 "AppRootCustomizer was passed wrong bean type in setBean(Object bean)"; // NOI18N
251

252             theBean = null;
253             result = false;
254         }
255         
256         return result;
257     }
258     
259     public String JavaDoc getHelpId() {
260         return "AS_CFG_Application";
261     }
262 }
263
Popular Tags