1 19 package org.netbeans.modules.xml.tax.beans.customizer; 20 21 import java.beans.PropertyChangeEvent ; 22 23 import org.netbeans.tax.TreeAttribute; 24 import org.netbeans.tax.TreeElement; 25 import org.netbeans.tax.TreeException; 26 27 import org.netbeans.modules.xml.tax.util.TAXUtil; 28 import org.netbeans.modules.xml.tax.beans.Lib; 29 30 35 public class TreeAttributeCustomizer extends AbstractTreeCustomizer { 36 37 38 private static final long serialVersionUID = 7976099790445909386L; 39 40 41 private volatile boolean askingDialog = false; 42 43 44 48 49 public TreeAttributeCustomizer () { 50 super (); 51 52 initComponents (); 53 nameLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlName")); valueLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlValue")); } 56 57 58 62 64 protected final TreeAttribute getAttribute () { 65 return (TreeAttribute)getTreeObject (); 66 } 67 68 70 protected final void safePropertyChange (PropertyChangeEvent pche) { 71 super.safePropertyChange (pche); 72 73 if (pche.getPropertyName ().equals (TreeAttribute.PROP_NAME)) { 74 updateNameComponent (); 75 } else if (pche.getPropertyName ().equals (TreeAttribute.PROP_VALUE)) { 76 updateValueComponent (); 77 } 78 } 79 80 82 protected final void updateAttributeName () { 83 if ( askingDialog ) { 84 return; 85 } 86 87 try { 88 String attrName = nameField.getText (); 89 90 boolean toSet = true; 91 TreeElement ownerElement = getAttribute ().getOwnerElement (); 92 if ( ownerElement != null ) { TreeAttribute oldAttribute = ownerElement.getAttribute (attrName); 94 if ( getAttribute () != oldAttribute ) { 95 if ( oldAttribute != null ) { 96 askingDialog = true; 97 toSet = Lib.confirmAction (Util.THIS.getString ("MSG_replace_attribute", attrName)); 98 askingDialog = false; 99 } 100 } 101 } 102 103 if ( toSet ) { 104 getAttribute ().setQName (attrName); 105 } else { 106 updateNameComponent (); 107 } 108 } catch (TreeException exc) { 109 updateNameComponent (); 110 TAXUtil.notifyTreeException (exc); 111 } 112 } 113 114 116 protected final void updateNameComponent () { 117 nameField.setText (getAttribute ().getQName ()); 118 } 119 120 122 protected final void updateAttributeValue () { 123 try { 124 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("\nTreeAttributeCustomizer::updateAttributeValue: valueField.getText() = " + valueField.getText ()); 126 getAttribute ().setValue (valueField.getText ()); 127 } catch (TreeException ex) { 129 if ( Util.THIS.isLoggable() ) Util.THIS.debug (" ::updateAttributeValue: ex = " + ex + "\n"); 131 updateValueComponent (); 132 TAXUtil.notifyTreeException (ex); 133 } 134 } 135 136 138 protected final void updateValueComponent () { 139 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("\nTreeAttributeCustomizer::updateValueComponent: getAttribute().getValue() = " + getAttribute ().getValue ()); 141 valueField.setText (getAttribute ().getValue ()); 142 } 143 144 146 protected void initComponentValues () { 147 updateNameComponent (); 148 updateValueComponent (); 149 } 150 151 152 154 protected final void updateReadOnlyStatus (boolean editable) { 155 nameField.setEditable (editable); 156 valueField.setEditable (editable); 157 } 158 159 164 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 166 167 nameLabel = new javax.swing.JLabel (); 168 nameField = new javax.swing.JTextField (); 169 valueLabel = new javax.swing.JLabel (); 170 valueField = new javax.swing.JTextField (); 171 172 setLayout(new java.awt.GridBagLayout ()); 173 174 nameLabel.setText(Util.THIS.getString ("PROP_xmlName")); 175 nameLabel.setLabelFor(nameField); 176 gridBagConstraints = new java.awt.GridBagConstraints (); 177 gridBagConstraints.gridx = 0; 178 gridBagConstraints.gridy = 0; 179 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 180 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 181 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 182 add(nameLabel, gridBagConstraints); 183 184 nameField.setColumns(20); 185 nameField.addActionListener(new java.awt.event.ActionListener () { 186 public void actionPerformed(java.awt.event.ActionEvent evt) { 187 nameFieldActionPerformed(evt); 188 } 189 }); 190 191 nameField.addFocusListener(new java.awt.event.FocusAdapter () { 192 public void focusGained(java.awt.event.FocusEvent evt) { 193 nameFieldFocusGained(evt); 194 } 195 public void focusLost(java.awt.event.FocusEvent evt) { 196 nameFieldFocusLost(evt); 197 } 198 }); 199 200 gridBagConstraints = new java.awt.GridBagConstraints (); 201 gridBagConstraints.gridx = 1; 202 gridBagConstraints.gridy = 0; 203 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 204 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 205 gridBagConstraints.weightx = 1.0; 206 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 207 add(nameField, gridBagConstraints); 208 209 valueLabel.setText(Util.THIS.getString ("PROP_xmlValue")); 210 valueLabel.setLabelFor(valueField); 211 gridBagConstraints = new java.awt.GridBagConstraints (); 212 gridBagConstraints.gridx = 0; 213 gridBagConstraints.gridy = 1; 214 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 215 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 216 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 217 gridBagConstraints.weighty = 1.0; 218 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 219 add(valueLabel, gridBagConstraints); 220 221 valueField.setColumns(20); 222 valueField.addActionListener(new java.awt.event.ActionListener () { 223 public void actionPerformed(java.awt.event.ActionEvent evt) { 224 valueFieldActionPerformed(evt); 225 } 226 }); 227 228 valueField.addFocusListener(new java.awt.event.FocusAdapter () { 229 public void focusGained(java.awt.event.FocusEvent evt) { 230 valueFieldFocusGained(evt); 231 } 232 public void focusLost(java.awt.event.FocusEvent evt) { 233 valueFieldFocusLost(evt); 234 } 235 }); 236 237 gridBagConstraints = new java.awt.GridBagConstraints (); 238 gridBagConstraints.gridx = 1; 239 gridBagConstraints.gridy = 1; 240 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 241 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 242 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 243 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 244 gridBagConstraints.weightx = 1.0; 245 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 246 add(valueField, gridBagConstraints); 247 248 } 250 private void valueFieldFocusGained(java.awt.event.FocusEvent evt) { if ("new".equals(getClientProperty("xml-edit-mode"))) { valueField.selectAll(); 253 } 254 } 256 private void nameFieldFocusGained(java.awt.event.FocusEvent evt) { if ("new".equals(getClientProperty("xml-edit-mode"))) { nameField.selectAll(); 259 } 260 } 262 264 private void valueFieldFocusLost (java.awt.event.FocusEvent evt) { if ( Util.THIS.isLoggable() ) Util.THIS.debug ("TreeAttributeCustomizer::valueFieldFocusLost"); 268 updateAttributeValue (); 269 } 271 273 private void nameFieldFocusLost (java.awt.event.FocusEvent evt) { updateAttributeName (); 276 } 278 280 private void valueFieldActionPerformed (java.awt.event.ActionEvent evt) { if ( Util.THIS.isLoggable() ) Util.THIS.debug ("TreeAttributeCustomizer::valueFieldActionPerformed"); 284 updateAttributeValue (); 285 } 287 289 private void nameFieldActionPerformed (java.awt.event.ActionEvent evt) { updateAttributeName (); 292 } 294 private javax.swing.JLabel nameLabel; 296 private javax.swing.JTextField nameField; 297 private javax.swing.JLabel valueLabel; 298 private javax.swing.JTextField valueField; 299 301 } 302 | Popular Tags |