9 Replies Latest reply: Aug 26, 2011 12:11 PM by DarrylBurke RSS

    J/X/Tree: expanding all nodes on a large tree on/off EDT?

    Kleopatra
      recently I was remembered of a long-standing task in SwingX, which is to support expanding all nodes of a JXTree .. for large trees.

      http://java.net/jira/browse/SWINGX-1442

      JXTree has api to do so, with a naive implemenation which simply loops through all rows until the end. That's good enough for smaller trees, but not for larger, can take minutes and is blocking the EDT.

      Simple way is to tell the developer it's no good for larger trees, "your job to do it somehow in the background" --- thinking about it, I couldn't come up with any idea about the how-to: expanding is all ui-related touching several view-related classes including the tree itself during expansion, so looks like it has to happen on the EDT. Being so, the next option might be some way to partion the expansion into smaller chunks, each being so small that the effective blocking wouldn't be noticeable with some prioritizing such that the visible part of the tree always is expanded. Sounds like quite a task ..

      On the other hand, maybe an ui which allows expanding 100k of nodes at once isn't optimal anyway - considering the time it would take the user to browse 100k nodes .. if so, SwingX could lean back and do nothing, happy option :-)

      Opinions, ideas, references to existing code or discussions highly welcome!

      Thanks
      Jeanette

      Edited by: Kleopatra on Aug 24, 2011 2:47 PM

      cross-posted to swinglabs forum: http://www.java.net/forum/topic/javadesktop/java-desktop-technologies/swinglabs/jxtree-expanding-all-nodes-large-tree-onoff-edt
        • 1. Re: J/X/Tree: expanding all nodes on a large tree on/off EDT?
          StanislavL
          What if you open several first visible rows (just to fill view rect of your JScrollPane) and then start a thread which sleeps for e.g. 0.5 sec and then expand 10 more rows and again sleeps till all will be expanded?
          • 2. Re: J/X/Tree: expanding all nodes on a large tree on/off EDT?
            Kleopatra
            Stan,

            yeah, had been thinking about something like that (that's what I meant - nebulously - with "chunks") though would expect real work along those lines because it must be able to react to user interactions, like scrolling by any amount ... seen any code doing it?

            Thanks
            Jeanette
            • 3. Re: J/X/Tree: expanding all nodes on a large tree on/off EDT?
              DarrylBurke
              Just a thought, based on some long-ago, days-of-slow-computers experience in repopulating not-all-that-large ActiveX tree and list comtrols in VFP.

              Is the process of expanding the nodes considerably speeded up if the tree is <tt>setVisible(false)</tt> before expanding the nodes and <tt>setVisible(true)</tt> on completion of the expanding?

              db
              • 4. Re: J/X/Tree: expanding all nodes on a large tree on/off EDT?
                jduprez
                yeah, had been thinking about something like that (that's what I meant - nebulously - with "chunks") though would expect real work along those lines because it must be able to react to user interactions, like scrolling by any amount ... seen any code doing it?
                Where is the bottleneck in your experiments? Is it the traversal of the tree model, or the repetitive UI calls (such as, expandPath/expandRow)?
                I assume if the traversal itself is "fast enough", the task seems rather simple, at least for fixed-rowheight trees, so let's say the traversal is slow.
                Then do it in chunks (1) , and let the scrollbar reflects only the known number of rows so far, that shouldn't worry so much the user (indeed that's pretty much what a user would expect, such as the browser's scroll knob changing its relative size as the page loads).

                J.

                (1) With this wording, whichever clever solution you eventually come up with, I can claim precedence :o)
                • 5. Re: J/X/Tree: expanding all nodes on a large tree on/off EDT?
                  StanislavL
                  Let's consider the tree has 1000 nodes, 10 first are visible and 100 are already expanded. User tries to scroll. What should happen? We should show him the 10-20 rows and in the same time we can expand 10 more on each scroll action.

                  The effect will be when user scrolls to borrom height of content is increased and it will look like the scrollbar knob remains.
                  • 6. Re: J/X/Tree: expanding all nodes on a large tree on/off EDT?
                    Kleopatra
                    jduprez wrote:
                    Where is the bottleneck in your experiments? Is it the traversal of the tree model, or the repetitive UI calls (such as, expandPath/expandRow)?
                    Good question - guilty of not having thought of measuring the different aspects separately, in fact not having measured by any means that would stand to the term ;-)

                    Looks like traversal depends on the model implementation, mostly lightning fast but could slow down to a crawl for some. Needs further investigation.
                    I assume if the traversal itself is "fast enough", the task seems rather simple, at least for fixed-rowheight trees, so let's say the traversal is slow.
                    hey, cool - so SwingX may look forward to a code contribution :-)
                    and let the scrollbar reflects only the known number of rows so far, that shouldn't worry so much the user (indeed that's pretty much what a user would expect, such as the browser's scroll knob changing its relative size as the page loads).
                    Thumb size is yet another point I didn't yet think of, good point.

                    >
                    (1) With this wording, whichever clever solution you eventually come up with, I can claim precedence :o)
                    LOL

                    Thanks
                    Jeanette
                    • 7. Re: J/X/Tree: expanding all nodes on a large tree on/off EDT?
                      Kleopatra
                      Just checked: visible or not, doesn't make a difference - good idea, though :-)

                      looks like it's not the painting as such but the notification running back and forth between the tree and the ui. (mostly guessing, it's untrue until measured, hach)

                      Cheers
                      Jeanette
                      • 8. Re: J/X/Tree: expanding all nodes on a large tree on/off EDT?
                        Kleopatra
                        just in case, anybody is interested and wants to watch: opened an issue in the swingx jira

                        http://java.net/jira/browse/SWINGX-1467

                        Cheers
                        Jeanette
                        • 9. Re: J/X/Tree: expanding all nodes on a large tree on/off EDT?
                          DarrylBurke
                          Kleopatra wrote:
                          Just checked: visible or not, doesn't make a difference - good idea, though :-)

                          looks like it's not the painting as such but the notification running back and forth between the tree and the ui. (mostly guessing, it's untrue until measured, hach)

                          Cheers
                          Jeanette
                          Ah, ok. In VFP, setting an ActiveX ListView / TreeView invisible while reloading its data had given me a MAJOR speedup.

                          db