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 190115
Collapse All | Expand All

(-)a/openide.nodes/apichanges.xml (+18 lines)
Lines 49-54 Link Here
49
<apidef name="nodes">Nodes API</apidef>
49
<apidef name="nodes">Nodes API</apidef>
50
</apidefs>
50
</apidefs>
51
<changes>
51
<changes>
52
    <change id="Children.createLazy">
53
        <api name="nodes"/>
54
        <summary>A mechanism to lazily update node's children.</summary>
55
        <version major="7" minor="18"/>
56
        <date day="9" month="9" year="2010"/>
57
        <author login="mentlicher"/>
58
        <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible"/>
59
        <description>
60
            <p>
61
            <a href="@TOP@/org/openide/nodes/Children.html">Children</a> have
62
            a new createLazy(Callable&lt;Children&gt; factory) method, that can be used
63
            to provide a lazy children implementation. Callable.call() is called
64
            just when node's children are really needed.
65
            </p>
66
        </description>
67
        <class package="org.openide.nodes" name="Node"/>
68
        <issue number="190115"/>
69
    </change>
52
    <change id="IndexedNode.LookupConstr">
70
    <change id="IndexedNode.LookupConstr">
53
        <api name="nodes"/>
71
        <api name="nodes"/>
54
        <summary>New constructor of IndexedNode</summary>
72
        <summary>New constructor of IndexedNode</summary>
(-)a/openide.nodes/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.nodes
2
OpenIDE-Module: org.openide.nodes
3
OpenIDE-Module-Localizing-Bundle: org/openide/nodes/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/nodes/Bundle.properties
4
AutoUpdate-Essential-Module: true
4
AutoUpdate-Essential-Module: true
5
OpenIDE-Module-Specification-Version: 7.17
5
OpenIDE-Module-Specification-Version: 7.18
6
6
(-)a/openide.nodes/src/org/openide/nodes/Children.java (+82 lines)
Lines 58-63 Link Here
58
import java.util.List;
58
import java.util.List;
59
import java.util.Set;
59
import java.util.Set;
60
import java.util.TreeSet;
60
import java.util.TreeSet;
61
import java.util.concurrent.Callable;
61
import java.util.concurrent.Executor;
62
import java.util.concurrent.Executor;
62
import java.util.concurrent.atomic.AtomicReference;
63
import java.util.concurrent.atomic.AtomicReference;
63
import java.util.logging.Level;
64
import java.util.logging.Level;
Lines 312-317 Link Here
312
            new SynchChildren <T> (factory);
313
            new SynchChildren <T> (factory);
313
    }
314
    }
314
315
316
    /**
317
     * Create a lazy children implementation.
318
     * @param factory The {@link Callable} whose <code>call()</code> method
319
     * is called just when node's children are really needed.
320
     * @return Provides lazy children implementation that can be passed
321
     * to {@link Node} constructor and thus allows the client code to decide
322
     * what children the node should have when {@link Callable#call()} is called.
323
     * @since 7.18
324
     */
325
    public static Children createLazy(Callable<Children> factory) {
326
        return new LazyChildren(factory);
327
    }
328
315
    /** Get the parent node of these children.
329
    /** Get the parent node of these children.
316
    * @return the node attached to this children object, or <code>null</code> if there is none yet
330
    * @return the node attached to this children object, or <code>null</code> if there is none yet
317
    */
331
    */
Lines 1793-1798 Link Here
1793
        }
1807
        }
1794
    }
1808
    }
1795
1809
1810
    /**
1811
     * Lazy children implementation
1812
     */
