KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CacheHelperEntryPanel.java
21  *
22  * Created on January 9, 2004, 12:15 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.List JavaDoc;
30 import java.util.ResourceBundle JavaDoc;
31 import java.text.MessageFormat JavaDoc;
32
33 import java.awt.Dimension JavaDoc;
34 import java.awt.GridBagConstraints JavaDoc;
35 import java.awt.Insets JavaDoc;
36
37 import javax.swing.JPanel JavaDoc;
38 import javax.swing.event.TableModelEvent JavaDoc;
39 import javax.swing.event.TableModelListener JavaDoc;
40 import org.netbeans.modules.j2ee.sun.dd.api.web.WebProperty;
41
42 import org.netbeans.modules.j2ee.sun.share.Constants;
43 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion;
44 import org.netbeans.modules.j2ee.sun.share.configbean.Utils;
45 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.ListMapping;
46 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableModel;
47 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTablePanel;
48 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableDialogPanelAccessor;
49 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.HelpContext;
50 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.ValidationSupport;
51 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.DynamicPropertyPanel;
52 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.PropertyListMapping;
53
54 /**
55  *
56  * @author Peter Williams
57  */

58 public class CacheHelperEntryPanel extends JPanel JavaDoc implements GenericTableDialogPanelAccessor, TableModelListener JavaDoc {
59
60     // Standard resource bundle from common
61
private static final ResourceBundle JavaDoc commonBundle = ResourceBundle.getBundle(
62         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); // NOI18N
63

64     // Resource bundle for webapp
65
private static final ResourceBundle JavaDoc webappBundle = ResourceBundle.getBundle(
66         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp.Bundle"); // NOI18N
67

68     // Field indices (maps to values[] handled by get/setValues()
69
private static final int NAME_FIELD = 0;
70     private static final int CLASSNAME_FIELD = 1;
71     private static final int PROPERTIES_FIELD = 2;
72     private static final int NUM_FIELDS = 3; // Number of objects expected in get/setValue methods.
73

74     // Appserver version current referenced
75
private ASDDVersion appServerVersion;
76     
77     // Local storage for data entered by user
78
private String JavaDoc name;
79     private String JavaDoc className;
80     private List JavaDoc properties;
81     
82     // Table for editing default helper web properties
83
private GenericTableModel propertiesModel;
84     private GenericTablePanel propertiesPanel;
85     
86     private Dimension JavaDoc basicPreferredSize;
87     
88     /** Creates new form CacheHelperEntryPanel */
89     public CacheHelperEntryPanel() {
90         initComponents();
91         initUserComponents();
92     }
93     
94     /** This method is called from within the constructor to
95      * initialize the form.
96      * WARNING: Do NOT modify this code. The content of this method is
97      * always regenerated by the Form Editor.
98      */

99     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
100
private void initComponents() {
101         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
102
103         jLblNameReqFlag = new javax.swing.JLabel JavaDoc();
104         jLblName = new javax.swing.JLabel JavaDoc();
105         jTxtName = new javax.swing.JTextField JavaDoc();
106         jLblClassNameReqFlag = new javax.swing.JLabel JavaDoc();
107         jLblClassName = new javax.swing.JLabel JavaDoc();
108         jTxtClassName = new javax.swing.JTextField JavaDoc();
109
110         setLayout(new java.awt.GridBagLayout JavaDoc());
111
112         jLblNameReqFlag.setLabelFor(jTxtName);
113         jLblNameReqFlag.setText(commonBundle.getString("LBL_RequiredMark"));
114         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
115         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
116         add(jLblNameReqFlag, gridBagConstraints);
117         jLblNameReqFlag.getAccessibleContext().setAccessibleName(commonBundle.getString("ACSN_RequiredMark"));
118         jLblNameReqFlag.getAccessibleContext().setAccessibleDescription(commonBundle.getString("ACSD_RequiredMark"));
119
120         jLblName.setDisplayedMnemonic(commonBundle.getString("MNE_Name").charAt(0));
121         jLblName.setLabelFor(jTxtName);
122         jLblName.setText(commonBundle.getString("LBL_Name_1"));
123         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
124         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
125         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
126         add(jLblName, gridBagConstraints);
127
128         jTxtName.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
129             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
130                 jTxtNameKeyReleased(evt);
131             }
132         });
133
134         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
135         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
136         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
137         gridBagConstraints.weightx = 1.0;
138         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
139         add(jTxtName, gridBagConstraints);
140         jTxtName.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_CacheHelperName"));
141         jTxtName.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_CacheHelperName"));
142
143         jLblClassNameReqFlag.setLabelFor(jTxtClassName);
144         jLblClassNameReqFlag.setText(commonBundle.getString("LBL_RequiredMark"));
145         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
147         add(jLblClassNameReqFlag, gridBagConstraints);
148         jLblClassNameReqFlag.getAccessibleContext().setAccessibleName(commonBundle.getString("ACSN_RequiredMark"));
149         jLblClassNameReqFlag.getAccessibleContext().setAccessibleDescription(commonBundle.getString("ACSD_RequiredMark"));
150
151         jLblClassName.setDisplayedMnemonic(webappBundle.getString("MNE_Classname").charAt(0));
152         jLblClassName.setLabelFor(jTxtClassName);
153         jLblClassName.setText(webappBundle.getString("LBL_Classname_1"));
154         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
155         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
156         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
157         add(jLblClassName, gridBagConstraints);
158
159         jTxtClassName.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
160             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
161                 jTxtClassNameKeyReleased(evt);
162             }
163         });
164
165         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
166         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
167         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
168         gridBagConstraints.weightx = 1.0;
169         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
170         add(jTxtClassName, gridBagConstraints);
171         jTxtClassName.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_Classname"));
172         jTxtClassName.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_Classname"));
173
174     }// </editor-fold>//GEN-END:initComponents
175

