1 19 package org.netbeans.modules.xml.tax.beans.customizer; 20 21 import java.beans.PropertyChangeEvent ; 22 23 import org.netbeans.tax.TreeException; 24 import org.netbeans.tax.TreeAttlistDeclAttributeDef; 25 26 import org.netbeans.modules.xml.tax.util.TAXUtil; 27 28 33 public class TreeAttlistDeclAttributeDefCustomizer extends AbstractTreeCustomizer { 34 35 36 private static final long serialVersionUID =2877621716093964464L; 37 38 39 43 44 public TreeAttlistDeclAttributeDefCustomizer () { 45 super (); 46 47 initComponents (); 48 49 elementNameLabel.setDisplayedMnemonic (Util.THIS.getChar ("TreeAttributeDeclCustomizer.elemNameLabel.mne")); nameLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlName")); typeLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_dtdAttDefType")); enumeratedLabel.setDisplayedMnemonic (Util.THIS.getChar ("DTDAttDefNode.enumeratedLabel.mne")); defaultTypeLabel.setDisplayedMnemonic (Util.THIS.getChar ("DTDAttDefNode.defaultTypeLabel.mne")); defaultValueLabel.setDisplayedMnemonic (Util.THIS.getChar ("DTDAttDefNode.defaultValueLabel.mne")); 56 initAccessibility (); 57 } 58 59 63 65 protected final TreeAttlistDeclAttributeDef getAttributeDef () { 66 return (TreeAttlistDeclAttributeDef)getTreeObject (); 67 } 68 69 71 protected final void safePropertyChange (PropertyChangeEvent pche) { 72 super.safePropertyChange (pche); 73 74 if (pche.getPropertyName ().equals (TreeAttlistDeclAttributeDef.PROP_NAME)) { 75 updateNameComponent (); 76 } else if (pche.getPropertyName ().equals (TreeAttlistDeclAttributeDef.PROP_TYPE)) { 77 updateTypeComponent (); 78 } else if (pche.getPropertyName ().equals (TreeAttlistDeclAttributeDef.PROP_ENUMERATED_TYPE)) { 79 updateEnumeratedTypeComponent (); 80 } else if (pche.getPropertyName ().equals (TreeAttlistDeclAttributeDef.PROP_DEFAULT_TYPE)) { 81 updateDefaultTypeComponent (); 82 } else if (pche.getPropertyName ().equals (TreeAttlistDeclAttributeDef.PROP_DEFAULT_VALUE)) { 83 updateDefaultValueComponent (); 84 } 85 } 86 87 88 90 protected final void updateElementNameComponent () { 91 elementNameField.setText (getAttributeDef ().getElementName ()); 92 } 93 94 96 protected final void updateNameComponent () { 97 nameField.setText (getAttributeDef ().getName ()); 98 } 99 100 102 protected final void updateAttributeDefName () { 103 try { 104 getAttributeDef ().setName (nameField.getText ()); 105 } catch (TreeException exc) { 106 updateNameComponent (); 107 TAXUtil.notifyTreeException (exc); 108 } 109 } 110 111 113 protected final void updateTypeComponent () { 114 typeField.setText (getAttributeDef ().getTypeName ()); 115 } 116 117 119 protected final void updateAttributeDefType () { 120 try { 121 getAttributeDef ().setType 122 (TreeAttlistDeclAttributeDef.findType (text2null (typeField.getText ())), 123 getAttributeDef ().getEnumeratedType ()); 124 } catch (TreeException exc) { 125 updateTypeComponent (); 126 TAXUtil.notifyTreeException (exc); 127 } 128 } 129 130 132 protected final void updateEnumeratedTypeComponent () { 133 enumeratedField.setText (null2text (getAttributeDef ().getEnumeratedTypeString ())); 134 } 135 136 138 protected final void updateAttributeDefEnumeratedType () { 139 try { 140 getAttributeDef ().setType 141 (getAttributeDef ().getType (), 142 TreeAttlistDeclAttributeDef.createEnumeratedType (text2null (enumeratedField.getText ()))); 143 } catch (TreeException exc) { 144 updateEnumeratedTypeComponent (); 145 TAXUtil.notifyTreeException (exc); 146 } 147 } 148 149 151 protected final void updateDefaultTypeComponent () { 152 defaultTypeField.setText (null2text (getAttributeDef ().getDefaultTypeName ())); 153 } 154 155 157 protected final void updateAttributeDefDefaultType () { 158 try { 159 getAttributeDef ().setDefaultType 160 (TreeAttlistDeclAttributeDef.findDefaultType (text2null (defaultTypeField.getText ())), 161 getAttributeDef ().getDefaultValue ()); 162 } catch (TreeException exc) { 163 updateDefaultTypeComponent (); 164 TAXUtil.notifyTreeException (exc); 165 } 166 } 167 168 170 protected final void updateDefaultValueComponent () { 171 defaultValueField.setText (null2text (getAttributeDef ().getDefaultValue ())); 172 } 173 174 176 protected final void updateAttributeDefDefaultValue () { 177 try { 178 short defaultType = getAttributeDef ().getDefaultType (); 179 String defaultValue = text2null (defaultValueField.getText ()); 180 if ( defaultValue == null ) { 181 if ( ( defaultType == TreeAttlistDeclAttributeDef.DEFAULT_TYPE_NULL ) || 182 ( defaultType == TreeAttlistDeclAttributeDef.DEFAULT_TYPE_FIXED ) ) { 183 defaultValue = ""; 184 } 185 } 186 getAttributeDef ().setDefaultType (defaultType, defaultValue); 187 } catch (TreeException exc) { 188 updateDefaultValueComponent (); 189 TAXUtil.notifyTreeException (exc); 190 } 191 } 192 193 194 196 protected final void initComponentValues () { 197 updateElementNameComponent (); 198 updateNameComponent (); 199 updateTypeComponent (); 200 updateEnumeratedTypeComponent (); 201 updateDefaultTypeComponent (); 202 updateDefaultValueComponent (); 203 } 204 205 206 208 protected final void updateReadOnlyStatus (boolean editable) { 209 nameField.setEditable (editable); 210 typeField.setEditable (editable); 211 enumeratedField.setEditable (editable); 212 defaultTypeField.setEditable (editable); 213 defaultValueField.setEditable (editable); 214 } 215 216 217 222 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 224 225 elementNameLabel = new javax.swing.JLabel (); 226 elementNameField = new javax.swing.JTextField (); 227 nameLabel = new javax.swing.JLabel (); 228 nameField = new javax.swing.JTextField (); 229 typeLabel = new javax.swing.JLabel (); 230 typeField = new javax.swing.JTextField (); 231 enumeratedLabel = new javax.swing.JLabel (); 232 enumeratedField = new javax.swing.JTextField (); 233 defaultTypeLabel = new javax.swing.JLabel (); 234 defaultTypeField = new javax.swing.JTextField (); 235 defaultValueLabel = new javax.swing.JLabel (); 236 defaultValueField = new javax.swing.JTextField (); 237 fillPanel = new javax.swing.JPanel (); 238 239 setLayout(new java.awt.GridBagLayout ()); 240 241 elementNameLabel.setText(Util.THIS.getString ("TreeAttributeDeclCustomizer.elemNameLabel.text")); 242 elementNameLabel.setLabelFor(elementNameField); 243 gridBagConstraints = new java.awt.GridBagConstraints (); 244 gridBagConstraints.gridx = 0; 245 gridBagConstraints.gridy = 0; 246 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 247 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 248 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 249 add(elementNameLabel, gridBagConstraints); 250 251 elementNameField.setEditable(false); 252 elementNameField.setColumns(20); 253 elementNameField.addFocusListener(new java.awt.event.FocusAdapter () { 254 public void focusGained(java.awt.event.FocusEvent evt) { 255 elementNameFieldFocusGained(evt); 256 } 257 }); 258 259 gridBagConstraints = new java.awt.GridBagConstraints (); 260 gridBagConstraints.gridx = 1; 261 gridBagConstraints.gridy = 0; 262 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 263 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 264 gridBagConstraints.weightx = 1.0; 265 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 266 add(elementNameField, gridBagConstraints); 267 268 nameLabel.setText(Util.THIS.getString ("PROP_xmlName")); 269 nameLabel.setLabelFor(nameField); 270 gridBagConstraints = new java.awt.GridBagConstraints (); 271 gridBagConstraints.gridx = 0; 272 gridBagConstraints.gridy = 1; 273 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 274 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 275 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 276 add(nameLabel, gridBagConstraints); 277 278 nameField.setColumns(20); 279 nameField.addActionListener(new java.awt.event.ActionListener () { 280 public void actionPerformed(java.awt.event.ActionEvent evt) { 281 nameFieldActionPerformed(evt); 282 } 283 }); 284 285 nameField.addFocusListener(new java.awt.event.FocusAdapter () { 286 public void focusGained(java.awt.event.FocusEvent evt) { 287 nameFieldFocusGained(evt); 288 } 289 public void focusLost(java.awt.event.FocusEvent evt) { 290 nameFieldFocusLost(evt); 291 } 292 }); 293 294 gridBagConstraints = new java.awt.GridBagConstraints (); 295 gridBagConstraints.gridx = 1; 296 gridBagConstraints.gridy = 1; 297 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 298 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 299 gridBagConstraints.weightx = 1.0; 300 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 301 add(nameField, gridBagConstraints); 302 303 typeLabel.setText(Util.THIS.getString ("PROP_dtdAttDefType")); 304 typeLabel.setLabelFor(typeField); 305 gridBagConstraints = new java.awt.GridBagConstraints (); 306 gridBagConstraints.gridx = 0; 307 gridBagConstraints.gridy = 2; 308 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 309 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 310 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 311 add(typeLabel, gridBagConstraints); 312 313 typeField.setColumns(20); 314 typeField.addActionListener(new java.awt.event.ActionListener () { 315 public void actionPerformed(java.awt.event.ActionEvent evt) { 316 typeFieldActionPerformed(evt); 317 } 318 }); 319 320 typeField.addFocusListener(new java.awt.event.FocusAdapter () { 321 public void focusGained(java.awt.event.FocusEvent evt) { 322 typeFieldFocusGained(evt); 323 } 324 public void focusLost(java.awt.event.FocusEvent evt) { 325 typeFieldFocusLost(evt); 326 } 327 }); 328 329 gridBagConstraints = new java.awt.GridBagConstraints (); 330 gridBagConstraints.gridx = 1; 331 gridBagConstraints.gridy = 2; 332 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 333 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 334 gridBagConstraints.weightx = 1.0; 335 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 336 add(typeField, gridBagConstraints); 337 338 enumeratedLabel.setText(Util.THIS.getString ("DTDAttDefNode.enumeratedLabel.text")); 339 enumeratedLabel.setLabelFor(enumeratedField); 340 gridBagConstraints = new java.awt.GridBagConstraints (); 341 gridBagConstraints.gridx = 0; 342 gridBagConstraints.gridy = 3; 343 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 344 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 345 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 346 add(enumeratedLabel, gridBagConstraints); 347 348 enumeratedField.setColumns(20); 349 enumeratedField.addActionListener(new java.awt.event.ActionListener () { 350 public void actionPerformed(java.awt.event.ActionEvent evt) { 351 enumeratedFieldActionPerformed(evt); 352 } 353 }); 354 355 enumeratedField.addFocusListener(new java.awt.event.FocusAdapter () { 356 public void focusGained(java.awt.event.FocusEvent evt) { 357 enumeratedFieldFocusGained(evt); 358 } 359 public void focusLost(java.awt.event.FocusEvent evt) { 360 enumeratedFieldFocusLost(evt); 361 } 362 }); 363 364 gridBagConstraints = new java.awt.GridBagConstraints (); 365 gridBagConstraints.gridx = 1; 366 gridBagConstraints.gridy = 3; 367 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 368 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 369 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 370 add(enumeratedField, gridBagConstraints); 371 372 defaultTypeLabel.setText(Util.THIS.getString ("DTDAttDefNode.defaultTypeLabel.text")); 373 defaultTypeLabel.setLabelFor(defaultTypeField); 374 gridBagConstraints = new java.awt.GridBagConstraints (); 375 gridBagConstraints.gridx = 0; 376 gridBagConstraints.gridy = 4; 377 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 378 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 379 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 380 add(defaultTypeLabel, gridBagConstraints); 381 382 defaultTypeField.setColumns(20); 383 defaultTypeField.addActionListener(new java.awt.event.ActionListener () { 384 public void actionPerformed(java.awt.event.ActionEvent evt) { 385 defaultTypeFieldActionPerformed(evt); 386 } 387 }); 388 389 defaultTypeField.addFocusListener(new java.awt.event.FocusAdapter () { 390 public void focusGained(java.awt.event.FocusEvent evt) { 391 defaultTypeFieldFocusGained(evt); 392 } 393 public void focusLost(java.awt.event.FocusEvent evt) { 394 defaultTypeFieldFocusLost(evt); 395 } 396 }); 397 398 gridBagConstraints = new java.awt.GridBagConstraints (); 399 gridBagConstraints.gridx = 1; 400 gridBagConstraints.gridy = 4; 401 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 402 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 403 gridBagConstraints.weightx = 1.0; 404 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 405 add(defaultTypeField, gridBagConstraints); 406 407 defaultValueLabel.setText(Util.THIS.getString ("DTDAttDefNode.defaultValueLabel.text")); 408 defaultValueLabel.setLabelFor(defaultValueField); 409 gridBagConstraints = new java.awt.GridBagConstraints (); 410 gridBagConstraints.gridx = 0; 411 gridBagConstraints.gridy = 5; 412 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 413 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 414 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 415 add(defaultValueLabel, gridBagConstraints); 416 417 defaultValueField.setColumns(20); 418 defaultValueField.addActionListener(new java.awt.event.ActionListener () { 419 public void actionPerformed(java.awt.event.ActionEvent evt) { 420 defaultValueFieldActionPerformed(evt); 421 } 422 }); 423 424 defaultValueField.addFocusListener(new java.awt.event.FocusAdapter () { 425 public void focusGained(java.awt.event.FocusEvent evt) { 426 defaultValueFieldFocusGained(evt); 427 } 428 public void focusLost(java.awt.event.FocusEvent evt) { 429 defaultValueFieldFocusLost(evt); 430 } 431 }); 432 433 gridBagConstraints = new java.awt.GridBagConstraints (); 434 gridBagConstraints.gridx = 1; 435 gridBagConstraints.gridy = 5; 436 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 437 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 438 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 439 add(defaultValueField, gridBagConstraints); 440 441 fillPanel.setPreferredSize(new java.awt.Dimension (0, 0)); 442 gridBagConstraints = new java.awt.GridBagConstraints (); 443 gridBagConstraints.gridx = 0; 444 gridBagConstraints.gridy = 6; 445 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 446 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 447 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 448 gridBagConstraints.weightx = 1.0; 449 gridBagConstraints.weighty = 1.0; 450 add(fillPanel, gridBagConstraints); 451 452 } 454 private void defaultValueFieldFocusGained(java.awt.event.FocusEvent evt) { defaultValueField.selectAll (); 457 } 459 private void defaultTypeFieldFocusGained(java.awt.event.FocusEvent evt) { defaultTypeField.selectAll (); 462 } 464 private void enumeratedFieldFocusGained(java.awt.event.FocusEvent evt) { enumeratedField.selectAll (); 467 } 469 private void typeFieldFocusGained(java.awt.event.FocusEvent evt) { typeField.selectAll (); 472 } 474 private void nameFieldFocusGained(java.awt.event.FocusEvent evt) { nameField.selectAll (); 477 } 479 private void elementNameFieldFocusGained(java.awt.event.FocusEvent evt) { elementNameField.selectAll (); 482 } 484 private void defaultValueFieldActionPerformed(java.awt.event.ActionEvent evt) { updateAttributeDefDefaultValue (); 487 } 489 private void defaultValueFieldFocusLost(java.awt.event.FocusEvent evt) { updateAttributeDefDefaultValue (); 492 } 494 private void defaultTypeFieldFocusLost(java.awt.event.FocusEvent evt) { updateAttributeDefDefaultType (); 497 } 499 private void defaultTypeFieldActionPerformed(java.awt.event.ActionEvent evt) { updateAttributeDefDefaultType (); 502 } 504 private void enumeratedFieldActionPerformed(java.awt.event.ActionEvent evt) { updateAttributeDefEnumeratedType (); 507 } 509 private void enumeratedFieldFocusLost(java.awt.event.FocusEvent evt) { updateAttributeDefEnumeratedType (); 512 } 514 private void typeFieldFocusLost(java.awt.event.FocusEvent evt) { updateAttributeDefType (); 517 } 519 private void typeFieldActionPerformed(java.awt.event.ActionEvent evt) { updateAttributeDefType (); 522 } 524 private void nameFieldFocusLost(java.awt.event.FocusEvent evt) { updateAttributeDefName (); 527 } 529 private void nameFieldActionPerformed(java.awt.event.ActionEvent evt) { updateAttributeDefName (); 532 } 534 private javax.swing.JLabel nameLabel; 536 private javax.swing.JLabel enumeratedLabel; 537 private javax.swing.JTextField nameField; 538 private javax.swing.JLabel defaultTypeLabel; 539 private javax.swing.JTextField enumeratedField; 540 private javax.swing.JLabel typeLabel; 541 private javax.swing.JTextField defaultTypeField; 542 private javax.swing.JTextField typeField; 543 private javax.swing.JLabel defaultValueLabel; 544 private javax.swing.JTextField defaultValueField; 545 private javax.swing.JLabel elementNameLabel; 546 private javax.swing.JTextField elementNameField; 547 private javax.swing.JPanel fillPanel; 548 550 551 553 public void initAccessibility (){ 554 555 elementNameField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_elementNameField")); 556 elementNameField.selectAll (); 557 558 nameField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_nameField1")); 559 nameField.selectAll (); 560 561 typeField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_typeField")); 562 typeField.selectAll (); 563 564 enumeratedField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_enumeratedField")); 565 enumeratedField.selectAll (); 566 567 defaultTypeField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_defaultTypeField")); 568 defaultTypeField.selectAll (); 569 570 defaultValueField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_defaultValueField")); 571 defaultValueField.selectAll (); 572 573 this.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_TreeAttlistDeclAttributeDefCustomizer")); 574 } 575 } 576 | Popular Tags |