KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

46 public class ResourceEnvRefCustomizer extends BaseCustomizer implements PropertyChangeListener JavaDoc {
47     
48     private static final ResourceBundle JavaDoc customizerBundle = ResourceBundle.getBundle(
49         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.Bundle"); // NOI18N
50

51     private ResourceEnvRef theBean;
52     
53     /** Creates new form ResourceEnvRefCustomizer */
54     public ResourceEnvRefCustomizer() {
55         initComponents();
56         initUserComponents();
57     }
58     
59     /** This method is called from within the constructor to
60      * initialize the form.
61      * WARNING: Do NOT modify this code. The content of this method is
62      * always regenerated by the Form Editor.
63      */

64     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
65
private void initComponents() {
66         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
67
68         jPanel1 = new javax.swing.JPanel JavaDoc();
69         jLblName = new javax.swing.JLabel JavaDoc();
70         jTxtName = new javax.swing.JTextField JavaDoc();
71         jLblJndiName = new javax.swing.JLabel JavaDoc();
72         jTxtJndiName = new javax.swing.JTextField JavaDoc();
73
74         setLayout(new java.awt.GridBagLayout JavaDoc());
75
76         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
77
78         jLblName.setLabelFor(jTxtName);
79         jLblName.setText(customizerBundle.getString("LBL_ResourceEnvReferenceName_1"));
80         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
81         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
82         gridBagConstraints.ipady = 4;
83         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
84         jPanel1.add(jLblName, gridBagConstraints);
85
86         jTxtName.setEditable(false);
87         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
88         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
89         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
90         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
91         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
92         jPanel1.add(jTxtName, gridBagConstraints);
93         jTxtName.getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_ResourceEnvReferenceName"));
94         jTxtName.getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_ResourceEnvReferenceName"));
95
96         jLblJndiName.setLabelFor(jTxtJndiName);
97         jLblJndiName.setText(customizerBundle.getString("LBL_JNDIName_1"));
98         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
99         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
100         gridBagConstraints.ipady = 4;
101         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
102         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
103         jPanel1.add(jLblJndiName, gridBagConstraints);
104
105         jTxtJndiName.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
106             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
107                 jTxtJndiNameKeyReleased(evt);
108             }
109         });
110
111         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
112         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
113         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
114         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
115         gridBagConstraints.weightx = 1.0;
116         gridBagConstraints.weighty = 1.0;
117         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
118         jPanel1.add(jTxtJndiName, gridBagConstraints);
119         jTxtJndiName.getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_JNDIName"));
120         jTxtJndiName.getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_JNDIName"));
121
122         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
123         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
124         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
125         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
126         gridBagConstraints.weightx = 1.0;
127         gridBagConstraints.weighty = 1.0;
128         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 5, 5);
129         add(jPanel1, gridBagConstraints);
130
131     }// </editor-fold>//GEN-END:initComponents
132

133     private void jTxtJndiNameKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtJndiNameKeyReleased
134
if(theBean != null) {
135             String JavaDoc oldJndiName = theBean.getJndiName();
136             try {
137                 String JavaDoc newJndiName = jTxtJndiName.getText().trim();
138                 if(!newJndiName.equals(oldJndiName)) {
139                     theBean.setJndiName(newJndiName);
140                     validateField(ResourceEnvRef.FIELD_JNDI_NAME);
141                 }
142             } catch(PropertyVetoException JavaDoc ex) {
143                 jTxtJndiName.setText(oldJndiName);
144             }
145         }
146     }//GEN-LAST:event_jTxtJndiNameKeyReleased
147

148     // Variables declaration - do not modify//GEN-BEGIN:variables
149
private javax.swing.JLabel JavaDoc jLblJndiName;
150     private javax.swing.JLabel JavaDoc jLblName;
151     private javax.swing.JPanel JavaDoc jPanel1;
152     private javax.swing.JTextField JavaDoc jTxtJndiName;
153     private javax.swing.JTextField JavaDoc jTxtName;
154     // End of variables declaration//GEN-END:variables
155

156     private void initUserComponents() {
157         // Add title panel
158
addTitlePanel(customizerBundle.getString("TITLE_ResourceEnvReference")); // NOI18N
159
getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_ResourceEnvReference")); // NOI18N
160
getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_ResourceEnvReference")); // NOI18N
161

162         // Add error panel
163
addErrorPanel();
164     }
165     
166     protected void initFields() {
167         jTxtName.setText(theBean.getResourceEnvRefName());
168         jTxtJndiName.setText(theBean.getJndiName());
169     }
170
171     public void propertyChange(PropertyChangeEvent JavaDoc propertyChangeEvent) {
172         String JavaDoc eventName = propertyChangeEvent.getPropertyName();
173         
174         if(ResourceEnvRef.RESOURCE_ENV_REF_NAME.equals(eventName)) {
175             jTxtName.setText(theBean.getResourceEnvRefName());
176         }
177     }
178     
179     protected void addListeners() {
180         super.addListeners();
181         theBean.addPropertyChangeListener(this);
182     }
183     
184     protected void removeListeners() {
185         super.removeListeners();
186         theBean.removePropertyChangeListener(this);
187     }
188     
189     protected boolean setBean(Object JavaDoc bean) {
190         boolean result = super.setBean(bean);
191         
192         if(bean instanceof ResourceEnvRef) {
193             theBean = (ResourceEnvRef) bean;
194             result = true;
195         } else {
196             // if bean is not a ResourceEnvRef, then it shouldn't have passed Base either.
197
assert (result == false) :
198                 "ResourceEnvRefCustomizer was passed wrong bean type in setBean(Object bean)"; // NOI18N
199

200             theBean = null;
201             result = false;
202         }
203         
204         return result;
205     }
206     
207     public String JavaDoc getHelpId() {
208         return "AS_CFG_ResourceEnvRef"; // NOI18N
209
}
210 }
211
Popular Tags