176     private void jTxtClassNameKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtClassNameKeyReleased
177
// Add your handling code here:
178
className = jTxtClassName.getText();
179         firePropertyChange(Constants.USER_DATA_CHANGED, null, null);
180     }//GEN-LAST:event_jTxtClassNameKeyReleased
181

182     private void jTxtNameKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtNameKeyReleased
183
// Add your handling code here:
184
name = jTxtName.getText();
185         firePropertyChange(Constants.USER_DATA_CHANGED, null, null);
186     }//GEN-LAST:event_jTxtNameKeyReleased
187

188     
189     // Variables declaration - do not modify//GEN-BEGIN:variables
190
private javax.swing.JLabel JavaDoc jLblClassName;
191     private javax.swing.JLabel JavaDoc jLblClassNameReqFlag;
192     private javax.swing.JLabel JavaDoc jLblName;
193     private javax.swing.JLabel JavaDoc jLblNameReqFlag;
194     private javax.swing.JTextField JavaDoc jTxtClassName;
195     private javax.swing.JTextField JavaDoc jTxtName;
196     // End of variables declaration//GEN-END:variables
197

198     private void initUserComponents() {
199         /* Save preferred size before adding table. We have our own width and
200          * will add a constant of our own choosing for the height in init(), below.
201          */

202         basicPreferredSize = getPreferredSize();
203         
204         /* Class helper properties table panel :
205          * TableEntry list has three properties: Name, Value, Description
206          */

207         ArrayList JavaDoc tableColumns = new ArrayList JavaDoc(3);
208         tableColumns.add(new GenericTableModel.AttributeEntry(
209             WebProperty.NAME, commonBundle.getString("LBL_Name"), true)); // NOI18N
210
tableColumns.add(new GenericTableModel.AttributeEntry(
211             WebProperty.VALUE, commonBundle.getString("LBL_Value"), true)); // NOI18N
212
tableColumns.add(new GenericTableModel.ValueEntry(
213             WebProperty.DESCRIPTION, commonBundle.getString("LBL_Description"))); // NOI18N
214

215         // Class helper property table
216
propertiesModel = new GenericTableModel(WebAppRootCustomizer.webPropertyFactory, tableColumns);
217         propertiesModel.addTableModelListener(this);
218         propertiesPanel = new GenericTablePanel(propertiesModel,
219             webappBundle, "HelperDefinitionProperties", // NOI18N - property name
220
DynamicPropertyPanel.class, HelpContext.HELP_CACHE_HELPER_PROPERTY_POPUP,
221             PropertyListMapping.getPropertyList(PropertyListMapping.CACHE_HELPER_PROPERTIES));
222         propertiesPanel.setHeadingMnemonic(webappBundle.getString("MNE_HelperDefinitionProperties").charAt(0)); // NOI18N
223

224         GridBagConstraints JavaDoc gridBagConstraints = new GridBagConstraints JavaDoc();
225         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
226         gridBagConstraints.fill = GridBagConstraints.BOTH;
227         gridBagConstraints.weightx = 1.0;
228         gridBagConstraints.weighty = 1.0;
229         gridBagConstraints.insets = new Insets JavaDoc(0, 6, 5, 5);
230         add(propertiesPanel, gridBagConstraints);
231     }
232     
233     /** -----------------------------------------------------------------------
234      * Implementation of TableModelListener interface
235      */

