KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CacheGeneralPanel.java
21  *
22  * Created on January 7, 2004, 5:10 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.ResourceBundle JavaDoc;
29
30 import java.awt.GridBagConstraints JavaDoc;
31 import java.awt.Insets JavaDoc;
32 import java.beans.PropertyVetoException JavaDoc;
33
34 import javax.swing.event.TableModelEvent JavaDoc;
35 import javax.swing.event.TableModelListener JavaDoc;
36
37 import org.netbeans.modules.j2ee.sun.dd.api.web.WebProperty;
38
39 import org.netbeans.modules.j2ee.sun.share.configbean.Utils;
40 import org.netbeans.modules.j2ee.sun.share.configbean.WebAppRoot;
41 import org.netbeans.modules.j2ee.sun.share.configbean.WebAppCache;
42 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableModel;
43 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTablePanel;
44 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.HelpContext;
45 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.DynamicPropertyPanel;
46 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.PropertyListMapping;
47
48 /**
49  *
50  * @author Peter Williams
51  */

52 public class CacheGeneralPanel extends javax.swing.JPanel JavaDoc implements TableModelListener JavaDoc {
53     
54     private static final ResourceBundle JavaDoc webappBundle = ResourceBundle.getBundle(
55         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp.Bundle"); // NOI18N
56

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

60     private WebAppRootCustomizer masterPanel;
61
62     // Table for editing Cache Property web properties
63
private GenericTableModel propertiesModel;
64     private GenericTablePanel propertiesPanel;
65
66     /** Creates new form CacheGeneralPanel */
67     public CacheGeneralPanel(WebAppRootCustomizer src) {
68         masterPanel = src;
69
70         initComponents();
71         initUserComponents();
72     }
73     
74     /** This method is called from within the constructor to
75      * initialize the form.
76      * WARNING: Do NOT modify this code. The content of this method is
77      * always regenerated by the Form Editor.
78      */

79     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
80
private void initComponents() {
81         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
82
83         jPnlCacheGeneral = new javax.swing.JPanel JavaDoc();
84         jLblCacheSettings = new javax.swing.JLabel JavaDoc();
85         jChkCacheEnabled = new javax.swing.JCheckBox JavaDoc();
86         jLblMaxEntries = new javax.swing.JLabel JavaDoc();
87         jTxtMaxEntries = new javax.swing.JTextField JavaDoc();
88         jLblTimeout = new javax.swing.JLabel JavaDoc();
89         jTxtTimeout = new javax.swing.JTextField JavaDoc();
90
91         setLayout(new java.awt.GridBagLayout JavaDoc());
92
93         getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_CacheGeneralTab"));
94         getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_CacheGeneralTab"));
95         jPnlCacheGeneral.setLayout(new java.awt.GridBagLayout JavaDoc());
96
97         jLblCacheSettings.setText(webappBundle.getString("LBL_CacheSettings"));
98         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
99         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
100         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
101         gridBagConstraints.weightx = 1.0;
102         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
103         jPnlCacheGeneral.add(jLblCacheSettings, gridBagConstraints);
104
105         jChkCacheEnabled.setText(webappBundle.getString("LBL_CacheEnabled"));
106         jChkCacheEnabled.addItemListener(new java.awt.event.ItemListener JavaDoc() {
107             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
108                 jChkCacheEnabledItemStateChanged(evt);
109             }
110         });
111
112         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
113         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
114         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
115         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 2, 0, 0);
116         jPnlCacheGeneral.add(jChkCacheEnabled, gridBagConstraints);
117         jChkCacheEnabled.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_CacheEnabled"));
118         jChkCacheEnabled.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_CacheEnabled"));
119
120         jLblMaxEntries.setLabelFor(jTxtMaxEntries);
121         jLblMaxEntries.setText(webappBundle.getString("LBL_MaximumEntries_1"));
122         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
123         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
124         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
125         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
126         jPnlCacheGeneral.add(jLblMaxEntries, gridBagConstraints);
127
128         jTxtMaxEntries.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
129             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
130                 jTxtMaxEntriesKeyReleased(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.anchor = java.awt.GridBagConstraints.WEST;
138         gridBagConstraints.weightx = 0.5;
139         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
140         jPnlCacheGeneral.add(jTxtMaxEntries, gridBagConstraints);
141         jTxtMaxEntries.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_MaximumEntries"));
142         jTxtMaxEntries.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_MaximumEntries"));
143
144         jLblTimeout.setLabelFor(jTxtTimeout);
145         jLblTimeout.setText(webappBundle.getString("LBL_Timeout_1"));
146         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
147         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
148         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
149         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 0);
150         jPnlCacheGeneral.add(jLblTimeout, gridBagConstraints);
151
152         jTxtTimeout.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
153             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
154                 jTxtTimeoutKeyReleased(evt);
155             }
156         });
157
158         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
159         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
160         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
161         gridBagConstraints.weightx = 0.5;
162         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 5);
163         jPnlCacheGeneral.add(jTxtTimeout, gridBagConstraints);
164         jTxtTimeout.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_Timeout"));
165         jTxtTimeout.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_Timeout"));
166
167         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
168         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
169         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
170         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
171         gridBagConstraints.weightx = 1.0;
172         add(jPnlCacheGeneral, gridBagConstraints);
173
174     }// </editor-fold>//GEN-END:initComponents
175

