KickJava   Java API By Example, From Geeks To Geeks.

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


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

58 public class CacheHelperPanel extends javax.swing.JPanel JavaDoc implements 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     private WebAppRootCustomizer masterPanel;
69     
70     // Table for editing default helper web properties
71
private GenericTableModel defaultHelperPropertiesModel;
72     private GenericTablePanel defaultHelperPropertiesPanel;
73     
74     // Table for editing cache helper classes
75
private GenericTableModel cacheHelperClassesModel;
76     private GenericTablePanel cacheHelperClassesPanel;
77     
78     /** Creates new form CacheHelperPanel */
79     public CacheHelperPanel(WebAppRootCustomizer src) {
80         masterPanel = src;
81         
82         initComponents();
83         initUserComponents();
84     }
85     
86     /** This method is called from within the constructor to
87      * initialize the form.
88      * WARNING: Do NOT modify this code. The content of this method is
89      * always regenerated by the Form Editor.
90      */

91     private void initComponents() {//GEN-BEGIN:initComponents
92

93         setLayout(new java.awt.GridBagLayout JavaDoc());
94
95         getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_CacheHelpersTab"));
96         getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_CacheHelpersTab"));
97     }//GEN-END:initComponents
98

99     
100     // Variables declaration - do not modify//GEN-BEGIN:variables
101
// End of variables declaration//GEN-END:variables
102

103     private void initUserComponents() {
104         /** Default helper properties table panel :
105          * TableEntry list has three properties: Name, Value, Description
106          */

107         ArrayList JavaDoc tableColumns = new ArrayList JavaDoc(3);
108         tableColumns.add(new GenericTableModel.AttributeEntry(
109             WebProperty.NAME, commonBundle.getString("LBL_Name"), true)); // NOI18N
110
tableColumns.add(new GenericTableModel.AttributeEntry(
111             WebProperty.VALUE, commonBundle.getString("LBL_Value"), true)); // NOI18N
112
tableColumns.add(new GenericTableModel.ValueEntry(
113             WebProperty.DESCRIPTION, commonBundle.getString("LBL_Description"))); // NOI18N
114

115         // Default helper property table
116
defaultHelperPropertiesModel = new GenericTableModel(DefaultHelper.PROPERTY, WebAppRootCustomizer.webPropertyFactory, tableColumns);
117         defaultHelperPropertiesPanel = new GenericTablePanel(defaultHelperPropertiesModel,
118             webappBundle, "DefaultHelperProperties", // NOI18N - property name
119
DynamicPropertyPanel.class, HelpContext.HELP_CACHE_DEFAULT_HELPER_POPUP,
120             PropertyListMapping.getPropertyList(PropertyListMapping.CACHE_DEFAULT_HELPER_PROPERTIES));
121         
122         GridBagConstraints JavaDoc gridBagConstraints = new GridBagConstraints JavaDoc();
123         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
124         gridBagConstraints.fill = GridBagConstraints.BOTH;
125         gridBagConstraints.weightx = 1.0;
126         gridBagConstraints.weighty = 1.0;
127         gridBagConstraints.insets = new Insets JavaDoc(6, 6, 0, 5);
128         add(defaultHelperPropertiesPanel, gridBagConstraints);
129         
130         /** Cache helper classes table panel :
131          * TableEntry list has three properties: Name, Classname, Properties
132          */

133         tableColumns = new ArrayList JavaDoc(3);
134             tableColumns.add(new GenericTableModel.AttributeEntry(
135                 CacheHelper.NAME, commonBundle.getString("LBL_Name"), true)); // NOI18N
136
tableColumns.add(new GenericTableModel.AttributeEntry(
137             CacheHelper.CLASSNAME, webappBundle.getString("LBL_Classname"), true)); // NOI18N
138
tableColumns.add(new PropertiesEntry());
139         
140         // add Property table
141
cacheHelperClassesModel = new GenericTableModel(cacheHelperFactory, tableColumns);
142         cacheHelperClassesPanel = new GenericTablePanel(cacheHelperClassesModel,
143             webappBundle, "CacheHelperProperties", // NOI18N - property name
144
CacheHelperEntryPanel.class, HelpContext.HELP_CACHE_HELPER_DEFINITION_POPUP);
145         
146         gridBagConstraints = new GridBagConstraints JavaDoc();
147         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
148         gridBagConstraints.fill = GridBagConstraints.BOTH;
149         gridBagConstraints.weightx = 1.0;
150         gridBagConstraints.weighty = 1.0;
151         gridBagConstraints.insets = new Insets JavaDoc(0, 6, 0, 5);
152         add(cacheHelperClassesPanel, gridBagConstraints);
153     }
154     
155     public void addListeners() {
156         defaultHelperPropertiesModel.addTableModelListener(this);
157         cacheHelperClassesModel.addTableModelListener(this);
158     }
159     
160     public void removeListeners() {
161         defaultHelperPropertiesModel.removeTableModelListener(this);
162         cacheHelperClassesModel.removeTableModelListener(this);
163     }
164     
165     /** Initialization of all the fields in this panel from the bean that
166      * was passed in.
167      */

168     public void initFields(WebAppCache cacheBean) {
169         ASDDVersion asVersion = cacheBean.getParent().getAppServerVersion();
170         defaultHelperPropertiesPanel.setModel(cacheBean.getDefaultHelper(), asVersion);
171         cacheHelperClassesPanel.setModel(cacheBean.getCacheHelpers(), asVersion);
172     }
173     
174     /** -----------------------------------------------------------------------
175      * Implementation of javax.swing.event.TableModelListener
176      */

177     public void tableChanged(TableModelEvent JavaDoc e) {
178         WebAppRoot bean = masterPanel.getBean();
179         if(bean != null) {
180             WebAppCache cacheBean = bean.getCacheBean();
181             Object JavaDoc eventSource = e.getSource();
182             try {
183                 if(eventSource == defaultHelperPropertiesModel) {
184                     // This statement will not produce a change event because
185
// of the way we handle property storage for properties like
186
// this one. (The DefaultHelper we're modifying is already the
187
// one owned by the bean).
188
//
189
// cacheBean.setDefaultHelper((DefaultHelper) defaultHelperPropertiesModel.getDataBaseBean());
190
} else if(eventSource == cacheHelperClassesModel) {
191                     List JavaDoc cacheHelperList = cacheHelperClassesModel.getData();
192                     cacheBean.setCacheHelpers(cacheHelperList);
193                     masterPanel.firePropertyChange(WebAppRootCustomizer.CACHE_HELPER_LIST_CHANGED, false, true);
194                 }
195
196                 // Force property change to be issued by the bean
197
bean.setDirty();
198             } catch(PropertyVetoException JavaDoc ex) {
199                 // FIXME undo whatever changed... how?
200
}
201         }
202     }
203     
204     // New for migration to sun DD API model. Factory instance to pass to generic table model
205
// to allow it to create cacheHelper beans.
206
static GenericTableModel.ParentPropertyFactory cacheHelperFactory =
207         new GenericTableModel.ParentPropertyFactory() {
208             public CommonDDBean newParentProperty(ASDDVersion asVersion) {
209                 return StorageBeanFactory.getStorageBeanFactory(asVersion).createCacheHelper();
210             }
211         };
212 }
213
Popular Tags