KickJava   Java API By Example, From Geeks To Geeks.

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


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  * WebAppSessionConfigPanel.java
21  *
22  * Created on October 22, 2003, 4:48 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp;
26
27 import java.awt.GridBagConstraints JavaDoc;
28 import java.awt.GridBagLayout JavaDoc;
29 import java.awt.Insets JavaDoc;
30 import java.util.ArrayList JavaDoc;
31
32 import java.util.ResourceBundle JavaDoc;
33 import java.beans.PropertyVetoException JavaDoc;
34
35 import javax.swing.JPanel JavaDoc;
36 import javax.swing.DefaultComboBoxModel JavaDoc;
37 import javax.swing.event.TableModelListener JavaDoc;
38 import javax.swing.event.TableModelEvent JavaDoc;
39
40 import org.netbeans.modules.j2ee.sun.dd.api.web.ManagerProperties;
41 import org.netbeans.modules.j2ee.sun.dd.api.web.StoreProperties;
42 import org.netbeans.modules.j2ee.sun.dd.api.web.SessionProperties;
43 import org.netbeans.modules.j2ee.sun.dd.api.web.CookieProperties;
44 import org.netbeans.modules.j2ee.sun.dd.api.web.WebProperty;
45 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion;
46
47 import org.netbeans.modules.j2ee.sun.share.configbean.ValidationError;
48 import org.netbeans.modules.j2ee.sun.share.configbean.WebAppRoot;
49 import org.netbeans.modules.j2ee.sun.share.configbean.SessionConfigSubBean;
50 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.TextMapping;
51 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableModel;
52 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTablePanel;
53 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.HelpContext;
54 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.DynamicPropertyPanel;
55 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.PropertyListMapping;
56
57 /**
58  *
59  * @author Peter Williams
60  * @version %I%, %G%
61  */

62 public class WebAppSessionConfigPanel extends JPanel JavaDoc implements TableModelListener JavaDoc {
63
64     /** resource bundle */
65     private static final ResourceBundle JavaDoc webappBundle = ResourceBundle.getBundle(
66         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp.Bundle"); // NOI18N
67

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

71     /** xml <--> ui mapping for persistence types combo box */
72     private static final TextMapping [] persistenceTypes = {
73         new TextMapping("", ""), // NOI18N
74
new TextMapping("memory", webappBundle.getString("MEMORY_PERSISTENCE_TYPE")), // NOI18N
75
new TextMapping("file", webappBundle.getString("FILE_PERSISTENCE_TYPE")), // NOI18N
76
new TextMapping("ha", webappBundle.getString("HA_PERSISTENCE_TYPE")), // NOI18N
77
new TextMapping("mmap", webappBundle.getString("MMAP_PERSISTENCE_TYPE")), // NOI18N
78
new TextMapping("replicated", webappBundle.getString("REPLICATED_PERSISTENCE_TYPE")), // NOI18N
79
new TextMapping("s1ws60", webappBundle.getString("S1WS60_PERSISTENCE_TYPE")), // NOI18N
80
new TextMapping("custom", webappBundle.getString("CUSTOM_PERSISTENCE_TYPE")), // NOI18N
81
};
82     
83     private WebAppRootCustomizer masterPanel;
84
85     private DefaultComboBoxModel JavaDoc persistenceTypeModel;
86     
87     // Table for editing Manager Properties web properties
88
private GenericTableModel mgrPropertiesModel;
89     private GenericTablePanel mgrPropertiesPanel;
90     
91     // Table for editing Store Properties web properties
92
private GenericTableModel storePropertiesModel;
93     private GenericTablePanel storePropertiesPanel;
94     
95     // Table for editing Session Properties web properties
96
private GenericTableModel sessionPropertiesModel;
97     private GenericTablePanel sessionPropertiesPanel;
98     
99     // Table for editing Cookie Properties web properties
100
private GenericTableModel cookiePropertiesModel;
101     private GenericTablePanel cookiePropertiesPanel;
102     
103     /** Creates new form WebAppSessionConfigPanel */
104     public WebAppSessionConfigPanel(WebAppRootCustomizer src) {
105         masterPanel = src;
106         
107         initComponents();
108         initUserComponents();
109     }
110     
111     /** This method is called from within the constructor to
112      * initialize the form.
113      * WARNING: Do NOT modify this code. The content of this method is
114      * always regenerated by the Form Editor.
115      */

116     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
117
private void initComponents() {
118         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
119
120         sessionMgrPanel = new javax.swing.JPanel JavaDoc();
121         jLblSessionManager = new javax.swing.JLabel JavaDoc();
122         jLblPersistenceType = new javax.swing.JLabel JavaDoc();
123         jComboPersistenceType = new javax.swing.JComboBox JavaDoc();
124         propertyTabbedPanel = new javax.swing.JTabbedPane JavaDoc();
125
126         setLayout(new java.awt.GridBagLayout JavaDoc());
127
128         getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_WebAppSessionConfigTab"));
129         getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_WebAppSessionConfigTab"));
130         sessionMgrPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
131
132         jLblSessionManager.setText(webappBundle.getString("LBL_SessionManager"));
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
135         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
136         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
137         sessionMgrPanel.add(jLblSessionManager, gridBagConstraints);
138
139         jLblPersistenceType.setLabelFor(jComboPersistenceType);
140         jLblPersistenceType.setText(webappBundle.getString("LBL_PersistenceType_1"));
141         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
142         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
143         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 0);
144         sessionMgrPanel.add(jLblPersistenceType, gridBagConstraints);
145
146         jComboPersistenceType.setPrototypeDisplayValue("Ay");
147         jComboPersistenceType.addActionListener(new java.awt.event.ActionListener JavaDoc() {
148             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
149                 jComboPersistenceTypeActionPerformed(evt);
150             }
151         });
152
153         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
154         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
155         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
156         gridBagConstraints.weightx = 1.0;
157         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 5);
158         sessionMgrPanel.add(jComboPersistenceType, gridBagConstraints);
159         jComboPersistenceType.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_PersistenceType"));
160         jComboPersistenceType.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_PersistenceType"));
161
162         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
164         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
165         gridBagConstraints.weightx = 1.0;
166         add(sessionMgrPanel, gridBagConstraints);
167
168         propertyTabbedPanel.setTabPlacement(javax.swing.JTabbedPane.BOTTOM);
169         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
170         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
171         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
172         gridBagConstraints.weightx = 1.0;
173         gridBagConstraints.weighty = 1.0;
174         add(propertyTabbedPanel, gridBagConstraints);
175
176     }// </editor-fold>//GEN-END:initComponents
177

