KickJava   Java API By Example, From Geeks To Geeks.

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


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  * WebAppPropertiesPanel.java
21  *
22  * Created on October 13, 2005, 3:00 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.PropertyChangeEvent JavaDoc;
33 import java.beans.PropertyChangeListener JavaDoc;
34 import java.beans.PropertyVetoException JavaDoc;
35
36 import javax.swing.event.TableModelEvent JavaDoc;
37 import javax.swing.event.TableModelListener JavaDoc;
38
39 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
40 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp;
41
42 import org.netbeans.modules.j2ee.sun.share.configbean.WebAppRoot;
43 import org.netbeans.modules.j2ee.sun.share.configbean.StorageBeanFactory;
44 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableModel;
45 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTablePanel;
46 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.HelpContext;
47
48 /**
49  *
50  * @author Peter Williams
51  */

52 public class WebAppPropertiesPanel 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 WebAppRootCustomizer masterPanel;
58     
59     // Table for editing Property idempotent url patterns
60
private GenericTableModel idempotentUrlPatternModel;
61     private GenericTablePanel idempotentUrlPatternPanel;
62
63     // Listens for changes to the default list of charsets
64
private ParameterEncodingPanel parameterEncodingPanel;
65     private PropertyChangeListener JavaDoc parameterEncodingChangeListener;
66     
67     /** Creates new form WebAppPropertiesPanel */
68     public WebAppPropertiesPanel(WebAppRootCustomizer src) {
69         masterPanel = src;
70         
71         initComponents();
72         initUserComponents();
73     }
74     
75     /** This method is called from within the constructor to
76      * initialize the form.
77      * WARNING: Do NOT modify this code. The content of this method is
78      * always regenerated by the Form Editor.
79      */

80     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
81
private void initComponents() {
82
83         setLayout(new java.awt.GridBagLayout JavaDoc());
84
85         getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_WebAppPropertiesTab"));
86         getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_WebAppPropertiesTab"));
87     }
88     // </editor-fold>//GEN-END:initComponents
89

90     
91     // Variables declaration - do not modify//GEN-BEGIN:variables
92
// End of variables declaration//GEN-END:variables
93

94     private void initUserComponents() {
95         /** Add parameter encoding panel.
96          */

97         parameterEncodingPanel = new ParameterEncodingPanel();
98
99         GridBagConstraints JavaDoc gridBagConstraints = new GridBagConstraints JavaDoc();
100         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
101         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
102         gridBagConstraints.weightx = 1.0;
103         gridBagConstraints.weighty = 0;
104         gridBagConstraints.insets = new Insets JavaDoc(0, 0, 0, 0);
105         add(parameterEncodingPanel, gridBagConstraints);
106
107         parameterEncodingChangeListener = new PropertyChangeListener JavaDoc() {
108             public void propertyChange(PropertyChangeEvent JavaDoc pce) {
109                 String JavaDoc newValue = (String JavaDoc) pce.getNewValue();
110                 updateParameterEncoding(pce.getPropertyName(), newValue);
111             }
112         };
113         
114         // add idempotentUrlPattern table
115
ArrayList JavaDoc tableColumns = new ArrayList JavaDoc(2);
116         tableColumns.add(new GenericTableModel.AttributeEntry(SunWebApp.IDEMPOTENT_URL_PATTERN, "UrlPattern", // NOI18N
117
webappBundle, "UrlPattern", true, false)); // NOI18N
118
tableColumns.add(new GenericTableModel.AttributeEntry(SunWebApp.IDEMPOTENT_URL_PATTERN, "NumOfRetries", // NOI18N
119
webappBundle, "NumOfRetries", true, false)); // NOI18N
120

121         idempotentUrlPatternModel = new GenericTableModel(SunWebApp.IDEMPOTENT_URL_PATTERN, tableColumns);
122         idempotentUrlPatternPanel = new GenericTablePanel(idempotentUrlPatternModel,
123             webappBundle, "IdempotentUrlPatterns", // NOI18N - property name
124
HelpContext.HELP_WEBAPP_IDEMPOTENTURLPATTERN_POPUP);
125         idempotentUrlPatternPanel.setHeadingMnemonic(webappBundle.getString("MNE_IdempotentUrlPatterns").charAt(0)); // NOI18N
126

127         gridBagConstraints = new GridBagConstraints JavaDoc();
128         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
129         gridBagConstraints.fill = GridBagConstraints.BOTH;
130         gridBagConstraints.weightx = 1.0;
131         gridBagConstraints.weighty = 1.0;
132         gridBagConstraints.insets = new Insets JavaDoc(0, 6, 0, 5);
133         add(idempotentUrlPatternPanel, gridBagConstraints);
134     }
135     
136     public void addListeners() {
137         idempotentUrlPatternModel.addTableModelListener(this);
138         parameterEncodingPanel.addPropertyChangeListener(ParameterEncodingPanel.PROP_DEFAULT_CHARSET, parameterEncodingChangeListener);
139         parameterEncodingPanel.addPropertyChangeListener(ParameterEncodingPanel.PROP_FORM_HINT_FIELD, parameterEncodingChangeListener);
140         parameterEncodingPanel.addListeners();
141     }
142     
143     public void removeListeners() {
144         parameterEncodingPanel.removeListeners();
145         parameterEncodingPanel.removePropertyChangeListener(ParameterEncodingPanel.PROP_DEFAULT_CHARSET, parameterEncodingChangeListener);
146         parameterEncodingPanel.removePropertyChangeListener(ParameterEncodingPanel.PROP_FORM_HINT_FIELD, parameterEncodingChangeListener);
147         idempotentUrlPatternModel.removeTableModelListener(this);
148     }
149     
150     /** Initialization of all the fields in this panel from the bean that
151      * was passed in.
152      */

153     public void initFields(WebAppRoot bean) {
154         parameterEncodingPanel.initFields(bean.getAppServerVersion(), bean.getDefaultCharset(), bean.getFormHintField(), true);
155         idempotentUrlPatternPanel.setModelBaseBean(bean.getIdempotentUrlPattern(), bean.getAppServerVersion());
156     }
157     
158     private void updateParameterEncoding(String JavaDoc propName, String JavaDoc newValue) {
159         WebAppRoot bean = masterPanel.getBean();
160         if(bean != null) {
161             try {
162                 if(ParameterEncodingPanel.PROP_DEFAULT_CHARSET.equals(propName)) {
163                     bean.setDefaultCharset(newValue);
164                 } else if(ParameterEncodingPanel.PROP_FORM_HINT_FIELD.equals(propName)) {
165                     bean.setFormHintField(newValue);
166                 }
167             } catch(PropertyVetoException JavaDoc ex) {
168             }
169         }
170     }
171     
172     /** -----------------------------------------------------------------------
173      * Implementation of javax.swing.event.TableModelListener
174      */

175     public void tableChanged(TableModelEvent JavaDoc e) {
176         WebAppRoot bean = masterPanel.getBean();
177         if(bean != null) {
178             Object JavaDoc eventSource = e.getSource();
179             if(eventSource == idempotentUrlPatternModel) {
180                 // Nothing to do, same deal as JspConfig
181
}
182
183             // Force property change to be issued by the bean
184
bean.setDirty();
185         }
186     }
187 }
188
Popular Tags