236     public void tableChanged(TableModelEvent JavaDoc e) {
237         properties = propertiesModel.getData();
238     }
239     
240     /** -----------------------------------------------------------------------
241      * Implementation of GenericTableDialogPanelAccessor interface
242      */

243     public Collection JavaDoc getErrors(ValidationSupport validationSupport) {
244         ArrayList JavaDoc errorList = new ArrayList JavaDoc();
245         
246         if(!Utils.notEmpty(name)) {
247             Object JavaDoc [] args = new Object JavaDoc [1];
248             args[0] = commonBundle.getString("LBL_Name");
249             errorList.add(MessageFormat.format(commonBundle.getString("ERR_SpecifiedFieldIsEmpty"), args));
250         } else if(!Utils.isJavaIdentifier(name)) {
251             Object JavaDoc [] args = new Object JavaDoc [1];
252             args[0] = name;
253             errorList.add(MessageFormat.format(commonBundle.getString("ERR_NotValidIdentifier"), args));
254         }
255         
256         if(!Utils.notEmpty(className)) {
257             Object JavaDoc [] args = new Object JavaDoc [1];
258             args[0] = webappBundle.getString("LBL_Classname");
259             errorList.add(MessageFormat.format(commonBundle.getString("ERR_SpecifiedFieldIsEmpty"), args));
260         } else if(!Utils.isJavaPackage(className)) {
261             Object JavaDoc [] args = new Object JavaDoc [1];
262             args[0] = className;
263             errorList.add(MessageFormat.format(commonBundle.getString("ERR_NotValidPackage"), args));
264         }
265         
266         return errorList;
267     }
268     
269     public Object JavaDoc[] getValues() {
270         Object JavaDoc [] result = new Object JavaDoc[NUM_FIELDS];
271         
272         result[NAME_FIELD] = name;
273         result[CLASSNAME_FIELD] = className;
274         result[PROPERTIES_FIELD] = new ListMapping(properties);
275         
276         return result;
277     }
278     
279     public void init(ASDDVersion asVersion, int preferredWidth, List JavaDoc entries, Object JavaDoc data) {
280         /* Cache appserver version for use in setComponentValues.
281          */

282         appServerVersion = asVersion;
283         
284         /* Set preferred size to pre-table saved height plus constant, width is
285          * precalculated to be 3/4 of width of parent table.
286          */

287         setPreferredSize(new Dimension JavaDoc(preferredWidth, basicPreferredSize.height + 148));
288
289         /* Initialize property list, in case this is a <New...> operation.
290          * 'properties' data member picks up the real List used by the model
291          * in the listener, tableChanged().
292          */

293         propertiesPanel.setModel(new ArrayList JavaDoc(), asVersion);
294     }
295     
296     public void setValues(Object JavaDoc[] values) {
297         if(values != null && values.length == NUM_FIELDS) {
298             name = (String JavaDoc) values[NAME_FIELD];
299             className = (String JavaDoc) values[CLASSNAME_FIELD];
300             ListMapping lm = (ListMapping) values[PROPERTIES_FIELD];
301             properties = lm.getList();
302         } else {
303             if(values != null) {
304                 assert (values.length == NUM_FIELDS); // Should fail
305
}
306             
307             // default values
308
name = ""; // NOI18N
309
className = ""; // NOI18N
310
properties = new ArrayList JavaDoc();
311         }
312         
313         setComponentValues();
314     }
315     
316     private void setComponentValues() {
317         jTxtName.setText(name);
318         jTxtClassName.setText(className);
319         propertiesPanel.setModel(properties, appServerVersion);
320     }
321
322     public boolean requiredFieldsFilled() {
323         return (name != null && name.length() > 0 &&
324             className != null && className.length() > 0);
325     }
326 }
327
Popular Tags