178     private void jComboPersistenceTypeActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jComboPersistenceTypeActionPerformed
179
// Add your handling code here:
180
TextMapping type = (TextMapping) persistenceTypeModel.getSelectedItem();
181         
182         WebAppRoot theBean = masterPanel.getBean();
183         if(theBean != null) {
184             SessionConfigSubBean sessonConfigBean = theBean.getSessionConfigBean();
185             try {
186                 sessonConfigBean.setPersistenceType(type.getXMLString());
187             } catch(PropertyVetoException JavaDoc ex) {
188                 persistenceTypeModel.setSelectedItem(
189                     getPersistenceTypeMapping(sessonConfigBean.getPersistenceType()));
190             }
191         }
192     }//GEN-LAST:event_jComboPersistenceTypeActionPerformed
193

194     // Variables declaration - do not modify//GEN-BEGIN:variables
195
private javax.swing.JComboBox JavaDoc jComboPersistenceType;
196     private javax.swing.JLabel JavaDoc jLblPersistenceType;
197     private javax.swing.JLabel JavaDoc jLblSessionManager;
198     private javax.swing.JTabbedPane JavaDoc propertyTabbedPanel;
199     private javax.swing.JPanel JavaDoc sessionMgrPanel;
200     // End of variables declaration//GEN-END:variables
201

