Automatic expand all nodes of BeanTreeView when explorer is opened for the first time

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Automatic expand all nodes of BeanTreeView when explorer is opened for the first time

stephaneleonel
Hello Community,

We are building a school management app that will be soon released as free an open source in netbeans platform portal.

The application contains an explorer which load data from database and displays a tree at startup :
[Image: https://forums.netbeans.org/files/capture1_813.png ]

But, at startup, only the root is displayed as you can see in the image above.

We want to expand automatically all nodes at startup, like this :

[Image: https://forums.netbeans.org/files/capture2_441.png ]

How can we do that ?

Note that childs are asynchronously built.




Attachments:
http://forums.netbeans.org//files/capture2_441.png
http://forums.netbeans.org//files/capture1_813.png

Reply | Threaded
Open this post in threaded view
|

Re: Automatic expand all nodes of BeanTreeView when explorer is opened for the first time

stephen cumminger
BeanTreeView.expandAll();


Steve

-----Original Message-----
From: stephaneleonel [mailto:[hidden email]]
Sent: August-27-17 8:12 AM
To: [hidden email]
Subject: [platform-dev] Automatic expand all nodes of BeanTreeView when explorer is opened for the first time

Hello Community,

We are building a school management app that will be soon released as free an open source in netbeans platform portal.

The application contains an explorer which load data from database and displays a tree at startup :
[Image: https://forums.netbeans.org/files/capture1_813.png ]

But, at startup, only the root is displayed as you can see in the image above.

We want to expand automatically all nodes at startup, like this :

[Image: https://forums.netbeans.org/files/capture2_441.png ]

How can we do that ?

Note that childs are asynchronously built.




Attachments:
http://forums.netbeans.org//files/capture2_441.png
http://forums.netbeans.org//files/capture1_813.png

Reply | Threaded
Open this post in threaded view
|

Re: Automatic expand all nodes of BeanTreeView when explorer is opened for the first time

Dmitry Avtonomov
If your view doesn't have this method, then you could use something like this (this code expands only the first level of children, modify to your liking to expand arbitrarily deep into the tree, however, depending on the tree, this might be expensive):


    final Runnable runNodeExpansion = new Runnable() {
            @Override
            public void run() {
                Node toExpand = root;
                Node prevNode = toExpand;
                boolean foundChildren, nodesEqual;
                do {
                    ov.expandNode(toExpand);
                    Node[] nodes = toExpand.getChildren().getNodes(true);
                    foundChildren = false;
                    nodesEqual = false;
                    if (nodes != null && nodes.length > 0) {
                        for (int i = 0; i < nodes.length; i++) {
                            Node n = nodes[i];
                            Node[] childNodes = n.getChildren().getNodes(true);
                            if (childNodes != null && childNodes.length > 0) {
                                foundChildren = true;
                                toExpand = n;
                                nodesEqual = toExpand.equals(prevNode);
                                prevNode = toExpand;
                                break;
                            }
                        }
                    }

                } while (foundChildren && !nodesEqual);
            }
        };
        WindowManager.getDefault().invokeWhenUIReady(runNodeExpansion);


Best,
Dmitry 


On Sun, Aug 27, 2017 at 5:14 PM, stephen cumminger <[hidden email]> wrote:
BeanTreeView.expandAll();


Steve

-----Original Message-----
From: stephaneleonel [mailto:[hidden email]]
Sent: August-27-17 8:12 AM
To: [hidden email]
Subject: [platform-dev] Automatic expand all nodes of BeanTreeView when explorer is opened for the first time

Hello Community,

We are building a school management app that will be soon released as free an open source in netbeans platform portal.

The application contains an explorer which load data from database and displays a tree at startup :
[Image: https://forums.netbeans.org/files/capture1_813.png ]

But, at startup, only the root is displayed as you can see in the image above.

We want to expand automatically all nodes at startup, like this :

[Image: https://forums.netbeans.org/files/capture2_441.png ]

How can we do that ?

Note that childs are asynchronously built.




Attachments:
http://forums.netbeans.org//files/capture2_441.png
http://forums.netbeans.org//files/capture1_813.png