1813
    static class LazyChildren extends Children {
1814
1815
        private Callable<Children> factory;
1816
        private Children original;
1817
        private final Object originalLock= new Object();
1818
1819
        LazyChildren(Callable<Children> factory) {
1820
            this.factory = factory;
1821
        }
1822
1823
        Children getOriginal() {
1824
            synchronized (originalLock) {
1825
                if (original == null) {
1826
                    try {
1827
                        original = factory.call();
1828
                    } catch (Exception ex) {
1829
                        throw new RuntimeException(ex);
1830
                    }
1831
                }
1832
                return original;
1833
            }
1834
        }
1835
1836
        @Override
1837
        public boolean add(Node[] nodes) {
1838
            return getOriginal().add(nodes);
1839
        }
1840
1841
        @Override
1842
        public boolean remove(Node[] nodes) {
1843
            return getOriginal().remove(nodes);
1844
        }
1845
1846
        @Override
1847
        protected void addNotify() {
1848
            getOriginal().addNotify();
1849
        }
1850
1851
        @Override
1852
        protected void removeNotify() {
1853
            getOriginal().removeNotify();
1854
        }
1855
1856
        @Override
1857
        EntrySupport entrySupport() {
1858
            return getOriginal().entrySupport();
1859
        }
1860
1861
        @Override
1862
        public Node findChild(String name) {
1863
            return getOriginal().findChild(name);
1864
        }
1865
        
1866
1867
        /*
1868
        void postInitializeEntrySupport(EntrySupport es) {
1869
            if (getNodesEntry() == null) {
1870
                nodesEntry = createNodesEntry();
1871
            }
1872
            es.setEntries(Collections.singleton(getNodesEntry()));
1873
        }
1874
         */
1875
        
1876
    }
1877
1796
    /*
1878
    /*
1797
      static void printNodes (Node[] n) {
1879
      static void printNodes (Node[] n) {
1798
        for (int i = 0; i < n.length; i++) {
1880
        for (int i = 0; i < n.length; i++) {
(-)a/openide.nodes/src/org/openide/nodes/FilterNode.java (+2 lines)
Lines 1075-1080 Link Here
1075
                    }
1075
                    }
1076
                );
1076
                );
1077
            }
1077
            }
1078
        } else {
1079
            super.updateChildren();
1078
        }
1080
        }
1079
    }
1081
    }
1080
1082
(-)a/openide.nodes/src/org/openide/nodes/Node.java (+6 lines)
Lines 465-470 Link Here
465
     * whether children are of the right subclass
465
     * whether children are of the right subclass
466
     */
466
     */
467
    void updateChildren() {
467
    void updateChildren() {
468
        Children ch = hierarchy;
469
        if (ch instanceof Children.LazyChildren) {
470
            // Replace the children with the ones provided lazily:
471
            ch = ((Children.LazyChildren) ch).getOriginal();
472
            setChildren(ch);
473
        }
468
    }
474
    }
469
475
470
    /** Allows to change Children of the node. Call to this method aquires
476
    /** Allows to change Children of the node. Call to this method aquires
(-)a/openide.nodes/test/unit/src/org/openide/nodes/SetChildrenTest.java (+29 lines)
Lines 46-51 Link Here
46
46
47
import java.beans.*;
47
import java.beans.*;
48
import java.util.*;
48
import java.util.*;
49
import java.util.concurrent.Callable;
49
50
50
import org.netbeans.junit.*;
51
import org.netbeans.junit.*;
51
52
Lines 261-266 Link Here
261
        
262
        
262
        GoldenEvent.assertEvents ( nl.getEvents(), goldenEvents, PropertyChangeEvent.class );        
263
        GoldenEvent.assertEvents ( nl.getEvents(), goldenEvents, PropertyChangeEvent.class );        
263
    }
264
    }
265
266
    /** Test whether Children are retrieved lazily
267
     */
268
    public void testUpdateChildren() {
269
        UpdateChildrenFactory uchf = new UpdateChildrenFactory();
270
        AbstractNode n = new AbstractNode(Children.createLazy(uchf));
271
        assertNull(uchf.newChildren);
272
        assertSame("Children not updated", uchf.newChildrenToReturn, n.getChildren());
273
274
        uchf = new UpdateChildrenFactory();
275
        n = new AbstractNode(Children.createLazy(uchf));
276
        assertFalse("Children not updated, the node should not be leaf", n.isLeaf());
277
    }
264
    
278
    
265
    
279
    
266
    /** Tests property changes on old and new nodes
280
    /** Tests property changes on old and new nodes
Lines 290-295 Link Here
290
        }        
304
        }        
291
    }
305
    }
292
    
306
    
307
    private static class UpdateChildrenFactory implements Callable<Children> {
308
309
        Children newChildrenToReturn = new Children.Array();
310
        Children newChildren;
311
312
        @Override
313
        public Children call() throws Exception {
314
            if (newChildren == null) {
315
                newChildren = newChildrenToReturn;
316
            }
317
            return newChildren;
318
        }
319
        
320
    }
321
293
    /** Useful class for testing events.
322
    /** Useful class for testing events.
294
     */
323
     */
295
    
324
    

Return to bug 190115