202     void initUserComponents() {
203         // Setup persistence type
204
persistenceTypeModel = new DefaultComboBoxModel JavaDoc();
205         for(int i = 0; i < persistenceTypes.length; i++) {
206             persistenceTypeModel.addElement(persistenceTypes[i]);
207         }
208         jComboPersistenceType.setModel(persistenceTypeModel);
209         
210         /** Table column description for a table to edit a WebProperty, used by
211          * all of the panels on this customizer.
212          * TableEntry list has three properties: Name, Value, Description
213          */

214         ArrayList JavaDoc tableColumns = new ArrayList JavaDoc(3);
215         tableColumns.add(new GenericTableModel.AttributeEntry(WebProperty.NAME,
216             commonBundle.getString("LBL_Name"), true)); // NOI18N
217
tableColumns.add(new GenericTableModel.AttributeEntry(WebProperty.VALUE,
218             commonBundle.getString("LBL_Value"), true)); // NOI18N
219
tableColumns.add(new GenericTableModel.ValueEntry(WebProperty.DESCRIPTION,
220             commonBundle.getString("LBL_Description"))); // NOI18N
221

222         // add Manager Properties table
223
mgrPropertiesModel = new GenericTableModel(ManagerProperties.PROPERTY, WebAppRootCustomizer.webPropertyFactory, tableColumns);
224         mgrPropertiesPanel = new GenericTablePanel(mgrPropertiesModel,
225             webappBundle, "ManagerProperties", // NOI18N - property name
226
DynamicPropertyPanel.class, HelpContext.HELP_SESSIONCONFIG_MANAGER_POPUP,
227             PropertyListMapping.getPropertyList(PropertyListMapping.CONFIG_MANAGER_PROPERTIES));
228
229         GridBagConstraints JavaDoc gridBagConstraints = new GridBagConstraints JavaDoc();
230         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
231         gridBagConstraints.fill = GridBagConstraints.BOTH;
232         gridBagConstraints.weightx = 1.0;
233         gridBagConstraints.weighty = 1.0;
234         gridBagConstraints.insets = new Insets JavaDoc(6, 6, 0, 5);
235         JPanel JavaDoc holderPanel = new JPanel JavaDoc();
236         holderPanel.setLayout(new GridBagLayout JavaDoc());
237         holderPanel.add(mgrPropertiesPanel, gridBagConstraints);
238
239         propertyTabbedPanel.addTab(webappBundle.getString("TAB_ManagerProperties"), // NOI18N
240
holderPanel);
241
242         // add Store Properties table
243
storePropertiesModel = new GenericTableModel(StoreProperties.PROPERTY, WebAppRootCustomizer.webPropertyFactory, tableColumns);
244         storePropertiesPanel = new GenericTablePanel(storePropertiesModel,
245             webappBundle, "StoreProperties", // NOI18N - property name
246
DynamicPropertyPanel.class, HelpContext.HELP_SESSIONCONFIG_STORE_POPUP,
247             PropertyListMapping.getPropertyList(PropertyListMapping.CONFIG_STORE_PROPERTIES));
248
249         gridBagConstraints = new GridBagConstraints JavaDoc();
250         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
251         gridBagConstraints.fill = GridBagConstraints.BOTH;
252         gridBagConstraints.weightx = 1.0;
253         gridBagConstraints.weighty = 1.0;
254         gridBagConstraints.insets = new Insets JavaDoc(6, 6, 0, 5);
255         holderPanel = new JPanel JavaDoc();
256         holderPanel.setLayout(new GridBagLayout JavaDoc());
257         holderPanel.add(storePropertiesPanel, gridBagConstraints);
258
259         propertyTabbedPanel.addTab(webappBundle.getString("TAB_StoreProperties"), // NOI18N
260
holderPanel);
261         
262         // add Session Properties table
263
sessionPropertiesModel = new GenericTableModel(SessionProperties.PROPERTY, WebAppRootCustomizer.webPropertyFactory, tableColumns);
264         sessionPropertiesPanel = new GenericTablePanel(sessionPropertiesModel,
265             webappBundle, "SessionProperties", // NOI18N - property name
266
DynamicPropertyPanel.class, HelpContext.HELP_SESSIONCONFIG_SESSION_POPUP,
267             PropertyListMapping.getPropertyList(PropertyListMapping.CONFIG_SESSION_PROPERTIES));
268
269         gridBagConstraints = new GridBagConstraints JavaDoc();
270         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
271         gridBagConstraints.fill = GridBagConstraints.BOTH;
272         gridBagConstraints.weightx = 1.0;
273         gridBagConstraints.weighty = 1.0;
274         gridBagConstraints.insets = new Insets JavaDoc(6, 6, 0, 5);
275         holderPanel = new JPanel JavaDoc();
276         holderPanel.setLayout(new GridBagLayout JavaDoc());
277         holderPanel.add(sessionPropertiesPanel, gridBagConstraints);
278
279         propertyTabbedPanel.addTab(webappBundle.getString("TAB_SessionProperties"), // NOI18N
280
holderPanel);
281         
282         // add Cookie Properties table
283
cookiePropertiesModel = new GenericTableModel(CookieProperties.PROPERTY, WebAppRootCustomizer.webPropertyFactory, tableColumns);
284         cookiePropertiesPanel = new GenericTablePanel(cookiePropertiesModel,
285             webappBundle, "CookieProperties", // NOI18N - property name
286
DynamicPropertyPanel.class, HelpContext.HELP_SESSIONCONFIG_COOKIE_POPUP,
287             PropertyListMapping.getPropertyList(PropertyListMapping.CONFIG_COOKIE_PROPERTIES));
288
289         gridBagConstraints = new GridBagConstraints JavaDoc();
290         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
291         gridBagConstraints.fill = GridBagConstraints.BOTH;
292         gridBagConstraints.weightx = 1.0;
293         gridBagConstraints.weighty = 1.0;
294         gridBagConstraints.insets = new Insets JavaDoc(6, 6, 0, 5);
295         holderPanel = new JPanel JavaDoc();
296         holderPanel.setLayout(new GridBagLayout JavaDoc());
297         holderPanel.add(cookiePropertiesPanel, gridBagConstraints);
298
299         propertyTabbedPanel.addTab(webappBundle.getString("TAB_CookieProperties"), // NOI18N
300
holderPanel);
301     }
302     
303     public void addListeners() {
304         mgrPropertiesModel.addTableModelListener(this);
305         storePropertiesModel.addTableModelListener(this);
306         sessionPropertiesModel.addTableModelListener(this);
307         cookiePropertiesModel.addTableModelListener(this);
308     }
309     
310     public void removeListeners() {
311         mgrPropertiesModel.removeTableModelListener(this);
312         storePropertiesModel.removeTableModelListener(this);
313         sessionPropertiesModel.removeTableModelListener(this);
314         cookiePropertiesModel.removeTableModelListener(this);
315     }
316     
317     /** Initialization of all the fields in the customizer from the bean that
318      * was passed in.
319      */

