? test/unit/src/org/openide/nodes/FilterNode51862Test.java Index: apichanges.xml =================================================================== RCS file: /shared/data/ccvs/repository/openide/nodes/apichanges.xml,v retrieving revision 1.6 diff -u -r1.6 apichanges.xml --- apichanges.xml 1 Jul 2006 09:08:55 -0000 1.6 +++ apichanges.xml 11 Aug 2006 12:42:47 -0000 @@ -23,6 +23,20 @@ Nodes API + + + BeanNode constructor allows passing Lookup instance + + + + + + Adding a new constructors to BeanNode, allowing + subclasses to pass context Lookup. + + + + AbstractNode allows using different icon extensions Index: nbproject/project.properties =================================================================== RCS file: /shared/data/ccvs/repository/openide/nodes/nbproject/project.properties,v retrieving revision 1.7 diff -u -r1.7 project.properties --- nbproject/project.properties 2 Aug 2006 06:53:32 -0000 1.7 +++ nbproject/project.properties 11 Aug 2006 12:42:47 -0000 @@ -23,4 +23,4 @@ javadoc.arch=${basedir}/../arch/arch-openide-nodes.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=6.8.0 +spec.version.base=6.9.0 Index: src/org/openide/nodes/BeanNode.java =================================================================== RCS file: /shared/data/ccvs/repository/openide/nodes/src/org/openide/nodes/BeanNode.java,v retrieving revision 1.9 diff -u -r1.9 BeanNode.java --- src/org/openide/nodes/BeanNode.java 10 Aug 2006 15:56:33 -0000 1.9 +++ src/org/openide/nodes/BeanNode.java 11 Aug 2006 12:42:48 -0000 @@ -45,6 +45,10 @@ import org.openide.util.Exceptions; import org.openide.util.HelpCtx; import org.openide.util.Utilities; +import org.openide.util.Lookup; +import org.openide.util.lookup.InstanceContent; +import org.openide.util.lookup.ProxyLookup; +import org.openide.util.lookup.AbstractLookup; import org.openide.util.WeakListeners; import org.openide.util.actions.SystemAction; @@ -83,6 +87,14 @@ /** is synchronization of name in progress */ private boolean synchronizeName; + + /** If there was no provided lookup, this field is null + * and the bean is placed into CookieSet. + * If there was a lookup, it is wrapped into proxy + * with this instanceContent as second delegate. + * The bean is then registered here. + */ + private InstanceContent beanHolder; // init .................................................................................................................. @@ -94,7 +106,7 @@ * @throws IntrospectionException if the bean cannot be analyzed */ public BeanNode(T bean) throws IntrospectionException { - this(bean, getChildren(bean)); + this(bean, null, null); } /** Constructs a node for a JavaBean with a defined child list. @@ -105,7 +117,21 @@ */ protected BeanNode(T bean, Children children) throws IntrospectionException { - super((children == null) ? getChildren(bean) : children); + this(bean, children, null); + } + + /** Constructs a node for a JavaBean with a defined child list. + * Intended for use by subclasses with different strategies for computing the children. + * @param bean the bean this node will be based on + * @param children children for the node (default if null) + * @param lkp the lookup to provide content of {@link #getLookup} + * and also {@link #getCookie} + * @throws IntrospectionException if the bean cannot be analyzed + * @since 6.xx + */ + protected BeanNode(T bean, Children children, Lookup lkp) + throws IntrospectionException { + super((children == null) ? getChildren(bean) : children, lkp); if (bean == null) { throw new NullPointerException("cannot make a node for a null bean"); // NOI18N @@ -123,6 +149,13 @@ throw mkie(le); } } + + final Lookup replaceProvidedLookup(Lookup lookup) { + if (lookup == null) return null; + beanHolder = new InstanceContent(); + AbstractLookup al = new AbstractLookup(beanHolder); + return new ProxyLookup(new Lookup[] { lookup, al }); + } private static Children getChildren(Object bean) { if (bean instanceof BeanContext) { @@ -573,7 +606,11 @@ Node.Cookie instanceCookie = TMUtil.createInstanceCookie(bean); if (instanceCookie != null) { - getCookieSet().add(instanceCookie); + if (beanHolder == null) { + getCookieSet().add(instanceCookie); + } else { + beanHolder.add(instanceCookie); + } } } Index: test/unit/src/org/openide/nodes/BeanNodeTest.java =================================================================== RCS file: /shared/data/ccvs/repository/openide/nodes/test/unit/src/org/openide/nodes/BeanNodeTest.java,v retrieving revision 1.2 diff -u -r1.2 BeanNodeTest.java --- test/unit/src/org/openide/nodes/BeanNodeTest.java 1 Jul 2006 09:09:01 -0000 1.2 +++ test/unit/src/org/openide/nodes/BeanNodeTest.java 11 Aug 2006 12:42:48 -0000 @@ -27,6 +27,9 @@ import org.netbeans.junit.NbTestSuite; import org.openide.nodes.*; +import org.openide.cookies.InstanceCookie; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; /** Test updating of bean children in proper circumstances, e.g. * deleting nodes or beans. @@ -141,6 +144,41 @@ bean.setHiddenProperty (11); assertFalse ("No change should be notified", pcl.changed ()); + } + + public void testLookupAndBean() throws Exception { + class MyClass { + } + + MyClass inst = new MyClass(); + + Bean1 b = new Bean1(); + BeanNode n = new BeanNode(b, null, Lookups.singleton(inst)); + + // the bean is present in CookieSet ... + InstanceCookie ic1 = n.getCookie(InstanceCookie.class); + assertNotNull(ic1); + assertSame(b, ic1.instanceCreate()); + + // ... and in the lookup as well + InstanceCookie ic2 = n.getLookup().lookup(InstanceCookie.class); + assertNotNull(ic2); + assertSame(b, ic2.instanceCreate()); + + // my lookup is propagated + MyClass tst = n.getLookup().lookup(MyClass.class); + assertSame(inst, tst); + } + + public void testCanUseCookieSetWithoutLookup() throws Exception { + class MyBeanNode extends BeanNode { + MyBeanNode(Object bean) throws IntrospectionException { + super(bean, null, null); + getCookieSet(); + } + }; + + new MyBeanNode(new Bean1()); } // XXX test synchronizeName