Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

38
LINES

< > BotCompany Repo | #1021591 // jDynamicTree_concurrent - calculates children in background queue [dev.]

JavaX fragment (include)

1  
import javax.swing.tree.*;
2  
3  
static <A, B extends Collection<A>> JTree jDynamicTree_concurrent(final A root, final F1<A, B> makeChildren, fO... optParams) {
4  
  ret swing(func -> JTree {
5  
    final Q queue = startQ();
6  
    DefaultMutableTreeNode rootNode = new(root);
7  
    rootNode.add(new DefaultMutableTreeNode(jDynamicTree_dummy()));
8  
    final JTree tree = new JTree(rootNode);
9  
    tree.setShowsRootHandles(true);
10  
    tree.collapseRow(0);
11  
    final bool keepChildrenOnCollapse = optParam(optParams, 'keepChildrenOnCollapse, false);
12  
    //final bool makeChildrenIsFast = optParam(optParams, 'makeChildrenIsFast, false);
13  
    final bool debug = boolPar debug(optParams, true);
14  
    
15  
    tree.addTreeWillExpandListener(new TreeWillExpandListener {
16  
      public void treeWillCollapse(TreeExpansionEvent e) {}
17  
      public void treeWillExpand(TreeExpansionEvent e) {
18  
        if (debug) print("treeWillExpand");
19  
        final DefaultMutableTreeNode node = cast e.getPath().getLastPathComponent();
20  
        if (keepChildrenOnCollapse && !jDynamicTree_isInDummyState(node)) ret;
21  
        
22  
        queue.add(r {
23  
          print("Calling: " + makeChildren);
24  
          B raw = callF(makeChildren, (A) node.getUserObject());
25  
          print("raw => " + className(raw));
26  
          fL<A> l = asList(raw);
27  
          if (debug) print("Have children: " + l(l));
28  
          swing {
29  
            if (replaceTreeNodeChildren_withDummyChild(node, l, jDynamicTree_dummy()))
30  
              ((DefaultTreeModel) tree.getModel()).nodeStructureChanged(node);
31  
          }
32  
        });
33  
      }
34  
    });
35  
    
36  
    ret tree;
37  
  });
38  
}

Author comment

Began life as a copy of #1016044

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1021591
Snippet name: jDynamicTree_concurrent - calculates children in background queue [dev.]
Eternal ID of this version: #1021591/9
Text MD5: 93a27d7e8824469e7986b56cf847ef59
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-02-19 17:08:33
Source code size: 1625 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 315 / 324
Version history: 8 change(s)
Referenced in: [show references]