KickJava   Java API By Example, From Geeks To Geeks.

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


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  * KeyFieldEntryPanel.java
21  *
22  * Created on February 4, 2004, 12:37 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.Collection JavaDoc;
29 import java.util.ResourceBundle JavaDoc;
30 import java.text.MessageFormat JavaDoc;
31
32 import java.awt.Dimension JavaDoc;
33
34 import javax.swing.JPanel JavaDoc;
35 import javax.swing.DefaultComboBoxModel JavaDoc;
36
37 import org.netbeans.modules.j2ee.sun.share.Constants;
38 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion;
39 import org.netbeans.modules.j2ee.sun.share.configbean.Utils;
40 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableDialogPanelAccessor;
41 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.TextMapping;
42 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.ValidationSupport;
43
44 /**
45  *
46  * @author Peter Williams
47  */

48 public class KeyFieldEntryPanel extends JPanel JavaDoc implements GenericTableDialogPanelAccessor {
49     
50     private static final ResourceBundle JavaDoc webappBundle = ResourceBundle.getBundle(
51         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp.Bundle"); // NOI18N
52

53     private static final ResourceBundle JavaDoc commonBundle = ResourceBundle.getBundle(
54         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); // NOI18N
55

56     private static final TextMapping [] keyScopeTypes = ScopeMapping.getKeyScopeMappings();
57
58     // Field indices (maps to values[] handled by get/setValues()
59
private static final int NAME_FIELD = 0;
60     private static final int SCOPE_FIELD = 1;
61     private static final int NUM_FIELDS = 2; // Number of objects expected in get/setValue methods.
62

63     // Local storage for data entered by user
64
private String JavaDoc keyFieldName;
65     private String JavaDoc keyFieldScope;
66
67     // expression combo box model
68
private DefaultComboBoxModel JavaDoc keyFieldScopeModel;
69
70     /** Creates new form KeyFieldEntryPanel */
71     public KeyFieldEntryPanel() {
72         initComponents();
73         initUserComponents();
74     }
75     
76     /** This method is called from within the constructor to
77      * initialize the form.
78      * WARNING: Do NOT modify this code. The content of this method is
79      * always regenerated by the Form Editor.
80      */

81     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
82
private void initComponents() {
83         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
84
85         jLblKeyFieldReq = new javax.swing.JLabel JavaDoc();
86         jLblKeyFieldName = new javax.swing.JLabel JavaDoc();
87         jTxtKeyFieldName = new javax.swing.JTextField JavaDoc();
88         jLblFiller1 = new javax.swing.JLabel JavaDoc();
89         jLblKeyScope = new javax.swing.JLabel JavaDoc();
90         jCbxKeyScope = new javax.swing.JComboBox JavaDoc();
91
92         setLayout(new java.awt.GridBagLayout JavaDoc());
93
94         jLblKeyFieldReq.setLabelFor(jTxtKeyFieldName);
95         jLblKeyFieldReq.setText(commonBundle.getString("LBL_RequiredMark"));
96         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
97         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
98         add(jLblKeyFieldReq, gridBagConstraints);
99         jLblKeyFieldReq.getAccessibleContext().setAccessibleName(commonBundle.getString("ACSN_RequiredMark"));
100         jLblKeyFieldReq.getAccessibleContext().setAccessibleDescription(commonBundle.getString("ACSD_RequiredMark"));
101
102         jLblKeyFieldName.setDisplayedMnemonic(webappBundle.getString("MNE_KeyFieldName").charAt(0));
103         jLblKeyFieldName.setLabelFor(jTxtKeyFieldName);
104         jLblKeyFieldName.setText(webappBundle.getString("LBL_KeyFieldName_1"));
105         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
106         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
107         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
108         add(jLblKeyFieldName, gridBagConstraints);
109
110         jTxtKeyFieldName.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
111             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
112                 jTxtKeyFieldNameKeyReleased(evt);
113             }
114         });
115
116         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
117         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
118         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
119         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
120         add(jTxtKeyFieldName, gridBagConstraints);
121         jTxtKeyFieldName.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_KeyFieldName"));
122         jTxtKeyFieldName.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_KeyFieldName"));
123
124         jLblFiller1.setLabelFor(jCbxKeyScope);
125         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
126         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 0);
127         add(jLblFiller1, gridBagConstraints);
128
129         jLblKeyScope.setDisplayedMnemonic(webappBundle.getString("MNE_KeyFieldScope").charAt(0));
130         jLblKeyScope.setLabelFor(jCbxKeyScope);
131         jLblKeyScope.setText(webappBundle.getString("LBL_KeyFieldScope_1"));
132         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
133         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
134         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 0);
135         add(jLblKeyScope, gridBagConstraints);
136
137         jCbxKeyScope.addActionListener(new java.awt.event.ActionListener JavaDoc() {
138             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
139                 jCbxKeyScopeActionPerformed(evt);
140             }
141         });
142
143         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
144         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
145         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
146         gridBagConstraints.weightx = 1.0;
147         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 5);
148         add(jCbxKeyScope, gridBagConstraints);
149         jCbxKeyScope.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_KeyFieldScope"));
150         jCbxKeyScope.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_KeyFieldScope"));
151
152     }// </editor-fold>//GEN-END:initComponents
153