176     private void jChkCacheEnabledItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_jChkCacheEnabledItemStateChanged
177
// Add your handling code here:
178
WebAppRoot bean = masterPanel.getBean();
179         if(bean != null) {
180             WebAppCache cacheBean = bean.getCacheBean();
181             try {
182                 boolean state = Utils.interpretCheckboxState(evt);
183                 cacheBean.setCacheEnabled(Boolean.toString(state));
184             } catch(PropertyVetoException JavaDoc ex) {
185                 jChkCacheEnabled.setSelected(Utils.booleanValueOf(cacheBean.getCacheEnabled()));
186             }
187         }
188     }//GEN-LAST:event_jChkCacheEnabledItemStateChanged
189

190     private void jTxtMaxEntriesKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtMaxEntriesKeyReleased
191
// Add your handling code here:
192
WebAppRoot bean = masterPanel.getBean();
193         if(bean != null) {
194             WebAppCache cacheBean = bean.getCacheBean();
195             try {
196                 cacheBean.setCacheMaxEntries(jTxtMaxEntries.getText());
197                 cacheBean.validateField(WebAppCache.FIELD_CACHE_MAX_ENTRIES);
198             } catch(PropertyVetoException JavaDoc ex) {
199                 jTxtMaxEntries.setText(cacheBean.getCacheMaxEntries());
200             }
201         }
202     }//GEN-LAST:event_jTxtMaxEntriesKeyReleased
203

204     private void jTxtTimeoutKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtTimeoutKeyReleased
205
// Add your handling code here:
206
WebAppRoot bean = masterPanel.getBean();
207         if(bean != null) {
208             WebAppCache cacheBean = bean.getCacheBean();
209             try {
210                 cacheBean.setTimeoutInSeconds(jTxtTimeout.getText());
211                 cacheBean.validateField(WebAppCache.FIELD_CACHE_TIMEOUT);
212             } catch(PropertyVetoException JavaDoc ex) {
213                 jTxtTimeout.setText(cacheBean.getTimeoutInSeconds());
214             }
215         }
216     }//GEN-LAST:event_jTxtTimeoutKeyReleased
217

218     // Variables declaration - do not modify//GEN-BEGIN:variables
219
private javax.swing.JCheckBox JavaDoc jChkCacheEnabled;
220     private javax.swing.JLabel JavaDoc jLblCacheSettings;
221     private javax.swing.JLabel JavaDoc jLblMaxEntries;
222     private javax.swing.JLabel JavaDoc jLblTimeout;
223     private javax.swing.JPanel JavaDoc jPnlCacheGeneral;
224     private javax.swing.JTextField JavaDoc jTxtMaxEntries;
225     private javax.swing.JTextField JavaDoc jTxtTimeout;
226     // End of variables declaration//GEN-END:variables
227

228     private void initUserComponents() {
229         /** Add properties table panel :
230          * TableEntry list has three properties: Name, Value, Description
231          */

232         ArrayList JavaDoc tableColumns = new ArrayList JavaDoc(3);
233         tableColumns.add(new GenericTableModel.AttributeEntry(
234             WebProperty.NAME, commonBundle.getString("LBL_Name"), true)); // NOI18N
235
tableColumns.add(new GenericTableModel.AttributeEntry(
236             WebProperty.VALUE, commonBundle.getString("LBL_Value"), true)); // NOI18N
237
tableColumns.add(new GenericTableModel.ValueEntry(
238             WebProperty.DESCRIPTION, commonBundle.getString("LBL_Description"))); // NOI18N
239

240         // add Property table
241
propertiesModel = new GenericTableModel(WebAppRootCustomizer.webPropertyFactory, tableColumns);
242         propertiesPanel = new GenericTablePanel(propertiesModel,
243             webappBundle, "CacheProperties", // NOI18N - property name
244
DynamicPropertyPanel.class, HelpContext.HELP_CACHE_PROPERTY_POPUP,
245             PropertyListMapping.getPropertyList(PropertyListMapping.CACHE_PROPERTIES));
246         
247         GridBagConstraints JavaDoc gridBagConstraints = new GridBagConstraints JavaDoc();
248         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
249         gridBagConstraints.fill = GridBagConstraints.BOTH;
250         gridBagConstraints.weightx = 1.0;
251         gridBagConstraints.weighty = 1.0;
252         gridBagConstraints.insets = new Insets JavaDoc(0, 6, 0, 5);
253         add(propertiesPanel, gridBagConstraints);
254     }
255     
256     public void addListeners() {
257         propertiesModel.addTableModelListener(this);
258     }
259     
260     public void removeListeners() {
261         propertiesModel.removeTableModelListener(this);
262     }
263     
264     /** Initialization of all the fields in this panel from the bean that
265      * was passed in.
266      */

267     public void initFields(WebAppCache cacheBean) {
268         jTxtMaxEntries.setText(cacheBean.getCacheMaxEntries());
269         jTxtTimeout.setText(cacheBean.getTimeoutInSeconds());
270         jChkCacheEnabled.setSelected(Utils.booleanValueOf(cacheBean.getCacheEnabled()));
271         
272         propertiesPanel.setModel(cacheBean.getProperties(), cacheBean.getParent().getAppServerVersion());
273     }
274     
275     /** -----------------------------------------------------------------------
276      * Implementation of javax.swing.event.TableModelListener
277      */

278     public void tableChanged(TableModelEvent JavaDoc e) {
279         WebAppRoot bean = masterPanel.getBean();
280         if(bean != null) {
281             WebAppCache cacheBean = bean.getCacheBean();
282             try {
283                 cacheBean.setProperties(propertiesModel.getData());
284             
285                 // Force property change to be issued by the bean
286
bean.setDirty();
287             } catch(PropertyVetoException JavaDoc ex) {
288                 // FIXME undo whatever changed... how?
289

290             }
291         }
292     }
293 }
294
Popular Tags