KickJava   Java API By Example, From Geeks To Geeks.

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


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  * WebAppRootCustomizer.java
21  *
22  * Created on September 4, 2003, 5:28 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp;
26
27 import java.util.ResourceBundle JavaDoc;
28 import java.beans.PropertyChangeListener JavaDoc;
29 import java.beans.PropertyChangeEvent JavaDoc;
30 import javax.swing.SwingUtilities JavaDoc;
31
32 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
33 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion;
34
35 import org.netbeans.modules.j2ee.sun.share.configbean.StorageBeanFactory;
36 import org.netbeans.modules.j2ee.sun.share.configbean.WebAppRoot;
37 import org.netbeans.modules.j2ee.sun.share.configbean.ServletVersion;
38 import org.netbeans.modules.j2ee.sun.share.configbean.ErrorMessageDB;
39 import org.netbeans.modules.j2ee.sun.share.configbean.ValidationError;
40 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.BaseCustomizer;
41 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableModel;
42
43 /**
44  *
45  * @author Peter Williams
46  */

47 public class WebAppRootCustomizer extends BaseCustomizer implements PropertyChangeListener JavaDoc {
48
49     /** These two properties are defined here because they are specifically for
50      * this customizer to indicate the specific event only to it's subcomponents,
51      * not to anyone else.
52      */

53     public static final String JavaDoc CACHE_HELPER_LIST_CHANGED = "CacheHelperListChanged"; //NOI18N
54
public static final String JavaDoc SERVLET_LIST_CHANGED = "ServletListChanged"; //NOI18N
55

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

60     private static final int NUM_SERVLET24_PANELS = 1;
61     private static final int NUM_AS81_PANELS = 1;
62     private static final int PROPERTIES_TAB_INDEX = 2;
63     private static final int MESSAGE_TAB_INDEX = 4;
64     
65     private WebAppRoot theBean;
66     private boolean servlet24FeaturesVisible;
67     
68     // true if AS 8.1+ fields are visible.
69
private boolean as81FeaturesVisible;
70     
71     /** Creates new form WebAppRootCustomizer */
72     public WebAppRootCustomizer() {
73         initComponents();
74         initUserComponents();
75     }
76     
77     public WebAppRoot getBean() {
78         return theBean;
79     }
80     
81     /** This method is called from within the constructor to
82      * initialize the form.
83      * WARNING: Do NOT modify this code. The content of this method is
84      * always regenerated by the Form Editor.
85      */

86     private void initComponents() {//GEN-BEGIN:initComponents
87
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
88
89         webAppTabbedPanel = new javax.swing.JTabbedPane JavaDoc();
90
91         setLayout(new java.awt.GridBagLayout JavaDoc());
92
93         webAppTabbedPanel.setTabPlacement(javax.swing.JTabbedPane.BOTTOM);
94         webAppTabbedPanel.addChangeListener(new javax.swing.event.ChangeListener JavaDoc() {
95             public void stateChanged(javax.swing.event.ChangeEvent JavaDoc evt) {
96                 webAppTabbedPanelStateChanged(evt);
97             }
98         });
99
100         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
101         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
102         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
103         gridBagConstraints.weightx = 1.0;
104         gridBagConstraints.weighty = 1.0;
105         add(webAppTabbedPanel, gridBagConstraints);
106
107     }//GEN-END:initComponents
108

109     private void webAppTabbedPanelStateChanged(javax.swing.event.ChangeEvent JavaDoc evt) {//GEN-FIRST:event_webAppTabbedPanelStateChanged
110
showErrors();
111     }//GEN-LAST:event_webAppTabbedPanelStateChanged
112

113     // Variables declaration - do not modify//GEN-BEGIN:variables
114
private javax.swing.JTabbedPane JavaDoc webAppTabbedPanel;
115     // End of variables declaration//GEN-END:variables
116

117     private WebAppGeneralPanel generalPanel;
118     private WebAppClassloaderPanel classloaderPanel;
119     private WebAppPropertiesPanel propertiesPanel;
120     private WebAppSessionConfigPanel sessionConfigPanel;
121     private WebAppMessagesPanel messagesPanel;
122     private WebAppLocalePanel localeMappingPanel;
123     private WebAppCachePanel cachePanel;
124     
125     private void initUserComponents() {
126         as81FeaturesVisible = true;
127         
128         // Add title panel
129
addTitlePanel(webappBundle.getString("TITLE_SunWebApplication")); // NOI18N
130
getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_SunWebApplication")); // NOI18N
131
getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_SunWebApplication")); // NOI18N
132

133         // Add general panel
134
generalPanel = new WebAppGeneralPanel(this);
135         webAppTabbedPanel.addTab(webappBundle.getString("GENERAL_TAB"), generalPanel); // NOI18N
136

137         // Add classloader panel
138
// TODO - Ideally, this is a tab for AS 8.1, 9.0, but merely a subpanel on general for AS 7.0
139
classloaderPanel = new WebAppClassloaderPanel(this);
140         webAppTabbedPanel.addTab(webappBundle.getString("CLASSLOADER_TAB"), classloaderPanel); // NOI18N
141

142         // Add session configuration panel
143
propertiesPanel = new WebAppPropertiesPanel(this);
144         webAppTabbedPanel.addTab(webappBundle.getString("PROPERTIES_TAB"), propertiesPanel); // NOI18N
145

146         // Add session configuration panel
147
sessionConfigPanel = new WebAppSessionConfigPanel(this);
148         webAppTabbedPanel.addTab(webappBundle.getString("SESSION_CONFIG_TAB"), sessionConfigPanel); // NOI18N
149

150         // Add messages panel
151
servlet24FeaturesVisible = true;
152         messagesPanel = new WebAppMessagesPanel(this);
153         webAppTabbedPanel.addTab(webappBundle.getString("MESSAGES_TAB"), messagesPanel); // NOI18N
154

155         // Add locale panel
156
localeMappingPanel = new WebAppLocalePanel(this);
157         webAppTabbedPanel.addTab(webappBundle.getString("LOCALE_TAB"), localeMappingPanel); // NOI18N
158

159         // Add cache panel
160
cachePanel = new WebAppCachePanel(this);
161         webAppTabbedPanel.addTab(webappBundle.getString("CACHE_TAB"), cachePanel); // NOI18N
162

163         // Add error panel
164
addErrorPanel();
165     }
166     
167     protected void initFields() {
168         generalPanel.initFields(theBean);
169         classloaderPanel.initFields(theBean);
170         
171         if(ASDDVersion.SUN_APPSERVER_8_1.compareTo(theBean.getAppServerVersion()) <= 0) {
172             showAS81Panels();
173             propertiesPanel.initFields(theBean);
174         } else {
175             hideAS81Panels();
176         }
177         
178         sessionConfigPanel.initFields(theBean);
179         
180         if(theBean.getJ2EEModuleVersion().compareTo(ServletVersion.SERVLET_2_4) >= 0) {
181             showServlet24Panels();
182             messagesPanel.initFields(theBean);
183         } else {
184             hideServlet24Panels();
185         }
186         
187         localeMappingPanel.initFields(theBean);
188         cachePanel.initFields(theBean);
189     }
190     
191     private void showServlet24Panels() {
192         if(!servlet24FeaturesVisible) {
193             webAppTabbedPanel.insertTab(webappBundle.getString("MESSAGES_TAB"), // NOI18N
194
null, messagesPanel, null, getMessagesTabIndex());
195             servlet24FeaturesVisible = true;
196         }
197     }
198     
199     private void hideServlet24Panels() {
200         if(servlet24FeaturesVisible) {
201             webAppTabbedPanel.removeTabAt(getMessagesTabIndex()); // Remove messages panel
202
servlet24FeaturesVisible = false;
203         }
204     }
205     
206     private void showAS81Panels() {
207         if(!as81FeaturesVisible) {
208             webAppTabbedPanel.insertTab(webappBundle.getString("PROPERTIES_TAB"), // NOI18N
209
null, propertiesPanel, null, PROPERTIES_TAB_INDEX);
210             as81FeaturesVisible = true;
211         }
212     }
213     
214     private void hideAS81Panels() {
215         if(as81FeaturesVisible) {
216             webAppTabbedPanel.removeTabAt(PROPERTIES_TAB_INDEX); // Remove properties panel
217
as81FeaturesVisible = false;
218         }
219     }
220     
221     public void addListeners() {
222         super.addListeners();
223         
224         generalPanel.addListeners();
225         classloaderPanel.addListeners();
226         propertiesPanel.addListeners();
227         sessionConfigPanel.addListeners();
228         messagesPanel.addListeners();
229         localeMappingPanel.addListeners();
230         cachePanel.addListeners();
231         
232         theBean.addPropertyChangeListener(this);
233     }
234     
235     public void removeListeners() {
236         super.removeListeners();
237         
238         cachePanel.removeListeners();
239         localeMappingPanel.removeListeners();
240         messagesPanel.removeListeners();
241         sessionConfigPanel.removeListeners();
242         propertiesPanel.removeListeners();
243         classloaderPanel.removeListeners();
244         generalPanel.removeListeners();
245         
246         theBean.removePropertyChangeListener(this);
247     }
248     
249     public void partitionStateChanged(ErrorMessageDB.PartitionState oldState, ErrorMessageDB.PartitionState newState) {
250         if(newState.getPartition() == getPartition()) {
251             showErrors();
252         }
253         
254         if(oldState.hasMessages() != newState.hasMessages()) {
255             webAppTabbedPanel.setIconAt(newState.getPartition().getTabIndex(), newState.hasMessages() ? panelErrorIcon : null);
256         }
257     }
258     
259     protected boolean setBean(Object JavaDoc bean) {
260         boolean result = super.setBean(bean);
261         
262         if(bean instanceof WebAppRoot) {
263             theBean = (WebAppRoot) bean;
264             result = true;
265         } else {
266             // if bean is not a WebAppRoot, then it shouldn't have passed Base either.
267
assert (result == false) :
268                 "WebAppRootCustomizer was passed wrong bean type in setBean(Object bean)"; // NOI18N
269

270             theBean = null;
271             result = false;
272         }
273         
274         return result;
275     }
276     
277     private int getMessagesTabIndex() {
278         int result = MESSAGE_TAB_INDEX;
279         if(!as81FeaturesVisible) {
280             result -= 1;
281         }
282         return result;
283     }
284     
285     private int getAdjustedTabIndex() {
286         // Determine which tab has focus.
287
int selectedTabIndex = webAppTabbedPanel.getSelectedIndex();
288         
289         // Adjust tab index to normalize tab indices of tabs that come after
290
// the AS 8.1 specific panels, in case they are not showing.
291
if(!as81FeaturesVisible && selectedTabIndex >= PROPERTIES_TAB_INDEX) {
292             selectedTabIndex += NUM_AS81_PANELS;
293         }
294         
295         // Adjust tab index to normalize tab indices of tabs that come after
296
// the Servlet 2.4 specific panels, in case they are not showing.
297
if(!servlet24FeaturesVisible && selectedTabIndex >= MESSAGE_TAB_INDEX) {
298             selectedTabIndex += NUM_SERVLET24_PANELS;
299         }
300         
301         return selectedTabIndex;
302     }
303     
304     /** Returns the help ID for sun-web-app. Not only does this customizer have
305      * several (4-6) tabs, two of those have subtabs.
306      *
307      * @return String representing the current active help ID for this customizer
308      */

309     public String JavaDoc getHelpId() {
310         String JavaDoc result = "AS_CFG_WebAppGeneral"; // NOI18N
311

312         // Determine which tab has focus and return help context for that tab.
313
switch(getAdjustedTabIndex()) {
314             case 6:
315                 result = cachePanel.getHelpId();
316                 break;
317             case 5:
318                 result = "AS_CFG_WebAppLocale"; // NOI18N
319
break;
320             case 4:
321                 result = "AS_CFG_WebAppMessages"; // NOI18N
322
break;
323             case 3:
324                 result = sessionConfigPanel.getHelpId();
325                 break;
326             case 2:
327                 result = "AS_CFG_WebAppProperties"; // NOI18N
328
break;
329             case 1:
330                 result = "AS_CFG_WebAppClassloader"; // NOI18N
331
break;
332         }
333         
334         return result;
335     }
336     
337     /** Retrieve the partition that should be associated with the current
338      * selected tab.
339      *
340      * @return ValidationError.Partition
341      */

342     public ValidationError.Partition getPartition() {
343         switch(getAdjustedTabIndex()) {
344             case 6:
345                 return cachePanel.getPartition();
346             case 5:
347                 return ValidationError.PARTITION_WEB_LOCALE;
348             case 4:
349                 return ValidationError.PARTITION_WEB_MESSAGES;
350             case 3:
351                 return sessionConfigPanel.getPartition();
352             case 2:
353                 return ValidationError.PARTITION_WEB_PROPERTIES;
354             case 1:
355                 return ValidationError.PARTITION_WEB_CLASSLOADER;
356             default:
357                 return ValidationError.PARTITION_WEB_GENERAL;
358         }
359     }
360     
361     public void propertyChange(PropertyChangeEvent JavaDoc propertyChangeEvent) {
362         if(WebAppRoot.SERVLET_LIST_CHANGED.equals(propertyChangeEvent.getPropertyName())) {
363             // Make sure we handle this on the swing event thread from here on out.
364
SwingUtilities.invokeLater(new Runnable JavaDoc() {
365                 public void run() {
366                     firePropertyChange(WebAppRootCustomizer.SERVLET_LIST_CHANGED, false, true);
367                 }
368             });
369         }
370     }
371     
372     
373     // New for migration to sun DD API model. Factory instance to pass to generic table model
374
// to allow it to create webProperty beans. Since web property is so common, this factory
375
// is package-protected and used by several subpanels as well.
376
static GenericTableModel.ParentPropertyFactory webPropertyFactory =
377         new GenericTableModel.ParentPropertyFactory() {
378             public CommonDDBean newParentProperty(ASDDVersion asVersion) {
379                 return StorageBeanFactory.getStorageBeanFactory(asVersion).createWebProperty();
380             }
381         };
382 }
383
Popular Tags