KickJava   Java API By Example, From Geeks To Geeks.

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


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  * WebAppGeneralPanel.java
21  *
22  * Created on November 5, 2003, 4:56 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.awt.event.ItemEvent JavaDoc;
33 import java.beans.PropertyChangeEvent JavaDoc;
34 import java.beans.PropertyChangeListener JavaDoc;
35 import java.beans.PropertyVetoException JavaDoc;
36
37 import javax.swing.event.TableModelEvent JavaDoc;
38 import javax.swing.event.TableModelListener JavaDoc;
39
40 import org.netbeans.modules.j2ee.sun.dd.api.web.JspConfig;
41 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp;
42 import org.netbeans.modules.j2ee.sun.dd.api.web.WebProperty;
43 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion;
44
45 import org.netbeans.modules.j2ee.sun.share.configbean.WebAppRoot;
46 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.BaseCustomizer;
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 WebAppGeneralPanel extends javax.swing.JPanel JavaDoc implements TableModelListener JavaDoc {
59     
60     private static final ResourceBundle JavaDoc webappBundle = ResourceBundle.getBundle(
61         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp.Bundle"); // NOI18N
62

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

66     private WebAppRootCustomizer masterPanel;
67
68     // Table for editing JspConfig web properties
69
private GenericTableModel jspConfigModel;
70     private GenericTablePanel jspConfigPanel;
71
72     // Table for editing Property web properties
73
private GenericTableModel propertiesModel;
74     private GenericTablePanel propertiesPanel;
75
76     // true if AS 8.1+ fields are visible.
77
private boolean as81FeaturesVisible;
78     
79     // true if AS 9.0+ fields are visible.
80
private boolean as90FeaturesVisible;
81     
82     /** Creates new form WebAppGeneralPanel */
83     public WebAppGeneralPanel(WebAppRootCustomizer src) {
84         masterPanel = src;
85
86         initComponents();
87         initUserComponents();
88     }
89
90     /** This method is called from within the constructor to
91      * initialize the form.
92      * WARNING: Do NOT modify this code. The content of this method is
93      * always regenerated by the Form Editor.
94      */

95     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
96
private void initComponents() {
97         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
98
99         jLblContextRoot = new javax.swing.JLabel JavaDoc();
100         jTxtContextRoot = new javax.swing.JTextField JavaDoc();
101         jLblErrorUrl = new javax.swing.JLabel JavaDoc();
102         jTxtErrorUrl = new javax.swing.JTextField JavaDoc();
103         jLblHttpservletSecurityProvider = new javax.swing.JLabel JavaDoc();
104         jTxtHttpservletSecurityProvider = new javax.swing.JTextField JavaDoc();
105
106         setLayout(new java.awt.GridBagLayout JavaDoc());
107
108         getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_WebAppGeneralTab"));
109         getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_WebAppGeneralTab"));
110         jLblContextRoot.setLabelFor(jTxtContextRoot);
111         jLblContextRoot.setText(webappBundle.getString("LBL_ContextRoot_1"));
112         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
113         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
114         gridBagConstraints.ipady = 4;
115         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
116         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
117         add(jLblContextRoot, gridBagConstraints);
118
119         jTxtContextRoot.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
120             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
121                 jTxtContextRootKeyReleased(evt);
122             }
123         });
124
125         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
126         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
127         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
128         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
129         gridBagConstraints.weightx = 1.0;
130         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
131         add(jTxtContextRoot, gridBagConstraints);
132         jTxtContextRoot.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_ContextRoot"));
133         jTxtContextRoot.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_ContextRoot"));
134
135         jLblErrorUrl.setLabelFor(jTxtErrorUrl);
136         jLblErrorUrl.setText(webappBundle.getString("LBL_ErrorUrl_1"));
137         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
138         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
139         gridBagConstraints.ipady = 4;
140         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
141         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
142         add(jLblErrorUrl, gridBagConstraints);
143
144         jTxtErrorUrl.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
145             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
146                 jTxtErrorUrlKeyReleased(evt);
147             }
148         });
149
150         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
151         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
152         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
153         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
154         gridBagConstraints.weightx = 1.0;
155         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
156         add(jTxtErrorUrl, gridBagConstraints);
157
158         jLblHttpservletSecurityProvider.setLabelFor(jTxtHttpservletSecurityProvider);
159         jLblHttpservletSecurityProvider.setText(webappBundle.getString("LBL_HttpservletSecurityProvider_1"));
160         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
161         gridBagConstraints.gridwidth = 2;
162         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
163         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 0);
164         add(jLblHttpservletSecurityProvider, gridBagConstraints);
165
166         jTxtHttpservletSecurityProvider.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
167             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
168                 jTxtHttpservletSecurityProviderKeyReleased(evt);
169             }
170         });
171
172         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
173         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
174         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
175         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 5);
176         add(jTxtHttpservletSecurityProvider, gridBagConstraints);
177
178     }// </editor-fold>//GEN-END:initComponents
179

180     private void jTxtHttpservletSecurityProviderKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtHttpservletSecurityProviderKeyReleased
181
WebAppRoot bean = masterPanel.getBean();
182         if(bean != null) {
183             try {
184                 bean.setHttpservletSecurityProvider(jTxtHttpservletSecurityProvider.getText());
185 // masterPanel.validateField(WebAppRoot.FIELD_HTTP_SERVLET_SECURITY_PROVIDER);
186
} catch(java.beans.PropertyVetoException JavaDoc exception) {
187                 jTxtHttpservletSecurityProvider.setText(bean.getHttpservletSecurityProvider());
188             }
189         }
190     }//GEN-LAST:event_jTxtHttpservletSecurityProviderKeyReleased
191

192     private void jTxtErrorUrlKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtErrorUrlKeyReleased
193
WebAppRoot bean = masterPanel.getBean();
194         if(bean != null) {
195             try {
196                 bean.setErrorUrl(jTxtErrorUrl.getText());
197 // masterPanel.validateField(WebAppRoot.FIELD_ERROR_URL);
198
} catch(java.beans.PropertyVetoException JavaDoc exception) {
199                 jTxtErrorUrl.setText(bean.getErrorUrl());
200             }
201         }
202     }//GEN-LAST:event_jTxtErrorUrlKeyReleased
203

204     private void jTxtContextRootKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtContextRootKeyReleased
205
WebAppRoot bean = masterPanel.getBean();
206         if(bean != null) {
207             try {
208                 bean.setContextRoot(jTxtContextRoot.getText());
209 // masterPanel.validateField(WebAppRoot.FIELD_CONTEXT_ROOT);
210
} catch(java.beans.PropertyVetoException JavaDoc exception) {
211                 jTxtContextRoot.setText(bean.getContextRoot());
212             }
213         }
214     }//GEN-LAST:event_jTxtContextRootKeyReleased
215

216     
217     // Variables declaration - do not modify//GEN-BEGIN:variables
218
private javax.swing.JLabel JavaDoc jLblContextRoot;
219     private javax.swing.JLabel JavaDoc jLblErrorUrl;
220     private javax.swing.JLabel JavaDoc jLblHttpservletSecurityProvider;
221     private javax.swing.JTextField JavaDoc jTxtContextRoot;
222     private javax.swing.JTextField JavaDoc jTxtErrorUrl;
223     private javax.swing.JTextField JavaDoc jTxtHttpservletSecurityProvider;
224     // End of variables declaration//GEN-END:variables
225

226     private void initUserComponents() {
227             
228         as81FeaturesVisible = true;
229         as90FeaturesVisible = true;
230         
231         /** Add call properties table panel :
232          * TableEntry list has three properties: Name, Value, Description
233          */

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

242         // add JspConfig table
243
jspConfigModel = new GenericTableModel(JspConfig.PROPERTY, WebAppRootCustomizer.webPropertyFactory, tableColumns);
244         jspConfigPanel = new GenericTablePanel(jspConfigModel,
245             webappBundle, "JspConfigProperties", // NOI18N - property name
246
DynamicPropertyPanel.class, HelpContext.HELP_WEBAPP_JSPCONFIG_POPUP,
247             PropertyListMapping.getPropertyList(PropertyListMapping.WEBAPP_JSPCONFIG_PROPERTIES));
248         
249         GridBagConstraints JavaDoc 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(0, 6, 0, 5);
255         add(jspConfigPanel, gridBagConstraints);
256         
257         // add Properties table
258
propertiesModel = new GenericTableModel(WebAppRootCustomizer.webPropertyFactory, tableColumns);
259         propertiesPanel = new GenericTablePanel(propertiesModel,
260             webappBundle, "WebProperties", // NOI18N - property name
261
DynamicPropertyPanel.class, HelpContext.HELP_WEBAPP_PROPERTY_POPUP,
262             PropertyListMapping.getPropertyList(PropertyListMapping.WEBAPP_PROPERTIES));
263         
264         gridBagConstraints = new GridBagConstraints JavaDoc();
265         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
266         gridBagConstraints.fill = GridBagConstraints.BOTH;
267         gridBagConstraints.weightx = 1.0;
268         gridBagConstraints.weighty = 1.0;
269         gridBagConstraints.insets = new Insets JavaDoc(0, 6, 0, 5);
270         add(propertiesPanel, gridBagConstraints);
271     }
272     
273     public void addListeners() {
274         jspConfigModel.addTableModelListener(this);
275         propertiesModel.addTableModelListener(this);
276     }
277     
278     public void removeListeners() {
279         propertiesModel.removeTableModelListener(this);
280         jspConfigModel.removeTableModelListener(this);
281     }
282     
283     /** Initialization of all the fields in this panel from the bean that
284      * was passed in.
285      */

