KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > openide > explorer > TTVEnvBridge


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 package org.netbeans.modules.openide.explorer;
21
22 import java.util.Map JavaDoc;
23 import java.util.WeakHashMap JavaDoc;
24
25
26 /** A temporary workaround for issue 38132, getBeans returns null on
27  * TreeTableView. A better solution will be used for the TTV rewrite.
28  * <P>
29  * What it does:
30  * TableSheetCell calls TTVEnvBridge.getInstance(this), and calls
31  * setCurrentBeans with the node being rendered/edited.
32  * Then it puts itself as a client property of the PropertyPanel it is
33  * using to render.
34  * <P>
35  * On PropertyPanel.setProperty(), the PropertyPanel checks itself for this
36  * client property, and if it's there, calls findInstance to fetch the
37  * TTVEnvBridge instance, calls getCurrentBeans() and puts the result into
38  * a private field accessible via a package private method. It then calls
39  * TTVEnvBridge.clear() to remove references to the node.
40  * <P>
41  * If an editor component embedded in a PropertyPanel (EditablePropertyDisplayer)
42  * finds it is dealing with an ExPropertyEditor, it calls
43  * EditablePropertyDisplayer.findBeans(this). That method first checks if the
44  * property model is non-null, and if it is, checks a world of permutations of
45  * PropertyModel that have various ways of locating their beans. If there is
46  * no property model, then it checks if its parent is a PropertyPanel. If it
47  * is, it calls getBeans() on that.
48  * <P>
49  * If a renderer component embedded in a PropertyPanel (RendererPropertyDisplayer)
50  * finds it is dealing with an ExPropertyEditor, it calls
51  * EditablePropertyDisplayer.findBeans(this), as described above, from its
52  * paintComponent() method, before it calls RendererFactory.getRenderer(getProperty()).
53  * Then it sets the field ReusablePropertyEnv.NODE to the value returned by
54  * findBeans(), since there is a shared instance of ReusablePropertyEnv which
55  * is the PropertyEnv for all properties when they are renderered (for performance
56  * reasons).
57  * <P>
58  * Note: As far as is known, the TaskList module is the only module that has
59  * ever used PropertyEnv.getBeans(). It should be deprecated, along with
60  * PropertyEnv, in a future release.
61  *
62  * @author Tim Boudreau
63  */

64 public class TTVEnvBridge {
65     private static Map JavaDoc<Object JavaDoc, TTVEnvBridge> bridges = new WeakHashMap JavaDoc<Object JavaDoc, TTVEnvBridge>();
66     Object JavaDoc[] beans = null;
67     /** Creates a new instance of TTVEnvBridge */
68     private TTVEnvBridge() {
69     }
70     
71     public static TTVEnvBridge getInstance(Object JavaDoc identifier) {
72         TTVEnvBridge result = bridges.get(identifier);
73         if (result == null) {
74             result = new TTVEnvBridge();
75             bridges.put (identifier, result);
76         }
77         return result;
78     }
79     
80     public static TTVEnvBridge findInstance(Object JavaDoc identifier) {
81         return bridges.get(identifier);
82     }
83     
84     public void setCurrentBeans (Object JavaDoc[] o) {
85         beans = o;
86     }
87     
88     public void clear() {
89         beans = null;
90     }
91     
92     public Object JavaDoc[] getCurrentBeans() {
93         if (beans == null) {
94             return new Object JavaDoc[0];
95         } else {
96             return beans;
97         }
98     }
99 }
100
Popular Tags