KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > tax > beans > customizer > TreeAttributeCustomizer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.tax.beans.customizer;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
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 /**
31  *
32  * @author Libor Kramolis
33  * @version 0.1
34  */

35 public class TreeAttributeCustomizer extends AbstractTreeCustomizer {
36
37     /** Serial Version UID */
38     private static final long serialVersionUID = 7976099790445909386L;
39
40     /** */
41     private volatile boolean askingDialog = false;
42     
43     
44     //
45
// init
46
//
47

48     /** Creates new TreeAttributeCustomizer. */
49     public TreeAttributeCustomizer () {
50         super ();
51         
52         initComponents ();
53         nameLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlName")); // NOI18N
54
valueLabel.setDisplayedMnemonic (Util.THIS.getChar ("MNE_xmlValue")); // NOI18N
55
}
56     
57     
58     //
59
// itself
60
//
61

62     /**
63      */

64     protected final TreeAttribute getAttribute () {
65         return (TreeAttribute)getTreeObject ();
66     }
67     
68     /**
69      */

70     protected final void safePropertyChange (PropertyChangeEvent JavaDoc 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     /**
81      */

82     protected final void updateAttributeName () {
83         if ( askingDialog ) {
84             return;
85         }
86         
87         try {
88             String JavaDoc attrName = nameField.getText ();
89             
90             boolean toSet = true;
91             TreeElement ownerElement = getAttribute ().getOwnerElement ();
92             if ( ownerElement != null ) { // if it is not new attribute (has owner element)
93
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     /**
115      */

116     protected final void updateNameComponent () {
117         nameField.setText (getAttribute ().getQName ());
118     }
119     
120     /**
121      */

122     protected final void updateAttributeValue () {
123         try {
124             if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("\nTreeAttributeCustomizer::updateAttributeValue: valueField.getText() = " + valueField.getText ());//, new RuntimeException()); // NOI18N
125

126             getAttribute ().setValue (valueField.getText ());
127             // TAXUtil.setAttributeValue (getAttribute(), valueField.getText());
128
} catch (TreeException ex) {
129             if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (" ::updateAttributeValue: ex = " + ex + "\n"); // NOI18N
130

131             updateValueComponent ();
132             TAXUtil.notifyTreeException (ex);
133         }
134     }
135     
136     /**
137      */

138     protected final void updateValueComponent () {
139         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("\nTreeAttributeCustomizer::updateValueComponent: getAttribute().getValue() = " + getAttribute ().getValue ());//, new RuntimeException()); // NOI18N
140

141         valueField.setText (getAttribute ().getValue ());
142     }
143     
144     /**
145      */

146     protected void initComponentValues () {
147         updateNameComponent ();
148         updateValueComponent ();
149     }
150     
151     
152     /**
153      */

154     protected final void updateReadOnlyStatus (boolean editable) {
155         nameField.setEditable (editable);
156         valueField.setEditable (editable);
157     }
158     
159     /** This method is called from within the constructor to
160      * initialize the form.
161      * WARNING: Do NOT modify this code. The content of this method is
162      * always regenerated by the FormEditor.
163      */

164     private void initComponents() {//GEN-BEGIN:initComponents
165
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
166
167         nameLabel = new javax.swing.JLabel JavaDoc();
168         nameField = new javax.swing.JTextField JavaDoc();
169         valueLabel = new javax.swing.JLabel JavaDoc();
170         valueField = new javax.swing.JTextField JavaDoc();
171
172         setLayout(new java.awt.GridBagLayout JavaDoc());
173
174         nameLabel.setText(Util.THIS.getString ("PROP_xmlName"));
175         nameLabel.setLabelFor(nameField);
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(12, 12, 0, 0);
182         add(nameLabel, gridBagConstraints);
183
184         nameField.setColumns(20);
185         nameField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
186             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
187                 nameFieldActionPerformed(evt);
188             }
189         });
190
191         nameField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
192             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
193                 nameFieldFocusGained(evt);
194             }
195             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
196                 nameFieldFocusLost(evt);
197             }
198         });
199
200         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc();
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 JavaDoc(12, 12, 0, 0);
219         add(valueLabel, gridBagConstraints);
220
221         valueField.setColumns(20);
222         valueField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
223             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
224                 valueFieldActionPerformed(evt);
225             }
226         });
227
228         valueField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
229             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
230                 valueFieldFocusGained(evt);
231             }
232             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
233                 valueFieldFocusLost(evt);
234             }
235         });
236
237         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(12, 12, 0, 11);
246         add(valueField, gridBagConstraints);
247
248     }//GEN-END:initComponents
249

250     private void valueFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_valueFieldFocusGained
251
if ("new".equals(getClientProperty("xml-edit-mode"))) { // NOI18N
252
valueField.selectAll();
253         }
254     }//GEN-LAST:event_valueFieldFocusGained
255

256     private void nameFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldFocusGained
257
if ("new".equals(getClientProperty("xml-edit-mode"))) { // NOI18N
258
nameField.selectAll();
259         }
260     }//GEN-LAST:event_nameFieldFocusGained
261

262     /**
263      */

264     private void valueFieldFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_valueFieldFocusLost
265
// Add your handling code here:
266
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("TreeAttributeCustomizer::valueFieldFocusLost"); // NOI18N
267

268         updateAttributeValue ();
269     }//GEN-LAST:event_valueFieldFocusLost
270

271     /**
272      */

273     private void nameFieldFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldFocusLost
274
// Add your handling code here:
275
updateAttributeName ();
276     }//GEN-LAST:event_nameFieldFocusLost
277

278     /**
279      */

280     private void valueFieldActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_valueFieldActionPerformed
281
// Add your handling code here:
282
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("TreeAttributeCustomizer::valueFieldActionPerformed"); // NOI18N
283

284         updateAttributeValue ();
285     }//GEN-LAST:event_valueFieldActionPerformed
286

287     /**
288      */

289     private void nameFieldActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_nameFieldActionPerformed
290
// Add your handling code here:
291
updateAttributeName ();
292     }//GEN-LAST:event_nameFieldActionPerformed
293

294     // Variables declaration - do not modify//GEN-BEGIN:variables
295
private javax.swing.JLabel JavaDoc nameLabel;
296     private javax.swing.JTextField JavaDoc nameField;
297     private javax.swing.JLabel JavaDoc valueLabel;
298     private javax.swing.JTextField JavaDoc valueField;
299     // End of variables declaration//GEN-END:variables
300

301 }
302
Popular Tags