286     public void initFields(WebAppRoot bean) {
287         ASDDVersion asVersion = bean.getAppServerVersion();
288
289         jspConfigPanel.setModel(bean.getJspConfig(), asVersion);
290         propertiesPanel.setModel(bean.getProperties(), asVersion);
291
292         if(ASDDVersion.SUN_APPSERVER_8_1.compareTo(bean.getAppServerVersion()) <= 0) {
293             showAS81Fields();
294             jTxtContextRoot.setText(bean.getContextRoot());
295             jTxtErrorUrl.setText(bean.getErrorUrl());
296         } else {
297             hideAS81Fields();
298         }
299         
300         if(ASDDVersion.SUN_APPSERVER_9_0.compareTo(bean.getAppServerVersion()) <= 0) {
301             showAS90Fields();
302             jTxtHttpservletSecurityProvider.setText(bean.getHttpservletSecurityProvider());
303         } else {
304             hideAS90Fields();
305         }
306         
307     }
308         
309     // TODO after 5.0, generalize version based field display for multiple (> 2)
310
// appserver versions. (!PW note: this is the first panel to have changes across
311
// 3 revisions of the relevant DTD.)
312
//
313
// Generalization idea: Tag each control a "MinVersion" property whose value is the instance
314
// of AsDDVersion that corresponds with the needed appserver version. Could later tag
315
// with "MaxVersion", or even "ExcludeVersion", if necessary.
316
//
317
private void showAS81Fields() {
318         if(!as81FeaturesVisible) {
319             jLblContextRoot.setVisible(true);
320             jTxtContextRoot.setVisible(true);
321             jLblErrorUrl.setVisible(true);
322             jTxtErrorUrl.setVisible(true);
323             
324             as81FeaturesVisible = true;
325         }
326     }
327     
328     private void hideAS81Fields() {
329         if(as81FeaturesVisible) {
330             jLblContextRoot.setVisible(false);
331             jTxtContextRoot.setVisible(false);
332             jLblErrorUrl.setVisible(false);
333             jTxtErrorUrl.setVisible(false);
334             
335             as81FeaturesVisible = false;
336         }
337     }
338     
339     private void showAS90Fields() {
340         if(!as90FeaturesVisible) {
341             jLblHttpservletSecurityProvider.setVisible(true);
342             jTxtHttpservletSecurityProvider.setVisible(true);
343             
344             as90FeaturesVisible = true;
345         }
346     }
347     
348     private void hideAS90Fields() {
349         if(as90FeaturesVisible) {
350             jLblHttpservletSecurityProvider.setVisible(false);
351             jTxtHttpservletSecurityProvider.setVisible(false);
352             
353             as90FeaturesVisible = false;
354         }
355     }
356
357     /** -----------------------------------------------------------------------
358      * Implementation of javax.swing.event.TableModelListener
359      */

360     public void tableChanged(TableModelEvent JavaDoc e) {
361         WebAppRoot bean = masterPanel.getBean();
362         if(bean != null) {
363             try {
364                 Object JavaDoc eventSource = e.getSource();
365                 if(eventSource == jspConfigModel) {
366                     // This statement will not produce a change event because
367
// of the way we handle property storage for properties like
368
// this one. (The JspConfig we're modifying already is the
369
// one owned by the bean).
370
//
371
// bean.setJspConfig((JspConfig) jspConfigModel.getDataBaseBean());
372
} else if(eventSource == propertiesModel) {
373                     bean.setProperties(propertiesModel.getData());
374                 }
375                 
376                 // Force property change to be issued by the bean
377
bean.setDirty();
378             } catch(PropertyVetoException JavaDoc ex) {
379                 // FIXME undo whatever changed... how?
380
}
381         }
382     }
383 }
384
Popular Tags