KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > propertysheet > ReusablePropertyEnv


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 /*
20  * ReusablePropertyEnv.java
21  *
22  * Created on February 6, 2003, 6:17 PM
23  */

24 package org.openide.explorer.propertysheet;
25
26 import org.openide.nodes.Node;
27
28 import java.beans.*;
29
30
31 /** A subclass of PropertyEnv that can be reused by the rendering infrastructure.
32  * All methods for attaching listeners are no-ops: A renderer will only be
33  * momentarily attached to a given property, and property changes will result
34  * the property being rerendered (and the ReusablePropertyEnv being
35  * reconfigured correctly).<P>
36  * This class is <i>not thread safe</i>. It assumes that it will
37  * only be called from the AWT thread, since it is used in painting
38  * infrastructure. If property misrendering occurs, run NetBeans
39  * with the argument <code>-J-Dnetbeans.reusable.strictthreads=true</code>
40  * and exceptions will be thrown if it is called from off the
41  * AWT thread.
42  * <P>Note, the use of this class may be non-obvious at first - the value of
43  * <code>NODE</code> is set in the rendering loop, by the SheetTable instance,
44  * which knows about the nodes (other classes in the package should only
45  * be interested in the properties they represnt). The instance is actually
46  * used in <code>PropertyEditorBridgeEditor.setPropertyEditor()</code>, but
47  * must rely on the table to configure it.
48  * @author Tim Boudreau
49  */

50 final class ReusablePropertyEnv extends PropertyEnv {
51     private Object JavaDoc NODE = null;
52     private ReusablePropertyModel mdl;
53
54     /** Creates a new instance of ReusablePropertyEnv */
55     public ReusablePropertyEnv() {
56     }
57
58     public ReusablePropertyModel getReusablePropertyModel() {
59         return mdl;
60     }
61
62     void clear() {
63         NODE = null;
64
65         if (mdl != null) {
66             mdl.clear();
67         }
68     }
69
70     void setReusablePropertyModel(ReusablePropertyModel mdl) {
71         this.mdl = mdl;
72     }
73
74     /** Uses the <code>NODE</code> field to supply the beans - if it is an instance
75      * of ProxyNode (multi-selection), returns the nodes that ProxyNode represents. */

76     public Object JavaDoc[] getBeans() {
77         if (ReusablePropertyModel.DEBUG) {
78             ReusablePropertyModel.checkThread();
79         }
80
81         if (getNode() instanceof ProxyNode) {
82             return ((ProxyNode) getNode()).getOriginalNodes();
83         } else if (getNode() instanceof Object JavaDoc[]) {
84             return (Object JavaDoc[]) getNode();
85         } else {
86             return new Object JavaDoc[] { getNode() };
87         }
88     }
89
90     public FeatureDescriptor getFeatureDescriptor() {
91         return mdl.getProperty();
92     }
93
94     public void addVetoableChangeListener(VetoableChangeListener l) {
95     }
96
97     public void addPropertyChangeListener(PropertyChangeListener l) {
98     }
99
100     public void removeVetoableChangeListener(VetoableChangeListener l) {
101     }
102
103     public void removePropertyChangeListener(PropertyChangeListener l) {
104     }
105
106     public boolean isEditable() {
107         boolean result;
108
109         if (mdl.getProperty() != null) {
110             result = mdl.getProperty().canWrite();
111         } else {
112             result = true;
113         }
114
115         return result;
116     }
117
118     public void reset() {
119         setEditable(true);
120         setState(STATE_NEEDS_VALIDATION);
121     }
122
123     public Object JavaDoc getNode() {
124         return NODE;
125     }
126
127     public void setNode(Object JavaDoc NODE) {
128         this.NODE = NODE;
129     }
130 }
131
Popular Tags