Re: Automatic expand all nodes of BeanTreeView when explorer is opened for the first time
Dmitry Avtonomov <[email protected]> Sun, 27 Aug 2017 23:53:44 -0700
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <CAMMjtf8Sh5uK32tZX5xk7ZP5sSMP2qRwLBFzCnbtXGZVpekB0w@mail.gmail.com> |
--94eb2c0d293eb5b9d30557cac230
Content-Type: text/plain; charset="UTF-8"
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 <
[email protected]> wrote:
> BeanTreeView.expandAll();
>
>
> Steve
>
> -----Original Message-----
> From: stephaneleonel [mailto:[email protected]]
> Sent: August-27-17 8:12 AM
> To: [email protected]
> 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
>
>
--94eb2c0d293eb5b9d30557cac230
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:arial,he=
lvetica,sans-serif">If your view doesn't have this method, then you cou=
ld use something like this (this code expands only the first level of child=
ren, modify to your liking to expand arbitrarily deep into the tree, howeve=
r, depending on the tree, this might be expensive):</div><div class=3D"gmai=
l_default" style=3D"font-family:arial,helvetica,sans-serif"><br></div><div =
class=3D"gmail_default" style=3D"font-family:arial,helvetica,sans-serif"><b=
r></div><div class=3D"gmail_default"><div class=3D"gmail_default"><font fac=
e=3D"arial, helvetica, sans-serif">=C2=A0 =C2=A0 final Runnable runNodeExpa=
nsion =3D new Runnable() {</font></div><div class=3D"gmail_default"><font f=
ace=3D"arial, helvetica, sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 @Override</font></div><div class=3D"gmail_default"><font face=3D"arial,=
helvetica, sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 public vo=
id run() {</font></div><div class=3D"gmail_default"><font face=3D"arial, he=
lvetica, sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 Node toExpand =3D root;</font></div><div class=3D"gmail_default"><font =
face=3D"arial, helvetica, sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 Node prevNode =3D toExpand;</font></div><div class=3D"=
gmail_default"><font face=3D"arial, helvetica, sans-serif">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 boolean foundChildren, nodesEqual=
;</font></div><div class=3D"gmail_default"><font face=3D"arial, helvetica, =
sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 do {</f=
ont></div><div class=3D"gmail_default"><font face=3D"arial, helvetica, sans=
-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 ov.expandNode(toExpand);</font></div><div class=3D"gmail_default"><font=
face=3D"arial, helvetica, sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Node[] nodes =3D toExpand.getChildren().=
getNodes(true);</font></div><div class=3D"gmail_default"><font face=3D"aria=
l, helvetica, sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 foundChildren =3D false;</font></div><div class=3D"gma=
il_default"><font face=3D"arial, helvetica, sans-serif">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 nodesEqual =3D false;<=
/font></div><div class=3D"gmail_default"><font face=3D"arial, helvetica, sa=
ns-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 if (nodes !=3D null && nodes.length > 0) {</font></div><d=
iv class=3D"gmail_default"><font face=3D"arial, helvetica, sans-serif">=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 for (int i =3D 0; i < nodes.length; i++) {</font></div><div class=
=3D"gmail_default"><font face=3D"arial, helvetica, sans-serif">=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 Node n =3D nodes[i];</font></div><div class=3D"gmail_default"=
><font face=3D"arial, helvetica, sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Node[=
] childNodes =3D n.getChildren().getNodes(true);</font></div><div class=3D"=
gmail_default"><font face=3D"arial, helvetica, sans-serif">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 if (childNodes !=3D null && childNodes.length > 0) {<=
/font></div><div class=3D"gmail_default"><font face=3D"arial, helvetica, sa=
ns-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 foundChildren =3D true;</f=
ont></div><div class=3D"gmail_default"><font face=3D"arial, helvetica, sans=
-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 toExpand =3D n;</font></div><=
div class=3D"gmail_default"><font face=3D"arial, helvetica, sans-serif">=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 nodesEqual =3D toExpand.equals(prevNode)=
;</font></div><div class=3D"gmail_default"><font face=3D"arial, helvetica, =
sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 prevNode =3D toExpand;</fo=
nt></div><div class=3D"gmail_default"><font face=3D"arial, helvetica, sans-=
serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break;</font></div><div class=
=3D"gmail_default"><font face=3D"arial, helvetica, sans-serif">=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 }</font></div><div class=3D"gmail_default"><font face=3D"aria=
l, helvetica, sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }</font></div><div class=3D"gmail_defaul=
t"><font face=3D"arial, helvetica, sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }</font></div><div class=3D"gmail=
_default"><font face=3D"arial, helvetica, sans-serif"><br></font></div><div=
class=3D"gmail_default"><font face=3D"arial, helvetica, sans-serif">=C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } while (foundChildren &a=
mp;& !nodesEqual);</font></div><div class=3D"gmail_default"><font face=
=3D"arial, helvetica, sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
}</font></div><div class=3D"gmail_default"><font face=3D"arial, helvetica,=
sans-serif">=C2=A0 =C2=A0 =C2=A0 =C2=A0 };</font></div><div class=3D"gmail=
_default"><font face=3D"arial, helvetica, sans-serif">=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 WindowManager.getDefault().invokeWhenUIReady(runNodeExpansion);</fon=
t></div><div class=3D"gmail_default"><font face=3D"arial, helvetica, sans-s=
erif"><br></font></div><div class=3D"gmail_default"><font face=3D"arial, he=
lvetica, sans-serif"><br></font></div><div class=3D"gmail_default"><font fa=
ce=3D"arial, helvetica, sans-serif">Best,</font></div><div class=3D"gmail_d=
efault"><font face=3D"arial, helvetica, sans-serif">Dmitry=C2=A0</font></di=
v><div class=3D"gmail_default"><font face=3D"arial, helvetica, sans-serif">=
<br></font></div></div></div><div class=3D"gmail_extra"><br><div class=3D"g=
mail_quote">On Sun, Aug 27, 2017 at 5:14 PM, stephen cumminger <span dir=3D=
"ltr"><<a href=3D"mailto:[email protected]" target=3D"_blan=
k">[email protected]</a>></span> wrote:<br><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pad=
ding-left:1ex">BeanTreeView.expandAll();<br>
<br>
<br>
Steve<br>
<br>
-----Original Message-----<br>
From: stephaneleonel [mailto:<a href=3D"mailto:[email protected]">st=
ephaneleonel@yahoo.<wbr>com</a>]<br>
Sent: August-27-17 8:12 AM<br>
To: <a href=3D"mailto:[email protected]">[email protected]<=
/a><br>
Subject: [platform-dev] Automatic expand all nodes of BeanTreeView when exp=
lorer is opened for the first time<br>
<br>
Hello Community,<br>
<br>
We are building a school management app that will be soon released as free =
an open source in netbeans platform portal.<br>
<br>
The application contains an explorer which load data from database and disp=
lays a tree at startup :<br>
[Image: <a href=3D"https://forums.netbeans.org/files/capture1_813.png" rel=
=3D"noreferrer" target=3D"_blank">https://forums.netbeans.org/<wbr>files/ca=
pture1_813.png</a> ]<br>
<br>
But, at startup, only the root is displayed as you can see in the image abo=
ve.<br>
<br>
We want to expand automatically all nodes at startup, like this :<br>
<br>
[Image: <a href=3D"https://forums.netbeans.org/files/capture2_441.png" rel=
=3D"noreferrer" target=3D"_blank">https://forums.netbeans.org/<wbr>files/ca=
pture2_441.png</a> ]<br>
<br>
How can we do that ?<br>
<br>
Note that childs are asynchronously built.<br>
<br>
<br>
<br>
<br>
Attachments:<br>
<a href=3D"http://forums.netbeans.org//files/capture2_441.png" rel=3D"noref=
errer" target=3D"_blank">http://forums.netbeans.org//<wbr>files/capture2_44=
1.png</a><br>
<a href=3D"http://forums.netbeans.org//files/capture1_813.png" rel=3D"noref=
errer" target=3D"_blank">http://forums.netbeans.org//<wbr>files/capture1_81=
3.png</a><br>
<br>
</blockquote></div><br></div>
--94eb2c0d293eb5b9d30557cac230--