1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp; 26 27 import java.util.Arrays ; 28 import java.util.ArrayList ; 29 import java.util.Collection ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 import java.util.ResourceBundle ; 33 import java.text.MessageFormat ; 34 35 import java.awt.Dimension ; 36 import java.awt.BorderLayout ; 37 import java.awt.GridBagConstraints ; 38 import java.awt.Insets ; 39 import java.awt.event.ItemEvent ; 40 41 import java.beans.PropertyVetoException ; 42 import java.beans.PropertyChangeListener ; 43 import java.beans.PropertyChangeEvent ; 44 45 import javax.swing.JPanel ; 46 import javax.swing.DefaultComboBoxModel ; 47 import javax.swing.event.TableModelEvent ; 48 import javax.swing.event.TableModelListener ; 49 50 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 51 import org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException; 52 import org.netbeans.modules.j2ee.sun.dd.api.web.CacheMapping; 53 import org.netbeans.modules.j2ee.sun.dd.api.web.ConstraintField; 54 55 import org.netbeans.modules.j2ee.sun.share.Constants; 56 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion; 57 import org.netbeans.modules.j2ee.sun.share.configbean.StorageBeanFactory; 58 import org.netbeans.modules.j2ee.sun.share.configbean.Utils; 59 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.BaseCustomizer; 60 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.InputDialog; 61 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.TextMapping; 62 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableModel; 63 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTablePanel; 64 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.HelpContext; 65 66 67 71 public class CachePolicyPanel extends JPanel implements TableModelListener { 72 73 74 private static final ResourceBundle commonBundle = ResourceBundle.getBundle( 75 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); 77 private static final ResourceBundle webappBundle = ResourceBundle.getBundle( 78 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp.Bundle"); 80 private static final TextMapping [] scopeTypes = ScopeMapping.getScopeMappings(); 81 private static final TextMapping [] keyScopeTypes = ScopeMapping.getKeyScopeMappings(); 82 83 private CacheMapping theCacheMapping; 84 85 private boolean dataChanged; 87 private boolean timeoutEnabled; 88 private boolean refreshFieldEnabled; 89 90 private DefaultComboBoxModel timeoutScopeModel; 91 private DefaultComboBoxModel refreshFieldScopeModel; 92 93 private CacheMapping newCacheMapping; 95 private List httpMethods; 96 private List constraints; 97 98 private GenericTableModel dispatcherModel; 100 private GenericTablePanel dispatcherPanel; 101 102 private GenericTableModel keyFieldsModel; 104 private GenericTablePanel keyFieldsPanel; 105 106 private GenericTableModel constraintFieldsModel; 108 private GenericTablePanel constraintFieldsPanel; 109 110 private boolean as81FeaturesVisible; 112 113 private boolean initializingFields; 115 116 117 public CachePolicyPanel(ASDDVersion asVersion, CacheMapping mapping) { 118 theCacheMapping = mapping; 119 newCacheMapping = (CacheMapping) mapping.clone(); 120 121 String [] methodArray = newCacheMapping.getHttpMethod(); 122 httpMethods = new ArrayList (methodArray.length); 123 for(int i = 0; i < methodArray.length; i++) { 124 httpMethods.add(methodArray[i]); 125 } 126 127 constraints = Utils.arrayToList(newCacheMapping.getConstraintField()); 128 129 dataChanged = false; 130 initializingFields = false; 131 132 initComponents(); 133 initUserComponents(); 134 initFields(asVersion); 135 addListeners(); 136 } 137 138 143 private void initComponents() { 145 java.awt.GridBagConstraints gridBagConstraints; 146 147 jLblCachePolicy = new javax.swing.JLabel (); 148 jPnlTimeout = new javax.swing.JPanel (); 149 jLblTimeoutName = new javax.swing.JLabel (); 150 jTxtTimeoutName = new javax.swing.JTextField (); 151 jLblTimeoutValue = new javax.swing.JLabel (); 152 jTxtTimeoutValue = new javax.swing.JTextField (); 153 jLblTimeoutScope = new javax.swing.JLabel (); 154 jCbxTimeoutScope = new javax.swing.JComboBox (); 155 jPnlRefresh = new javax.swing.JPanel (); 156 jLblRefreshFieldName = new javax.swing.JLabel (); 157 jTxtRefreshFieldName = new javax.swing.JTextField (); 158 jLblRefreshScope = new javax.swing.JLabel (); 159 jCbxRefreshScope = new javax.swing.JComboBox (); 160 jPnlHttpMethods = new javax.swing.JPanel (); 161 jLblHttpMethods = new javax.swing.JLabel (); 162 jChkHttpGet = new javax.swing.JCheckBox (); 163 jChkHttpPost = new javax.swing.JCheckBox (); 164 165 setLayout(new java.awt.GridBagLayout ()); 166 167 setPreferredSize(new java.awt.Dimension (600, 600)); 168 jLblCachePolicy.setText(webappBundle.getString("LBL_CachePolicy")); 169 gridBagConstraints = new java.awt.GridBagConstraints (); 170 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 171 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 172 gridBagConstraints.weightx = 1.0; 173 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 174 add(jLblCachePolicy, gridBagConstraints); 175 176 jPnlTimeout.setLayout(new java.awt.GridBagLayout ()); 177 178 jPnlTimeout.setBorder(javax.swing.BorderFactory.createEtchedBorder()); 179 jLblTimeoutName.setDisplayedMnemonic(webappBundle.getString("MNE_TimeoutName").charAt(0)); 180 jLblTimeoutName.setLabelFor(jTxtTimeoutName); 181 jLblTimeoutName.setText(webappBundle.getString("LBL_TimeoutName_1")); 182 gridBagConstraints = new java.awt.GridBagConstraints (); 183 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 184 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 185 jPnlTimeout.add(jLblTimeoutName, gridBagConstraints); 186 187 jTxtTimeoutName.addKeyListener(new java.awt.event.KeyAdapter () { 188 public void keyReleased(java.awt.event.KeyEvent evt) { 189 jTxtTimeoutNameKeyReleased(evt); 190 } 191 }); 192 193 gridBagConstraints = new java.awt.GridBagConstraints (); 194 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 195 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 196 gridBagConstraints.weightx = 1.0; 197 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 5); 198 jPnlTimeout.add(jTxtTimeoutName, gridBagConstraints); 199 jTxtTimeoutName.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_TimeoutName")); 200 jTxtTimeoutName.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_TimeoutName")); 201 202 jLblTimeoutValue.setDisplayedMnemonic(webappBundle.getString("MNE_Timeout").charAt(0)); 203 jLblTimeoutValue.setLabelFor(jTxtTimeoutValue); 204 jLblTimeoutValue.setText(webappBundle.getString("LBL_Timeout_1")); 205 gridBagConstraints = new java.awt.GridBagConstraints (); 206 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 207 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 208 jPnlTimeout.add(jLblTimeoutValue, gridBagConstraints); 209 210 jTxtTimeoutValue.addKeyListener(new java.awt.event.KeyAdapter () { 211 public void keyReleased(java.awt.event.KeyEvent evt) { 212 jTxtTimeoutValueKeyReleased(evt); 213 } 214 }); 215 216 gridBagConstraints = new java.awt.GridBagConstraints (); 217 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 218 gridBagConstraints.weightx = 1.0; 219 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 220 jPnlTimeout.add(jTxtTimeoutValue, gridBagConstraints); 221 jTxtTimeoutValue.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_Timeout")); 222 jTxtTimeoutValue.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_Timeout")); 223 224 jLblTimeoutScope.setDisplayedMnemonic(webappBundle.getString("MNE_TimeoutScope").charAt(0)); 225 jLblTimeoutScope.setLabelFor(jCbxTimeoutScope); 226 jLblTimeoutScope.setText(webappBundle.getString("LBL_TimeoutScope_1")); 227 gridBagConstraints = new java.awt.GridBagConstraints (); 228 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 229 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 230 jPnlTimeout.add(jLblTimeoutScope, gridBagConstraints); 231 232 jCbxTimeoutScope.setPrototypeDisplayValue(""); 233 jCbxTimeoutScope.addActionListener(new java.awt.event.ActionListener () { 234 public void actionPerformed(java.awt.event.ActionEvent evt) { 235 jCbxTimeoutScopeActionPerformed(evt); 236 } 237 }); 238 239 gridBagConstraints = new java.awt.GridBagConstraints (); 240 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 241 gridBagConstraints.weightx = 1.0; 242 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 5); 243 jPnlTimeout.add(jCbxTimeoutScope, gridBagConstraints); 244 jCbxTimeoutScope.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_TimeoutScope")); 245 jCbxTimeoutScope.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_TimeoutScope")); 246 247 gridBagConstraints = new java.awt.GridBagConstraints (); 248 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 249 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 250 gridBagConstraints.weightx = 1.0; 251 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 5); 252 add(jPnlTimeout, gridBagConstraints); 253 254 jPnlRefresh.setLayout(new java.awt.GridBagLayout ()); 255 256 jPnlRefresh.setBorder(javax.swing.BorderFactory.createEtchedBorder()); 257 jLblRefreshFieldName.setDisplayedMnemonic(webappBundle.getString("MNE_RefreshFieldName").charAt(0)); 258 jLblRefreshFieldName.setLabelFor(jTxtRefreshFieldName); 259 jLblRefreshFieldName.setText(webappBundle.getString("LBL_RefreshFieldName_1")); 260 gridBagConstraints = new java.awt.GridBagConstraints (); 261 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 262 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 263 jPnlRefresh.add(jLblRefreshFieldName, gridBagConstraints); 264 265 jTxtRefreshFieldName.addKeyListener(new java.awt.event.KeyAdapter () { 266 public void keyReleased(java.awt.event.KeyEvent evt) { 267 jTxtRefreshFieldNameKeyReleased(evt); 268 } 269 }); 270 271 gridBagConstraints = new java.awt.GridBagConstraints (); 272 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 273 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 274 gridBagConstraints.weightx = 1.0; 275 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 5); 276 jPnlRefresh.add(jTxtRefreshFieldName, gridBagConstraints); 277 jTxtRefreshFieldName.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_RefreshFieldName")); 278 jTxtRefreshFieldName.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_RefreshFieldName")); 279 280 jLblRefreshScope.setDisplayedMnemonic(webappBundle.getString("MNE_RefreshScope").charAt(0)); 281 jLblRefreshScope.setLabelFor(jCbxRefreshScope); 282 jLblRefreshScope.setText(webappBundle.getString("LBL_RefreshScope_1")); 283 gridBagConstraints = new java.awt.GridBagConstraints (); 284 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 285 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 286 jPnlRefresh.add(jLblRefreshScope, gridBagConstraints); 287 288 jCbxRefreshScope.setPrototypeDisplayValue(""); 289 jCbxRefreshScope.addActionListener(new java.awt.event.ActionListener () { 290 public void actionPerformed(java.awt.event.ActionEvent evt) { 291 jCbxRefreshScopeActionPerformed(evt); 292 } 293 }); 294 295 gridBagConstraints = new java.awt.GridBagConstraints (); 296 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 297 gridBagConstraints.weightx = 1.0; 298 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 5); 299 jPnlRefresh.add(jCbxRefreshScope, gridBagConstraints); 300 jCbxRefreshScope.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_RefreshScope")); 301 jCbxRefreshScope.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_RefreshScope")); 302 303 gridBagConstraints = new java.awt.GridBagConstraints (); 304 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 305 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 306 gridBagConstraints.weightx = 1.0; 307 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 308 add(jPnlRefresh, gridBagConstraints); 309 310 jPnlHttpMethods.setLayout(new java.awt.GridBagLayout ()); 311 312 jPnlHttpMethods.setBorder(javax.swing.BorderFactory.createEtchedBorder()); 313 jLblHttpMethods.setText(webappBundle.getString("LBL_HttpMethods_1")); 314 gridBagConstraints = new java.awt.GridBagConstraints (); 315 gridBagConstraints.gridheight = 3; 316 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 317 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 318 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 319 jPnlHttpMethods.add(jLblHttpMethods, gridBagConstraints); 320 321 jChkHttpGet.setMnemonic(webappBundle.getString("MNE_HttpGet").charAt(0)); 322 jChkHttpGet.setText(webappBundle.getString("LBL_HttpGet")); 323 jChkHttpGet.addItemListener(new java.awt.event.ItemListener () { 324 public void itemStateChanged(java.awt.event.ItemEvent evt) { 325 jChkHttpGetItemStateChanged(evt); 326 } 327 }); 328 329 gridBagConstraints = new java.awt.GridBagConstraints (); 330 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 331 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 332 gridBagConstraints.weightx = 1.0; 333 gridBagConstraints.insets = new java.awt.Insets (2, 6, 0, 5); 334 jPnlHttpMethods.add(jChkHttpGet, gridBagConstraints); 335 jChkHttpGet.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_HttpGet")); 336 jChkHttpGet.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_HttpGet")); 337 338 jChkHttpPost.setMnemonic(webappBundle.getString("MNE_HttpPost").charAt(0)); 339 jChkHttpPost.setText(webappBundle.getString("LBL_HttpPost")); 340 jChkHttpPost.addItemListener(new java.awt.event.ItemListener () { 341 public void itemStateChanged(java.awt.event.ItemEvent evt) { 342 jChkHttpPostItemStateChanged(evt); 343 } 344 }); 345 346 gridBagConstraints = new java.awt.GridBagConstraints (); 347 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 348 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 349 gridBagConstraints.weightx = 1.0; 350 gridBagConstraints.insets = new java.awt.Insets (2, 6, 2, 5); 351 jPnlHttpMethods.add(jChkHttpPost, gridBagConstraints); 352 jChkHttpPost.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_HttpPost")); 353 jChkHttpPost.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_HttpPost")); 354 355 gridBagConstraints = new java.awt.GridBagConstraints (); 356 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 357 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 358 gridBagConstraints.weightx = 1.0; 359 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 360 add(jPnlHttpMethods, gridBagConstraints); 361 362 } 364 private void jChkHttpPostItemStateChanged(java.awt.event.ItemEvent evt) { handleHttpMethodSelection(evt, "POST"); } 368 private void jChkHttpGetItemStateChanged(java.awt.event.ItemEvent evt) { handleHttpMethodSelection(evt, "GET"); } 372 private void jCbxRefreshScopeActionPerformed(java.awt.event.ActionEvent evt) { if(!initializingFields) { 374 TextMapping scope = (TextMapping) refreshFieldScopeModel.getSelectedItem(); 375 newCacheMapping.setRefreshFieldScope(normalizeBlank(scope.getXMLString())); 376 setDataChanged(true); 377 } 378 } 380 private void jTxtRefreshFieldNameKeyReleased(java.awt.event.KeyEvent evt) { String refreshFieldName = jTxtRefreshFieldName.getText(); 382 newCacheMapping.setRefreshFieldName(refreshFieldName); 383 384 if(refreshFieldEnabled != Utils.notEmpty(refreshFieldName)) { 385 enableRefreshField(!refreshFieldEnabled); 386 } 387 388 setDataChanged(true); 389 } 391 private void jCbxTimeoutScopeActionPerformed(java.awt.event.ActionEvent evt) { if(!initializingFields) { 393 TextMapping scope = (TextMapping) timeoutScopeModel.getSelectedItem(); 394 newCacheMapping.setTimeoutScope(normalizeBlank(scope.getXMLString())); 395 setDataChanged(true); 396 } 397 } 399 private void jTxtTimeoutValueKeyReleased(java.awt.event.KeyEvent evt) { newCacheMapping.setTimeout(jTxtTimeoutValue.getText()); 401 setDataChanged(true); 402 } 404 private void jTxtTimeoutNameKeyReleased(java.awt.event.KeyEvent evt) { String timeoutName = jTxtTimeoutName.getText(); 406 407 if(Utils.notEmpty(timeoutName) && newCacheMapping.getTimeout() == null) { 411 newCacheMapping.setTimeout(""); } 413 414 newCacheMapping.setTimeoutName(timeoutName); 415 416 if(timeoutEnabled != Utils.notEmpty(timeoutName)) { 417 enableTimeout(!timeoutEnabled); 418 } 419 420 setDataChanged(true); 421 } 423 424 private javax.swing.JComboBox jCbxRefreshScope; 426 private javax.swing.JComboBox jCbxTimeoutScope; 427 private javax.swing.JCheckBox jChkHttpGet; 428 private javax.swing.JCheckBox jChkHttpPost; 429 private javax.swing.JLabel jLblCachePolicy; 430 private javax.swing.JLabel jLblHttpMethods; 431 private javax.swing.JLabel jLblRefreshFieldName; 432 private javax.swing.JLabel jLblRefreshScope; 433 private javax.swing.JLabel jLblTimeoutName; 434 private javax.swing.JLabel jLblTimeoutScope; 435 private javax.swing.JLabel jLblTimeoutValue; 436 private javax.swing.JPanel jPnlHttpMethods; 437 private javax.swing.JPanel jPnlRefresh; 438 private javax.swing.JPanel jPnlTimeout; 439 private javax.swing.JTextField jTxtRefreshFieldName; 440 private javax.swing.JTextField jTxtTimeoutName; 441 private javax.swing.JTextField jTxtTimeoutValue; 442 444 private void initUserComponents() { 445 as81FeaturesVisible = true; 446 447 timeoutScopeModel = new DefaultComboBoxModel (); 449 for(int i = 0; i < scopeTypes.length; i++) { 450 timeoutScopeModel.addElement(scopeTypes[i]); 451 } 452 jCbxTimeoutScope.setModel(timeoutScopeModel); 453 454 refreshFieldScopeModel = new DefaultComboBoxModel (); 456 for(int i = 0; i < keyScopeTypes.length; i++) { 457 refreshFieldScopeModel.addElement(keyScopeTypes[i]); 458 } 459 jCbxRefreshScope.setModel(refreshFieldScopeModel); 460 461 464 ArrayList tableColumns = new ArrayList (1); 465 tableColumns.add(new GenericTableModel.ValueEntry(CacheMapping.DISPATCHER, "Dispatcher", webappBundle, "Dispatcher", true, false)); 468 dispatcherModel = new GenericTableModel(CacheMapping.DISPATCHER, tableColumns); 470 dispatcherPanel = new GenericTablePanel(dispatcherModel, 471 webappBundle, "Dispatcher", HelpContext.HELP_CACHE_MAPPING_DISPATCHER_POPUP); 473 dispatcherPanel.setHeadingMnemonic(webappBundle.getString("MNE_Dispatcher").charAt(0)); 475 GridBagConstraints gridBagConstraints = new GridBagConstraints (); 476 gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; 477 gridBagConstraints.fill = GridBagConstraints.BOTH; 478 gridBagConstraints.weightx = 1.0; 479 gridBagConstraints.weighty = 1.0; 480 gridBagConstraints.insets = new Insets (0, 6, 0, 5); 481 add(dispatcherPanel, gridBagConstraints); 482 483 486 tableColumns = new ArrayList (2); 487 tableColumns.add(new GenericTableModel.AttributeEntry(CacheMapping.KEY_FIELD, "Name", webappBundle.getString("LBL_KeyFieldName"), true)); tableColumns.add(new GenericTableModel.AttributeEntry(CacheMapping.KEY_FIELD, "Scope", webappBundle.getString("LBL_KeyFieldScope"), false)); 492 keyFieldsModel = new GenericTableModel(CacheMapping.KEY_FIELD, tableColumns); 494 keyFieldsPanel = new GenericTablePanel(keyFieldsModel, 495 webappBundle, "KeyField", KeyFieldEntryPanel.class, 497 HelpContext.HELP_CACHE_MAPPING_KEYFIELD_POPUP); 498 keyFieldsPanel.setHeadingMnemonic(webappBundle.getString("MNE_KeyField").charAt(0)); 500 gridBagConstraints = new GridBagConstraints (); 501 gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; 502 gridBagConstraints.fill = GridBagConstraints.BOTH; 503 gridBagConstraints.weightx = 1.0; 504 gridBagConstraints.weighty = 1.0; 505 gridBagConstraints.insets = new Insets (0, 6, 0, 5); 506 add(keyFieldsPanel, gridBagConstraints); 507 508 512 tableColumns = new ArrayList (5); 513 tableColumns.add(new GenericTableModel.AttributeEntry(ConstraintField.NAME, 514 webappBundle.getString("LBL_ConstraintFieldName"), true)); tableColumns.add(new GenericTableModel.AttributeEntry(ConstraintField.SCOPE, 516 webappBundle.getString("LBL_ConstraintFieldScope"))); tableColumns.add(new GenericTableModel.AttributeEntry(ConstraintField.CACHEONMATCH, 518 webappBundle.getString("LBL_CacheOnMatch"))); tableColumns.add(new GenericTableModel.AttributeEntry(ConstraintField.CACHEONMATCHFAILURE, 520 webappBundle.getString("LBL_CacheOnMatchFailure"))); tableColumns.add(new ConstraintFieldValueEntry()); 522 523 constraintFieldsModel = new GenericTableModel(constraintFieldFactory, tableColumns); 525 constraintFieldsPanel = new GenericTablePanel(constraintFieldsModel, 526 webappBundle, "ConstraintField", ConstraintFieldEntryPanel.class, 528 HelpContext.HELP_CACHE_MAPPING_CONSTRAINT_POPUP); 529 constraintFieldsPanel.setHeadingMnemonic(webappBundle.getString("MNE_ConstraintField").charAt(0)); 531 gridBagConstraints = new GridBagConstraints (); 532 gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; 533 gridBagConstraints.fill = GridBagConstraints.BOTH; 534 gridBagConstraints.weightx = 1.0; 535 gridBagConstraints.weighty = 1.0; 536 gridBagConstraints.insets = new Insets (0, 6, 0, 5); 537 add(constraintFieldsPanel, gridBagConstraints); 538 } 539 540 543 public void initFields(ASDDVersion asVersion) { 544 try { 545 initializingFields = true; 546 jTxtTimeoutName.setText(newCacheMapping.getTimeoutName()); 547 enableTimeout(Utils.notEmpty(newCacheMapping.getTimeoutName())); 548 549 jTxtRefreshFieldName.setText(newCacheMapping.getRefreshFieldName()); 550 enableRefreshField(Utils.notEmpty(newCacheMapping.getRefreshFieldName())); 551 552 jChkHttpGet.setSelected(httpMethods.contains("GET")); jChkHttpPost.setSelected(httpMethods.contains("POST")); 555 keyFieldsPanel.setModelBaseBean(newCacheMapping, asVersion); 556 constraintFieldsPanel.setModel(constraints, asVersion); 557 558 if(ASDDVersion.SUN_APPSERVER_8_1.compareTo(asVersion) <= 0) { 559 showAS81Fields(); 560 dispatcherPanel.setModelBaseBean(newCacheMapping, asVersion); 561 } else { 562 hideAS81Fields(); 563 } 564 } finally { 565 initializingFields = false; 566 } 567 } 568 569 private void showAS81Fields() { 572 if(!as81FeaturesVisible) { 573 GridBagConstraints gridBagConstraints = new GridBagConstraints (); 574 gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; 575 gridBagConstraints.fill = GridBagConstraints.BOTH; 576 gridBagConstraints.weightx = 1.0; 577 gridBagConstraints.weighty = 1.0; 578 gridBagConstraints.insets = new Insets (0, 6, 5, 5); 579 580 int keyFieldsIndex = BaseCustomizer.getComponentIndex(this, keyFieldsPanel); 581 if(keyFieldsIndex != -1) { 582 add(dispatcherPanel, gridBagConstraints, keyFieldsIndex); 583 } else { 584 add(dispatcherPanel, gridBagConstraints); 585 } 586 as81FeaturesVisible = true; 587 } 588 } 589 590 private void hideAS81Fields() { 591 if(as81FeaturesVisible) { 592 remove(dispatcherPanel); 593 as81FeaturesVisible = false; 594 } 595 } 596 597 public void addListeners() { 598 dispatcherModel.addTableModelListener(this); 599 keyFieldsModel.addTableModelListener(this); 600 constraintFieldsModel.addTableModelListener(this); 601 } 602 603 private void enableTimeout(boolean enabled) { 604 timeoutEnabled = enabled; 605 jCbxTimeoutScope.setEnabled(enabled); 606 jTxtTimeoutValue.setEnabled(enabled); 607 jTxtTimeoutValue.setEditable(enabled); 608 609 if(!enabled) { 610 newCacheMapping.setTimeout(null); 611 newCacheMapping.setTimeoutScope(null); 612 } else { 613 String scope = newCacheMapping.getTimeoutScope(); 614 if(!Utils.notEmpty(scope)) { 615 newCacheMapping.setTimeoutScope("request.attribute"); } 617 } 618 619 jTxtTimeoutValue.setText(newCacheMapping.getTimeout()); 620 jCbxTimeoutScope.setSelectedItem( 621 getScopeMapping(newCacheMapping.getTimeoutScope(), scopeTypes)); 622 } 623 624 private void enableRefreshField(boolean enabled) { 625 refreshFieldEnabled = enabled; 626 jCbxRefreshScope.setEnabled(enabled); 627 if(!enabled) { 628 newCacheMapping.setRefreshField(false); 629 newCacheMapping.setRefreshFieldScope(null); 630 } else { 631 newCacheMapping.setRefreshField(true); 632 String scope = newCacheMapping.getRefreshFieldScope(); 633 if(!Utils.notEmpty(scope)) { 634 newCacheMapping.setRefreshFieldScope("request.parameter"); } 636 } 637 638 jCbxRefreshScope.setSelectedItem( 639 getScopeMapping(newCacheMapping.getRefreshFieldScope(), keyScopeTypes)); 640 } 641 642 private void handleHttpMethodSelection(ItemEvent evt, String method) { 643 if(!initializingFields) { 644 if(evt.getStateChange() == ItemEvent.SELECTED) { 645 if(!httpMethods.contains(method)) { 646 httpMethods.add(method); 647 } 648 } else if(evt.getStateChange() == ItemEvent.DESELECTED) { 649 if(httpMethods.contains(method)) { 650 httpMethods.remove(method); 651 } 652 } 653 654 setDataChanged(true); 655 } 656 } 657 658 private TextMapping getScopeMapping(String xmlKey, final TextMapping [] scopeMap) { 659 TextMapping result = null; 660 if(xmlKey == null) { 661 xmlKey = ""; } 663 for(int i = 0; i < scopeMap.length; i++) { 664 if(scopeMap[i].getXMLString().compareTo(xmlKey) == 0) { 665 result = scopeMap[i]; 666 break; 667 } 668 } 669 return result; 670 } 671 672 public boolean isDataChanged() { 673 return dataChanged; 674 } 675 676 public void setDataChanged(boolean changed) { 677 dataChanged = changed; 678 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 679 } 680 681 private String normalizeBlank(String value) { 682 return (value != "") ? value : null; 683 } 684 685 688 public void tableChanged(TableModelEvent e) { 689 Object eventSource = e.getSource(); 690 if(eventSource == dispatcherModel) { 691 } else if(eventSource == keyFieldsModel) { 693 } else if(eventSource == constraintFieldsModel) { 695 constraints = constraintFieldsModel.getData(); 696 } 697 698 setDataChanged(true); 699 } 700 701 private Collection getErrors() { 702 ArrayList errorList = new ArrayList (); 703 704 String timeoutName = newCacheMapping.getTimeoutName(); 705 if(Utils.notEmpty(timeoutName)) { 706 if(!Utils.isJavaIdentifier(timeoutName)) { 707 Object [] args = new Object [2]; 708 args[0] = webappBundle.getString("LBL_TimeoutName"); args[1] = timeoutName; 710 errorList.add(MessageFormat.format( 711 commonBundle.getString("ERR_NotValidIdentifierForField"), args)); } 713 714 String timeout = newCacheMapping.getTimeout(); 715 if(Utils.notEmpty(timeout)) { 716 try { 717 int value = Integer.parseInt(timeout); 718 if(value < 0) { 719 Object [] args = new Object [3]; 720 args[0] = webappBundle.getString("LBL_Timeout"); args[1] = timeout; 722 args[2] = "0"; errorList.add(MessageFormat.format( 724 commonBundle.getString("ERR_NumberTooLowForField"), args)); } 726 } catch(NumberFormatException ex) { 727 Object [] args = new Object [2]; 728 args[0] = webappBundle.getString("LBL_Timeout"); args[1] = timeout; 730 errorList.add(MessageFormat.format( 731 commonBundle.getString("ERR_NumberInvalidForField"), args)); } 733 } 734 } 735 736 String refreshFieldName = newCacheMapping.getRefreshFieldName(); 737 if(Utils.notEmpty(refreshFieldName)) { 738 if(!Utils.isJavaIdentifier(refreshFieldName)) { 739 Object [] args = new Object [2]; 740 args[0] = webappBundle.getString("LBL_RefreshFieldName"); args[1] = refreshFieldName; 742 errorList.add(MessageFormat.format( 743 commonBundle.getString("ERR_NotValidIdentifierForField"), args)); } 745 } 746 747 return errorList; 748 } 749 750 public static boolean invokeAsPopup(JPanel parent, ASDDVersion asVersion, CacheMapping mapping) { 751 CachePolicyPanel policyPanel = new CachePolicyPanel(asVersion, mapping); 752 policyPanel.displayDialog(parent); 753 return policyPanel.isDataChanged(); 754 } 755 756 private void displayDialog(JPanel parent) { 757 BetterInputDialog dialog = new BetterInputDialog(parent, 758 webappBundle.getString("CACHE_POLICY_TITLE"), this); 760 do { 761 if(dialog.display() == dialog.OK_OPTION) { 762 if(!dialog.hasErrors()) { 763 if(Utils.notEmpty(newCacheMapping.getTimeoutName())) { 765 theCacheMapping.setTimeout(newCacheMapping.getTimeout()); 766 theCacheMapping.setTimeoutName(newCacheMapping.getTimeoutName()); 767 theCacheMapping.setTimeoutScope(newCacheMapping.getTimeoutScope()); 768 } else { 769 theCacheMapping.setTimeout(null); 770 } 771 772 if(Utils.notEmpty(newCacheMapping.getRefreshFieldName())) { 774 theCacheMapping.setRefreshField(true); 775 theCacheMapping.setRefreshFieldName(newCacheMapping.getRefreshFieldName()); 776 theCacheMapping.setRefreshFieldScope(newCacheMapping.getRefreshFieldScope()); 777 } else { 778 theCacheMapping.setRefreshField(false); 779 } 780 781 theCacheMapping.setHttpMethod((String []) httpMethods.toArray(new String [0])); 783 784 try { 786 theCacheMapping.setDispatcher(newCacheMapping.getDispatcher()); 787 } catch(VersionNotSupportedException ex) { 793 } 795 796 int numFields = newCacheMapping.sizeKeyField(); 798 theCacheMapping.setKeyField(new boolean [numFields]); 799 for(int i = 0; i < numFields; i++) { 800 theCacheMapping.setKeyField(i, true); 801 theCacheMapping.setKeyFieldName(i, newCacheMapping.getKeyFieldName(i)); 802 theCacheMapping.setKeyFieldScope(i, newCacheMapping.getKeyFieldScope(i)); 803 } 804 805 theCacheMapping.setConstraintField((ConstraintField []) Utils.listToArray(constraints, ConstraintField.class)); 807 } 808 } else { 809 setDataChanged(false); 811 break; 812 } 813 } while(dialog.hasErrors()); 814 } 815 816 820 private static class BetterInputDialog extends InputDialog { 821 private final CachePolicyPanel dialogPanel; 822 823 public BetterInputDialog(JPanel parent, String title, CachePolicyPanel childPanel) { 824 super(parent, title); 825 826 dialogPanel = childPanel; 827 getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_CachePolicy")); 830 getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_CachePolicy")); 831 832 dialogPanel.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_CachePolicy")); 833 dialogPanel.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_CachePolicy")); 834 835 getContentPane().add(childPanel, BorderLayout.CENTER); 836 addListeners(); 837 pack(); 838 setLocationInside(parent); 839 handleErrorDisplay(); 840 } 841 842 private void addListeners() { 843 dialogPanel.addPropertyChangeListener(Constants.USER_DATA_CHANGED, new PropertyChangeListener () { 844 public void propertyChange(PropertyChangeEvent evt) { 845 handleErrorDisplay(); 846 } 847 }); 848 } 849 850 private void handleErrorDisplay() { 851 ArrayList errors = new ArrayList (); 852 errors.addAll(dialogPanel.getErrors()); 853 setErrors(errors); 854 } 855 856 protected String getHelpId() { 857 return HelpContext.HELP_CACHE_MAPPING_POLICY_POPUP; 858 } 859 } 860 861 static GenericTableModel.ParentPropertyFactory constraintFieldFactory = 864 new GenericTableModel.ParentPropertyFactory() { 865 public CommonDDBean newParentProperty(ASDDVersion asVersion) { 866 return StorageBeanFactory.getStorageBeanFactory(asVersion).createConstraintField(); 867 } 868 };} 869 | Popular Tags |