1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp; 26 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.List ; 30 import java.util.ResourceBundle ; 31 import java.text.MessageFormat ; 32 33 import java.awt.Dimension ; 34 import java.awt.GridBagConstraints ; 35 import java.awt.Insets ; 36 37 import javax.swing.JPanel ; 38 import javax.swing.DefaultComboBoxModel ; 39 import javax.swing.event.TableModelEvent ; 40 import javax.swing.event.TableModelListener ; 41 42 import org.netbeans.modules.j2ee.sun.dd.api.web.ConstraintField; 43 44 import org.netbeans.modules.j2ee.sun.share.Constants; 45 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion; 46 import org.netbeans.modules.j2ee.sun.share.configbean.StorageBeanFactory; 47 import org.netbeans.modules.j2ee.sun.share.configbean.Utils; 48 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableModel; 49 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTablePanel; 50 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableDialogPanelAccessor; 51 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.HelpContext; 52 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.BeanListMapping; 53 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.TextMapping; 54 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.ValidationSupport; 55 56 60 public class ConstraintFieldEntryPanel extends JPanel implements GenericTableDialogPanelAccessor, TableModelListener { 61 62 private static final ResourceBundle webappBundle = ResourceBundle.getBundle( 63 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp.Bundle"); 65 private static final ResourceBundle commonBundle = ResourceBundle.getBundle( 66 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); 68 private static final TextMapping [] scopeTypes = ScopeMapping.getScopeMappings(); 69 70 private static final int NAME_FIELD = 0; 72 private static final int SCOPE_FIELD = 1; 73 private static final int CACHEONMATCH_FIELD = 2; 74 private static final int CACHEONMATCHFAILURE_FIELD = 3; 75 private static final int VALUES_FIELD = 4; 76 private static final int NUM_FIELDS = 5; 78 private ASDDVersion appServerVersion; 80 81 private String constraintFieldName; 83 private String constraintFieldScope; 84 private boolean cacheOnMatch; 85 private boolean cacheOnMatchFailure; 86 private List constraintValues; 87 private ConstraintField constraintValuesBean; 88 89 private GenericTableModel constraintFieldValueModel; 91 private GenericTablePanel constraintFieldValuePanel; 92 93 private DefaultComboBoxModel constraintFieldScopeModel; 94 95 private Dimension basicPreferredSize; 96 97 98 public ConstraintFieldEntryPanel() { 99 constraintFieldName = ""; constraintFieldScope = ""; cacheOnMatch = true; 102 cacheOnMatchFailure = false; 103 105 initComponents(); 106 initUserComponents(); 107 } 108 109 114 private void initComponents() { 116 java.awt.GridBagConstraints gridBagConstraints; 117 118 jLblNameReqFlag = new javax.swing.JLabel (); 119 jLblName = new javax.swing.JLabel (); 120 jTxtName = new javax.swing.JTextField (); 121 jLblFiller1 = new javax.swing.JLabel (); 122 jLblScope = new javax.swing.JLabel (); 123 jCbxScope = new javax.swing.JComboBox (); 124 jLblFiller2 = new javax.swing.JLabel (); 125 jLblCacheOnMatch = new javax.swing.JLabel (); 126 jChkCacheOnMatch = new javax.swing.JCheckBox (); 127 jLblFiller3 = new javax.swing.JLabel (); 128 jLblCacheOnMatchFailure = new javax.swing.JLabel (); 129 jChkCacheOnMatchFailure = new javax.swing.JCheckBox (); 130 131 setLayout(new java.awt.GridBagLayout ()); 132 133 jLblNameReqFlag.setLabelFor(jTxtName); 134 jLblNameReqFlag.setText(commonBundle.getString("LBL_RequiredMark")); 135 gridBagConstraints = new java.awt.GridBagConstraints (); 136 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 137 add(jLblNameReqFlag, gridBagConstraints); 138 jLblNameReqFlag.getAccessibleContext().setAccessibleName(commonBundle.getString("ACSN_RequiredMark")); 139 jLblNameReqFlag.getAccessibleContext().setAccessibleDescription(commonBundle.getString("ACSD_RequiredMark")); 140 141 jLblName.setDisplayedMnemonic(webappBundle.getString("MNE_ConstraintFieldName").charAt(0)); 142 jLblName.setLabelFor(jTxtName); 143 jLblName.setText(webappBundle.getString("LBL_ConstraintFieldName_1")); 144 gridBagConstraints = new java.awt.GridBagConstraints (); 145 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 146 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 147 add(jLblName, gridBagConstraints); 148 149 jTxtName.addKeyListener(new java.awt.event.KeyAdapter () { 150 public void keyReleased(java.awt.event.KeyEvent evt) { 151 jTxtNameKeyReleased(evt); 152 } 153 }); 154 155 gridBagConstraints = new java.awt.GridBagConstraints (); 156 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 157 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 158 gridBagConstraints.weightx = 1.0; 159 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 5); 160 add(jTxtName, gridBagConstraints); 161 jTxtName.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_ConstraintFieldName")); 162 jTxtName.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_ConstraintFieldName")); 163 164 gridBagConstraints = new java.awt.GridBagConstraints (); 165 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 166 add(jLblFiller1, gridBagConstraints); 167 168 jLblScope.setDisplayedMnemonic(webappBundle.getString("MNE_ConstraintFieldScope").charAt(0)); 169 jLblScope.setLabelFor(jCbxScope); 170 jLblScope.setText(webappBundle.getString("LBL_ConstraintFieldScope_1")); 171 gridBagConstraints = new java.awt.GridBagConstraints (); 172 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 173 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 174 add(jLblScope, gridBagConstraints); 175 176 jCbxScope.addActionListener(new java.awt.event.ActionListener () { 177 public void actionPerformed(java.awt.event.ActionEvent evt) { 178 jCbxScopeActionPerformed(evt); 179 } 180 }); 181 182 gridBagConstraints = new java.awt.GridBagConstraints (); 183 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 184 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 185 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 5); 186 add(jCbxScope, gridBagConstraints); 187 jCbxScope.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_ConstraintFieldScope")); 188 jCbxScope.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_ConstraintFieldScope")); 189 190 jLblFiller2.setLabelFor(jChkCacheOnMatch); 191 gridBagConstraints = new java.awt.GridBagConstraints (); 192 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 193 add(jLblFiller2, gridBagConstraints); 194 195 jLblCacheOnMatch.setDisplayedMnemonic(webappBundle.getString("MNE_CacheOnMatch").charAt(0)); 196 jLblCacheOnMatch.setLabelFor(jChkCacheOnMatch); 197 jLblCacheOnMatch.setText(webappBundle.getString("LBL_CacheOnMatch_1")); 198 gridBagConstraints = new java.awt.GridBagConstraints (); 199 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 200 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 201 add(jLblCacheOnMatch, gridBagConstraints); 202 203 jChkCacheOnMatch.addItemListener(new java.awt.event.ItemListener () { 204 public void itemStateChanged(java.awt.event.ItemEvent evt) { 205 jChkCacheOnMatchItemStateChanged(evt); 206 } 207 }); 208 209 gridBagConstraints = new java.awt.GridBagConstraints (); 210 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 211 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 212 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 5); 213 add(jChkCacheOnMatch, gridBagConstraints); 214 jChkCacheOnMatch.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_CacheOnMatch")); 215 jChkCacheOnMatch.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_CacheOnMatch")); 216 217 jLblFiller3.setLabelFor(jChkCacheOnMatchFailure); 218 gridBagConstraints = new java.awt.GridBagConstraints (); 219 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 220 add(jLblFiller3, gridBagConstraints); 221 222 jLblCacheOnMatchFailure.setDisplayedMnemonic(webappBundle.getString("MNE_CacheOnMatchFailure").charAt(0)); 223 jLblCacheOnMatchFailure.setLabelFor(jChkCacheOnMatchFailure); 224 jLblCacheOnMatchFailure.setText(webappBundle.getString("LBL_CacheOnMatchFailure_1")); 225 gridBagConstraints = new java.awt.GridBagConstraints (); 226 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 227 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 228 add(jLblCacheOnMatchFailure, gridBagConstraints); 229 230 jChkCacheOnMatchFailure.addItemListener(new java.awt.event.ItemListener () { 231 public void itemStateChanged(java.awt.event.ItemEvent evt) { 232 jChkCacheOnMatchFailureItemStateChanged(evt); 233 } 234 }); 235 236 gridBagConstraints = new java.awt.GridBagConstraints (); 237 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 238 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 239 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 5); 240 add(jChkCacheOnMatchFailure, gridBagConstraints); 241 jChkCacheOnMatchFailure.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_CacheOnMatchFailure")); 242 jChkCacheOnMatchFailure.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_CacheOnMatchFailure")); 243 244 } 246 private void jChkCacheOnMatchFailureItemStateChanged(java.awt.event.ItemEvent evt) { cacheOnMatchFailure = Utils.interpretCheckboxState(evt); 248 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 249 } 251 private void jChkCacheOnMatchItemStateChanged(java.awt.event.ItemEvent evt) { cacheOnMatch = Utils.interpretCheckboxState(evt); 253 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 254 } 256 private void jCbxScopeActionPerformed(java.awt.event.ActionEvent evt) { TextMapping scope = (TextMapping) constraintFieldScopeModel.getSelectedItem(); 258 constraintFieldScope = scope.getXMLString(); 259 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 260 } 262 private void jTxtNameKeyReleased(java.awt.event.KeyEvent evt) { constraintFieldName = jTxtName.getText(); 264 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 265 } 267 268 private javax.swing.JComboBox jCbxScope; 270 private javax.swing.JCheckBox jChkCacheOnMatch; 271 private javax.swing.JCheckBox jChkCacheOnMatchFailure; 272 private javax.swing.JLabel jLblCacheOnMatch; 273 private javax.swing.JLabel jLblCacheOnMatchFailure; 274 private javax.swing.JLabel jLblFiller1; 275 private javax.swing.JLabel jLblFiller2; 276 private javax.swing.JLabel jLblFiller3; 277 private javax.swing.JLabel jLblName; 278 private javax.swing.JLabel jLblNameReqFlag; 279 private javax.swing.JLabel jLblScope; 280 private javax.swing.JTextField jTxtName; 281 283 private void initUserComponents() { 284 287 basicPreferredSize = getPreferredSize(); 288 289 293 ArrayList tableColumns = new ArrayList (4); 294 tableColumns.add(new GenericTableModel.AttributeEntry(ConstraintField.CONSTRAINT_FIELD_VALUE, "MatchExpr", webappBundle.getString("LBL_MatchExpression"), true)); tableColumns.add(new GenericTableModel.AttributeEntry(ConstraintField.CONSTRAINT_FIELD_VALUE, "CacheOnMatch", webappBundle.getString("LBL_CacheOnMatch"), false)); tableColumns.add(new GenericTableModel.AttributeEntry(ConstraintField.CONSTRAINT_FIELD_VALUE, "CacheOnMatchFailure", webappBundle.getString("LBL_CacheOnMatchFailure"), false)); tableColumns.add(new GenericTableModel.ValueEntry(ConstraintField.CONSTRAINT_FIELD_VALUE, ConstraintField.CONSTRAINT_FIELD_VALUE, 301 webappBundle.getString("LBL_MatchFieldValue"), true)); 303 constraintFieldValueModel = new ConstraintFieldValueTableModel(tableColumns); 305 constraintFieldValueModel.addTableModelListener(this); 306 constraintFieldValuePanel = new GenericTablePanel(constraintFieldValueModel, 307 webappBundle, "ConstraintFieldValue", ConstraintFieldValueEntryPanel.class, HelpContext.HELP_CACHE_MAPPING_CONSTRAINT_VALUE_POPUP); 309 constraintFieldValuePanel.setHeadingMnemonic(webappBundle.getString("MNE_ConstraintFieldValue").charAt(0)); 311 GridBagConstraints gridBagConstraints = new GridBagConstraints (); 312 gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; 313 gridBagConstraints.fill = GridBagConstraints.BOTH; 314 gridBagConstraints.weightx = 1.0; 315 gridBagConstraints.weighty = 1.0; 316 gridBagConstraints.insets = new Insets (0, 6, 0, 5); 317 add(constraintFieldValuePanel, gridBagConstraints); 318 319 constraintFieldScopeModel = new DefaultComboBoxModel (); 321 for(int i = 0; i < scopeTypes.length; i++) { 322 constraintFieldScopeModel.addElement(scopeTypes[i]); 323 } 324 jCbxScope.setModel(constraintFieldScopeModel); 325 } 326 327 private TextMapping getScopeMapping(String xmlKey) { 328 TextMapping result = null; 329 if(xmlKey == null) { 330 xmlKey = ""; } 332 for(int i = 0; i < scopeTypes.length; i++) { 333 if(scopeTypes[i].getXMLString().compareTo(xmlKey) == 0) { 334 result = scopeTypes[i]; 335 break; 336 } 337 } 338 return result; 339 } 340 341 344 public void tableChanged(TableModelEvent e) { 345 ConstraintField bean = (ConstraintField) constraintFieldValueModel.getDataBaseBean(); 349 if(constraintValuesBean == bean) { 350 } 351 } 352 353 356 public void init(ASDDVersion asVersion, int preferredWidth, List entries, Object data) { 357 359 appServerVersion = asVersion; 360 361 364 setPreferredSize(new Dimension (preferredWidth, basicPreferredSize.height + 148)); 365 366 369 constraintValuesBean = StorageBeanFactory.getStorageBeanFactory(appServerVersion).createConstraintField(); 370 constraintFieldValuePanel.setModelBaseBean(constraintValuesBean, asVersion); 371 } 372 373 public Object [] getValues() { 374 Object [] result = new Object [NUM_FIELDS]; 375 376 result[NAME_FIELD] = constraintFieldName; 377 result[SCOPE_FIELD] = constraintFieldScope; 378 result[CACHEONMATCH_FIELD] = Boolean.toString(cacheOnMatch); 379 result[CACHEONMATCHFAILURE_FIELD] = Boolean.toString(cacheOnMatchFailure); 380 result[VALUES_FIELD] = new BeanListMapping(constraintValuesBean, ConstraintField.CONSTRAINT_FIELD_VALUE); 381 382 return result; 383 } 384 385 public void setValues(Object [] values) { 386 if(values != null && values.length == NUM_FIELDS) { 387 constraintFieldName = (String ) values[NAME_FIELD]; 388 constraintFieldScope = (String ) values[SCOPE_FIELD]; 389 cacheOnMatch = Utils.booleanValueOf((String ) values[CACHEONMATCH_FIELD]); 390 cacheOnMatchFailure = Utils.booleanValueOf((String ) values[CACHEONMATCHFAILURE_FIELD]); 391 constraintValuesBean = (ConstraintField) ((BeanListMapping) values[VALUES_FIELD]).getBean(); 392 } else { 393 if(values != null) { 394 assert (values.length == NUM_FIELDS); } 396 397 constraintFieldName = ""; constraintFieldScope = ""; cacheOnMatch = true; 401 cacheOnMatchFailure = false; 402 constraintValuesBean = StorageBeanFactory.getStorageBeanFactory(appServerVersion).createConstraintField(); 403 } 404 405 setComponentValues(); 406 } 407 408 private void setComponentValues() { 409 jTxtName.setText(constraintFieldName); 410 constraintFieldScopeModel.setSelectedItem(getScopeMapping(constraintFieldScope)); 411 jChkCacheOnMatch.setSelected(cacheOnMatch); 412 jChkCacheOnMatchFailure.setSelected(cacheOnMatchFailure); 413 constraintFieldValuePanel.setModelBaseBean(constraintValuesBean, appServerVersion); 414 } 415 416 public Collection getErrors(ValidationSupport validationSupport) { 417 ArrayList errorList = new ArrayList (); 418 419 if(!Utils.notEmpty(constraintFieldName)) { 420 Object [] args = new Object [1]; 421 args[0] = webappBundle.getString("LBL_ConstraintFieldName"); errorList.add(MessageFormat.format(commonBundle.getString("ERR_SpecifiedFieldIsEmpty"), args)); } else if(!Utils.isJavaIdentifier(constraintFieldName)) { 424 Object [] args = new Object [1]; 425 args[0] = constraintFieldName; 426 errorList.add(MessageFormat.format(commonBundle.getString("ERR_NotValidIdentifier"), args)); } 428 429 return errorList; 430 } 431 432 public boolean requiredFieldsFilled() { 433 return (constraintFieldName != null && constraintFieldName.length() > 0); 434 } 435 436 private static class ConstraintFieldValueTableModel extends GenericTableModel { 437 public ConstraintFieldValueTableModel(List tableColumns) { 438 super(ConstraintField.CONSTRAINT_FIELD_VALUE, tableColumns); 439 } 440 441 public boolean alreadyExists(Object [] values) { 442 boolean exists = false; 443 444 Object bean = getDataBaseBean(); 445 if(bean instanceof ConstraintField) { 446 ConstraintField parentField = (ConstraintField) bean; 447 for(int i = 0, limit = parentField.sizeConstraintFieldValue(); i < limit; i++) { 448 if(match((String ) values[0], parentField.getConstraintFieldValueMatchExpr(i)) && 449 match((String ) values[3], parentField.getConstraintFieldValue(i))) { 450 exists = true; 451 break; 452 } 453 } 454 } 455 456 return exists; 457 } 458 459 private final boolean match(String a, String b) { 460 boolean result = false; 461 462 if(a == b) { 463 result = true; 464 } else if(a != null && b != null && a.equals(b)) { 465 result = true; 466 } 467 468 return result; 469 } 470 471 public boolean alreadyExists(String keyPropertyValue) { 472 return false; 475 } 476 } 477 } 478 | Popular Tags |