1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp; 26 27 import java.util.ResourceBundle ; 28 import java.beans.PropertyChangeListener ; 29 import java.beans.PropertyChangeEvent ; 30 import javax.swing.SwingUtilities ; 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 47 public class WebAppRootCustomizer extends BaseCustomizer implements PropertyChangeListener { 48 49 53 public static final String CACHE_HELPER_LIST_CHANGED = "CacheHelperListChanged"; public static final String SERVLET_LIST_CHANGED = "ServletListChanged"; 56 57 private static final ResourceBundle webappBundle = ResourceBundle.getBundle( 58 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp.Bundle"); 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 private boolean as81FeaturesVisible; 70 71 72 public WebAppRootCustomizer() { 73 initComponents(); 74 initUserComponents(); 75 } 76 77 public WebAppRoot getBean() { 78 return theBean; 79 } 80 81 86 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 88 89 webAppTabbedPanel = new javax.swing.JTabbedPane (); 90 91 setLayout(new java.awt.GridBagLayout ()); 92 93 webAppTabbedPanel.setTabPlacement(javax.swing.JTabbedPane.BOTTOM); 94 webAppTabbedPanel.addChangeListener(new javax.swing.event.ChangeListener () { 95 public void stateChanged(javax.swing.event.ChangeEvent evt) { 96 webAppTabbedPanelStateChanged(evt); 97 } 98 }); 99 100 gridBagConstraints = new java.awt.GridBagConstraints (); 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 } 109 private void webAppTabbedPanelStateChanged(javax.swing.event.ChangeEvent evt) { showErrors(); 111 } 113 private javax.swing.JTabbedPane webAppTabbedPanel; 115 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 addTitlePanel(webappBundle.getString("TITLE_SunWebApplication")); getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_SunWebApplication")); getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_SunWebApplication")); 133 generalPanel = new WebAppGeneralPanel(this); 135 webAppTabbedPanel.addTab(webappBundle.getString("GENERAL_TAB"), generalPanel); 137 classloaderPanel = new WebAppClassloaderPanel(this); 140 webAppTabbedPanel.addTab(webappBundle.getString("CLASSLOADER_TAB"), classloaderPanel); 142 propertiesPanel = new WebAppPropertiesPanel(this); 144 webAppTabbedPanel.addTab(webappBundle.getString("PROPERTIES_TAB"), propertiesPanel); 146 sessionConfigPanel = new WebAppSessionConfigPanel(this); 148 webAppTabbedPanel.addTab(webappBundle.getString("SESSION_CONFIG_TAB"), sessionConfigPanel); 150 servlet24FeaturesVisible = true; 152 messagesPanel = new WebAppMessagesPanel(this); 153 webAppTabbedPanel.addTab(webappBundle.getString("MESSAGES_TAB"), messagesPanel); 155 localeMappingPanel = new WebAppLocalePanel(this); 157 webAppTabbedPanel.addTab(webappBundle.getString("LOCALE_TAB"), localeMappingPanel); 159 cachePanel = new WebAppCachePanel(this); 161 webAppTabbedPanel.addTab(webappBundle.getString("CACHE_TAB"), cachePanel); 163 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"), null, messagesPanel, null, getMessagesTabIndex()); 195 servlet24FeaturesVisible = true; 196 } 197 } 198 199 private void hideServlet24Panels() { 200 if(servlet24FeaturesVisible) { 201 webAppTabbedPanel.removeTabAt(getMessagesTabIndex()); servlet24FeaturesVisible = false; 203 } 204 } 205 206 private void showAS81Panels() { 207 if(!as81FeaturesVisible) { 208 webAppTabbedPanel.insertTab(webappBundle.getString("PROPERTIES_TAB"), 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); 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 bean) { 260 boolean result = super.setBean(bean); 261 262 if(bean instanceof WebAppRoot) { 263 theBean = (WebAppRoot) bean; 264 result = true; 265 } else { 266 assert (result == false) : 268 "WebAppRootCustomizer was passed wrong bean type in setBean(Object bean)"; 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 int selectedTabIndex = webAppTabbedPanel.getSelectedIndex(); 288 289 if(!as81FeaturesVisible && selectedTabIndex >= PROPERTIES_TAB_INDEX) { 292 selectedTabIndex += NUM_AS81_PANELS; 293 } 294 295 if(!servlet24FeaturesVisible && selectedTabIndex >= MESSAGE_TAB_INDEX) { 298 selectedTabIndex += NUM_SERVLET24_PANELS; 299 } 300 301 return selectedTabIndex; 302 } 303 304 309 public String getHelpId() { 310 String result = "AS_CFG_WebAppGeneral"; 312 switch(getAdjustedTabIndex()) { 314 case 6: 315 result = cachePanel.getHelpId(); 316 break; 317 case 5: 318 result = "AS_CFG_WebAppLocale"; break; 320 case 4: 321 result = "AS_CFG_WebAppMessages"; break; 323 case 3: 324 result = sessionConfigPanel.getHelpId(); 325 break; 326 case 2: 327 result = "AS_CFG_WebAppProperties"; break; 329 case 1: 330 result = "AS_CFG_WebAppClassloader"; break; 332 } 333 334 return result; 335 } 336 337 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 propertyChangeEvent) { 362 if(WebAppRoot.SERVLET_LIST_CHANGED.equals(propertyChangeEvent.getPropertyName())) { 363 SwingUtilities.invokeLater(new Runnable () { 365 public void run() { 366 firePropertyChange(WebAppRootCustomizer.SERVLET_LIST_CHANGED, false, true); 367 } 368 }); 369 } 370 } 371 372 373 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 |