1 19 package org.netbeans.modules.xml.tax.beans.customizer; 20 21 import java.awt.Component ; 22 import java.awt.BorderLayout ; 23 import java.beans.PropertyChangeEvent ; 24 25 import org.netbeans.tax.TreeNamedObjectMap; 26 import org.netbeans.tax.TreeElement; 27 import org.netbeans.tax.TreeException; 28 29 import org.netbeans.modules.xml.tax.beans.Lib; 30 import org.netbeans.modules.xml.tax.util.TAXUtil; 31 32 37 public class TreeElementCustomizer extends AbstractTreeCustomizer { 38 39 40 private static final long serialVersionUID = -2086561604130767387L; 41 42 43 47 48 public TreeElementCustomizer () { 49 super (); 50 51 initComponents (); 52 nameLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlName")); tableLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_element_attributelist_label")); initAccessibility (); 55 } 56 57 58 62 64 protected final TreeElement getElement () { 65 return (TreeElement)getTreeObject (); 66 } 67 68 70 protected final void safePropertyChange (PropertyChangeEvent pche) { 71 super.safePropertyChange (pche); 72 73 if (pche.getPropertyName ().equals (TreeElement.PROP_TAG_NAME)) { 74 updateNameComponent (); 75 } 76 } 77 78 80 protected final void updateElementName () { 81 try { 82 getElement ().setQName (nameField.getText ()); 83 } catch (TreeException exc) { 84 updateNameComponent (); 85 TAXUtil.notifyTreeException (exc); 86 } 87 } 88 89 91 protected final void updateNameComponent () { 92 nameField.setText (getElement ().getQName ()); 93 } 94 95 97 protected final void initComponentValues () { 98 updateNameComponent (); 99 } 100 101 103 protected void ownInitComponents () { 104 TreeNamedObjectMap attributes = getElement ().getAttributes (); 105 106 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("TreeElementCustomizer::ownInitComponents: attributes = " + attributes); 108 attributesCustomizer = Lib.getCustomizer (TreeElement.class, attributes, "attributes"); 110 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("TreeElementCustomizer::ownInitComponents: attributesCustomizer = " + attributesCustomizer); 112 if (attributesCustomizer != null) { 113 attributeListPanel.add (attributesCustomizer, BorderLayout.CENTER); 114 } 115 } 116 117 119 protected void updateReadOnlyStatus (boolean editable) { 120 nameField.setEditable (editable); 121 if ( attributesCustomizer != null ) 122 attributesCustomizer.setEnabled (editable); } 124 125 126 131 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 133 134 nameLabel = new javax.swing.JLabel (); 135 nameField = new javax.swing.JTextField (); 136 jPanel2 = new javax.swing.JPanel (); 137 jPanel1 = new javax.swing.JPanel (); 138 tableLabel = new javax.swing.JLabel (); 139 attributeListPanel = new javax.swing.JPanel (); 140 141 setLayout(new java.awt.GridBagLayout ()); 142 143 setPreferredSize(new java.awt.Dimension (350, 230)); 144 nameLabel.setText(Util.THIS.getString ("PROP_xmlName")); 145 nameLabel.setLabelFor(nameField); 146 gridBagConstraints = new java.awt.GridBagConstraints (); 147 gridBagConstraints.gridy = 0; 148 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 149 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 150 add(nameLabel, gridBagConstraints); 151 152 nameField.setColumns(20); 153 nameField.addActionListener(new java.awt.event.ActionListener () { 154 public void actionPerformed(java.awt.event.ActionEvent evt) { 155 nameFieldActionPerformed(evt); 156 } 157 }); 158 159 nameField.addFocusListener(new java.awt.event.FocusAdapter () { 160 public void focusGained(java.awt.event.FocusEvent evt) { 161 nameFieldFocusGained(evt); 162 } 163 public void focusLost(java.awt.event.FocusEvent evt) { 164 nameFieldFocusLost(evt); 165 } 166 }); 167 168 gridBagConstraints = new java.awt.GridBagConstraints (); 169 gridBagConstraints.gridy = 0; 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 (12, 12, 0, 11); 174 add(nameField, gridBagConstraints); 175 176 jPanel2.setLayout(new java.awt.GridBagLayout ()); 177 178 jPanel1.setLayout(new java.awt.GridBagLayout ()); 179 180 tableLabel.setText(Util.THIS.getString ("TEXT_element_attributelist_label")); 181 tableLabel.setLabelFor(attributeListPanel); 182 gridBagConstraints = new java.awt.GridBagConstraints (); 183 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 184 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 185 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 186 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 187 gridBagConstraints.weightx = 1.0; 188 gridBagConstraints.weighty = 1.0; 189 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 190 jPanel1.add(tableLabel, gridBagConstraints); 191 192 gridBagConstraints = new java.awt.GridBagConstraints (); 193 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 194 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 195 jPanel2.add(jPanel1, gridBagConstraints); 196 197 attributeListPanel.setLayout(new java.awt.BorderLayout ()); 198 199 gridBagConstraints = new java.awt.GridBagConstraints (); 200 gridBagConstraints.gridx = 0; 201 gridBagConstraints.gridy = 1; 202 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 203 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 204 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 205 gridBagConstraints.weightx = 1.0; 206 gridBagConstraints.weighty = 1.0; 207 jPanel2.add(attributeListPanel, gridBagConstraints); 208 209 gridBagConstraints = new java.awt.GridBagConstraints (); 210 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 211 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 212 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 213 gridBagConstraints.weightx = 1.0; 214 gridBagConstraints.weighty = 1.0; 215 add(jPanel2, gridBagConstraints); 216 217 } 219 private void nameFieldFocusGained(java.awt.event.FocusEvent evt) { if ("new".equals(getClientProperty("xml-edit-mode"))) { nameField.selectAll(); 222 } 223 } 225 227 private void nameFieldFocusLost (java.awt.event.FocusEvent evt) { updateElementName (); 230 } 232 234 private void nameFieldActionPerformed (java.awt.event.ActionEvent evt) { updateElementName (); 237 } 239 private javax.swing.JLabel nameLabel; 241 private javax.swing.JLabel tableLabel; 242 private javax.swing.JTextField nameField; 243 private javax.swing.JPanel attributeListPanel; 244 private javax.swing.JPanel jPanel2; 245 private javax.swing.JPanel jPanel1; 246 248 private Component attributesCustomizer; 249 250 252 public void initAccessibility (){ 253 254 this.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_TreeElementCustomizer")); 255 nameField.getAccessibleContext ().setAccessibleDescription (Util.THIS.getString ("ACSD_nameField7")); 256 } 257 258 } 259 | Popular Tags |