This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 67098
Collapse All | Expand All

(-)apichanges.xml (+14 lines)
Lines 23-28 Link Here
23
<apidef name="nodes">Nodes API</apidef>
23
<apidef name="nodes">Nodes API</apidef>
24
</apidefs>
24
</apidefs>
25
<changes>
25
<changes>
26
<change id="BeanNode.LookupCtor">
27
     <api name="nodes"/>
28
     <summary>BeanNode constructor allows passing Lookup instance</summary>
29
     <version major="6" minor="9"/>
30
     <date day="11" month="8" year="2006"/>
31
     <author login="pnejedly"/>
32
     <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/>
33
     <description>
34
        Adding a new constructors to <code>BeanNode</code>, allowing
35
        subclasses to pass context Lookup.
36
     </description>
37
     <class package="org.openide.nodes" name="BeanNode"/>
38
     <issue number="67098"/>
39
    </change>
26
<change id="AbstractNode.setIconBaseWithExtension">
40
<change id="AbstractNode.setIconBaseWithExtension">
27
     <api name="nodes"/>
41
     <api name="nodes"/>
28
     <summary>AbstractNode allows using different icon extensions</summary>
42
     <summary>AbstractNode allows using different icon extensions</summary>
(-)nbproject/project.properties (-1 / +1 lines)
Lines 23-26 Link Here
23
javadoc.arch=${basedir}/../arch/arch-openide-nodes.xml
23
javadoc.arch=${basedir}/../arch/arch-openide-nodes.xml
24
javadoc.apichanges=${basedir}/apichanges.xml
24
javadoc.apichanges=${basedir}/apichanges.xml
25
25
26
spec.version.base=6.8.0
26
spec.version.base=6.9.0
(-)src/org/openide/nodes/BeanNode.java (-3 / +40 lines)
Lines 45-50 Link Here
45
import org.openide.util.Exceptions;
45
import org.openide.util.Exceptions;
46
import org.openide.util.HelpCtx;
46
import org.openide.util.HelpCtx;
47
import org.openide.util.Utilities;
47
import org.openide.util.Utilities;
48
import org.openide.util.Lookup;
49
import org.openide.util.lookup.InstanceContent;
50
import org.openide.util.lookup.ProxyLookup;
51
import org.openide.util.lookup.AbstractLookup;
48
import org.openide.util.WeakListeners;
52
import org.openide.util.WeakListeners;
49
import org.openide.util.actions.SystemAction;
53
import org.openide.util.actions.SystemAction;
50
54
Lines 83-88 Link Here
83
87
84
    /** is synchronization of name in progress */
88
    /** is synchronization of name in progress */
85
    private boolean synchronizeName;
89
    private boolean synchronizeName;
90
    
91
    /** If there was no provided lookup, this field is null
92
     * and the bean is placed into CookieSet.
93
     * If there was a lookup, it is wrapped into proxy 
94
     * with this instanceContent as second delegate.
95
     * The bean is then registered here.
96
     */
97
    private InstanceContent beanHolder;
86
98
87
    // init ..................................................................................................................
99
    // init ..................................................................................................................
88
100
Lines 94-100 Link Here
94
    * @throws IntrospectionException if the bean cannot be analyzed
106
    * @throws IntrospectionException if the bean cannot be analyzed
95
    */
107
    */
96
    public BeanNode(T bean) throws IntrospectionException {
108
    public BeanNode(T bean) throws IntrospectionException {
97
        this(bean, getChildren(bean));
109
        this(bean, null, null);
98
    }
110
    }
99
111
100
    /** Constructs a node for a JavaBean with a defined child list.
112
    /** Constructs a node for a JavaBean with a defined child list.
Lines 105-111 Link Here
105
    */
117
    */
106
    protected BeanNode(T bean, Children children)
118
    protected BeanNode(T bean, Children children)