320     public void initFields(WebAppRoot theBean) {
321         ASDDVersion asVersion = theBean.getAppServerVersion();
322         
323         SessionConfigSubBean sessonConfigBean = theBean.getSessionConfigBean();
324         persistenceTypeModel.setSelectedItem(
325             getPersistenceTypeMapping(sessonConfigBean.getPersistenceType()));
326         
327         mgrPropertiesPanel.setModel(sessonConfigBean.getManagerProperties(), asVersion);
328         storePropertiesPanel.setModel(sessonConfigBean.getStoreProperties(), asVersion);
329         sessionPropertiesPanel.setModel(sessonConfigBean.getSessionProperties(), asVersion);
330         cookiePropertiesPanel.setModel(sessonConfigBean.getCookieProperties(), asVersion);
331     }
332     
333     private TextMapping getPersistenceTypeMapping(String JavaDoc xmlKey) {
334         TextMapping result = persistenceTypes[0]; // Default to blank version
335
if(xmlKey == null) {
336             xmlKey = ""; // NOI18N
337
}
338         
339         for(int i = 0; i < persistenceTypes.length; i++) {
340             if(persistenceTypes[i].getXMLString().compareTo(xmlKey) == 0) {
341                 result = persistenceTypes[i];
342                 break;
343             }
344         }
345         
346         return result;
347     }
348     
349     
350     /** -----------------------------------------------------------------------
351      * Implementation of javax.swing.event.TableModelListener
352      */

353     public void tableChanged(TableModelEvent JavaDoc e) {
354         WebAppRoot bean = masterPanel.getBean();
355         if(bean != null) {
356             bean.setDirty();
357         }
358     }
359
360     
361     /** Returns the help ID for the selected tab within the session configuration
362      * tab of sun-web-app.
363      *
364      * @return String representing the current active help ID for this tabbed panel.
365      */

366     public String JavaDoc getHelpId() {
367         String JavaDoc result = "AS_CFG_SessionConfigurationManager"; // NOI18N
368

369         // Determine which tab has focus and return help context for that tab.
370
switch(propertyTabbedPanel.getSelectedIndex()) {
371             case 3:
372                 result = "AS_CFG_SessionConfigurationCookie"; // NOI18N
373
break;
374             case 2:
375                 result = "AS_CFG_SessionConfigurationSession"; // NOI18N
376
break;
377             case 1:
378                 result = "AS_CFG_SessionConfigurationStore"; // NOI18N
379
break;
380         }
381         
382         return result;
383     }
384     
385     /** Retrieve the partition that should be associated with the current
386      * selected tab.
387      *
388      * @return ValidationError.Partition
389      */

390     public ValidationError.Partition getPartition() {
391         switch(propertyTabbedPanel.getSelectedIndex()) {
392             case 3:
393                 return ValidationError.PARTITION_SESSION_COOKIE;
394             case 2:
395                 return ValidationError.PARTITION_SESSION_SESSION;
396             case 1:
397                 return ValidationError.PARTITION_SESSION_STORE;
398             default:
399                 return ValidationError.PARTITION_SESSION_MANAGER;
400         }
401     }
402 }
403
Popular Tags