154     private void jCbxKeyScopeActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jCbxKeyScopeActionPerformed
155
TextMapping scope = (TextMapping) keyFieldScopeModel.getSelectedItem();
156         keyFieldScope = scope.getXMLString();
157         firePropertyChange(Constants.USER_DATA_CHANGED, null, null);
158     }//GEN-LAST:event_jCbxKeyScopeActionPerformed
159

160     private void jTxtKeyFieldNameKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtKeyFieldNameKeyReleased
161
keyFieldName = jTxtKeyFieldName.getText();
162         firePropertyChange(Constants.USER_DATA_CHANGED, null, null);
163     }//GEN-LAST:event_jTxtKeyFieldNameKeyReleased
164

165     // Variables declaration - do not modify//GEN-BEGIN:variables
166
private javax.swing.JComboBox JavaDoc jCbxKeyScope;
167     private javax.swing.JLabel JavaDoc jLblFiller1;
168     private javax.swing.JLabel JavaDoc jLblKeyFieldName;
169     private javax.swing.JLabel JavaDoc jLblKeyFieldReq;
170     private javax.swing.JLabel JavaDoc jLblKeyScope;
171     private javax.swing.JTextField JavaDoc jTxtKeyFieldName;
172     // End of variables declaration//GEN-END:variables
173

174     private void initUserComponents() {
175         // Setup match expression combobox
176
keyFieldScopeModel = new DefaultComboBoxModel JavaDoc();
177         for(int i = 0; i < keyScopeTypes.length; i++) {
178             keyFieldScopeModel.addElement(keyScopeTypes[i]);
179         }
180         jCbxKeyScope.setModel(keyFieldScopeModel);
181     }
182     
183     private TextMapping getScopeMapping(String JavaDoc xmlKey) {
184         TextMapping result = null;
185         if(xmlKey == null) {
186             xmlKey = ""; // NOI18N
187
}
188         for(int i = 0; i < keyScopeTypes.length; i++) {
189             if(keyScopeTypes[i].getXMLString().compareTo(xmlKey) == 0) {
190                 result = keyScopeTypes[i];
191                 break;
192             }
193         }
194         
195         return result;
196     }
197     
198     /** -----------------------------------------------------------------------
199      * Implementation of GenericTableDialogPanelAccessor interface
200      */

201     public void init(ASDDVersion asVersion, int preferredWidth, java.util.List JavaDoc entries, Object JavaDoc data) {
202         setPreferredSize(new Dimension JavaDoc(preferredWidth, getPreferredSize().height));
203     }
204     
205     public Object JavaDoc[] getValues() {
206         Object JavaDoc [] result = new Object JavaDoc[NUM_FIELDS];
207         
208         result[NAME_FIELD] = keyFieldName;
209         result[SCOPE_FIELD] = keyFieldScope;
210         
211         return result;
212     }
213     
214     public void setValues(Object JavaDoc[] values) {
215         if(values != null && values.length == NUM_FIELDS) {
216             keyFieldName = (String JavaDoc) values[NAME_FIELD];
217             keyFieldScope = (String JavaDoc) values[SCOPE_FIELD];
218         } else {
219             if(values != null) {
220                 assert (values.length == NUM_FIELDS); // Should fail
221
}
222             
223             // default values
224
keyFieldName = ""; // NOI18N
225
keyFieldScope = ""; // NOI18N
226
}
227         
228         setComponentValues();
229     }
230     
231     private void setComponentValues() {
232         jTxtKeyFieldName.setText(keyFieldName);
233         keyFieldScopeModel.setSelectedItem(getScopeMapping(keyFieldScope));
234     }
235     
236     public Collection JavaDoc getErrors(ValidationSupport validationSupport) {
237         ArrayList JavaDoc errorList = new ArrayList JavaDoc();
238         
239         if(!Utils.notEmpty(keyFieldName)) {
240             Object JavaDoc [] args = new Object JavaDoc [1];
241             args[0] = webappBundle.getString("LBL_KeyFieldName");
242             errorList.add(MessageFormat.format(commonBundle.getString("ERR_SpecifiedFieldIsEmpty"), args));
243         } else if(!Utils.isJavaIdentifier(keyFieldName)) {
244             Object JavaDoc [] args = new Object JavaDoc [1];
245             args[0] = keyFieldName;
246             errorList.add(MessageFormat.format(commonBundle.getString("ERR_NotValidIdentifier"), args));
247         }
248         
249         return errorList;
250     }
251
252     public boolean requiredFieldsFilled() {
253         return (keyFieldName != null && keyFieldName.length() > 0);
254     }
255 }
256
Popular Tags