107
    throws IntrospectionException {
119
    throws IntrospectionException {
108
        super((children == null) ? getChildren(bean) : children);
120
        this(bean, children, null);
121
    }
122
123
    /** Constructs a node for a JavaBean with a defined child list.
124
    * Intended for use by subclasses with different strategies for computing the children.
125
    * @param bean the bean this node will be based on
126
    * @param children children for the node (default if null)
127
    * @param lkp the lookup to provide content of {@link #getLookup}
128
    *   and also {@link #getCookie}
129
    * @throws IntrospectionException if the bean cannot be analyzed
130
    * @since 6.xx
131
    */
132
    protected BeanNode(T bean, Children children, Lookup lkp)
133
    throws IntrospectionException {
134
        super((children == null) ? getChildren(bean) : children, lkp);
109
135
110
        if (bean == null) {
136
        if (bean == null) {
111
            throw new NullPointerException("cannot make a node for a null bean"); // NOI18N
137
            throw new NullPointerException("cannot make a node for a null bean"); // NOI18N
Lines 123-128 Link Here
123
            throw mkie(le);
149
            throw mkie(le);
124
        }
150
        }
125
    }
151
    }
152
    
153
    final Lookup replaceProvidedLookup(Lookup lookup) {
154
        if (lookup == null) return null;
155
        beanHolder = new InstanceContent();
156
        AbstractLookup al = new AbstractLookup(beanHolder);
157
        return new ProxyLookup(new Lookup[] { lookup, al });
158
    } 
126
159
127
    private static Children getChildren(Object bean) {
160
    private static Children getChildren(Object bean) {
128
        if (bean instanceof BeanContext) {
161
        if (bean instanceof BeanContext) {
Lines 573-579 Link Here
573
        Node.Cookie instanceCookie = TMUtil.createInstanceCookie(bean);
606
        Node.Cookie instanceCookie = TMUtil.createInstanceCookie(bean);
574
607
575
        if (instanceCookie != null) {
608
        if (instanceCookie != null) {
576
            getCookieSet().add(instanceCookie);
609
            if (beanHolder == null) {
610
                getCookieSet().add(instanceCookie);
611
            } else {
612
                beanHolder.add(instanceCookie);
613
            }
577
        }
614
        }
578
    }
615
    }
579
616
(-)test/unit/src/org/openide/nodes/BeanNodeTest.java (+38 lines)
Lines 27-32 Link Here
27
import org.netbeans.junit.NbTestSuite;
27
import org.netbeans.junit.NbTestSuite;
28
28
29
import org.openide.nodes.*;
29
import org.openide.nodes.*;
30
import org.openide.cookies.InstanceCookie;
31
import org.openide.util.Lookup;
32
import org.openide.util.lookup.Lookups;
30
33
31
/** Test updating of bean children in proper circumstances, e.g.
34
/** Test updating of bean children in proper circumstances, e.g.
32
 * deleting nodes or beans.
35
 * deleting nodes or beans.
Lines 141-146 Link Here
141
        bean.setHiddenProperty (11);
144
        bean.setHiddenProperty (11);
142
        
145
        
143
        assertFalse ("No change should be notified", pcl.changed ());
146
        assertFalse ("No change should be notified", pcl.changed ());
147
    }
148
    
149
    public void testLookupAndBean() throws Exception {
150
        class MyClass {
151
        }
152
153
        MyClass inst = new MyClass();
154
155
        Bean1 b = new Bean1();
156
        BeanNode n = new BeanNode(b, null, Lookups.singleton(inst));
157
158
        // the bean is present in CookieSet ...
159
        InstanceCookie ic1 = n.getCookie(InstanceCookie.class);
160
        assertNotNull(ic1);
161
        assertSame(b, ic1.instanceCreate());
162
163
        // ... and in the lookup as well
164
        InstanceCookie ic2 = n.getLookup().lookup(InstanceCookie.class);
165
        assertNotNull(ic2);
166
        assertSame(b, ic2.instanceCreate());
167
168
        // my lookup is propagated
169
        MyClass tst = n.getLookup().lookup(MyClass.class);
170
        assertSame(inst, tst);
171
    }
172
173
    public void testCanUseCookieSetWithoutLookup() throws Exception {
174
        class MyBeanNode extends BeanNode {
175
            MyBeanNode(Object bean) throws IntrospectionException {
176
                super(bean, null, null);
177
                getCookieSet();
178
            }
179
        };
180
181
        new MyBeanNode(new Bean1());
144
    }
182
    }
145
    
183
    
146
    // XXX test synchronizeName
184
    // XXX test synchronizeName

Return to bug 67098