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)

import javax.swing.tree.*;

static <A, B extends Collection<A>> JTree jDynamicTree_concurrent(final A root, final F1<A, B> makeChildren, fO... optParams) {
  ret swing(func -> JTree {
    final Q queue = startQ();
    DefaultMutableTreeNode rootNode = new(root);
    rootNode.add(new DefaultMutableTreeNode(jDynamicTree_dummy()));
    final JTree tree = new JTree(rootNode);
    tree.setShowsRootHandles(true);
    tree.collapseRow(0);
    final bool keepChildrenOnCollapse = optParam(optParams, 'keepChildrenOnCollapse, false);
    //final bool makeChildrenIsFast = optParam(optParams, 'makeChildrenIsFast, false);
    final bool debug = boolPar debug(optParams, true);
    
    tree.addTreeWillExpandListener(new TreeWillExpandListener {
      public void treeWillCollapse(TreeExpansionEvent e) {}
      public void treeWillExpand(TreeExpansionEvent e) {
        if (debug) print("treeWillExpand");
        final DefaultMutableTreeNode node = cast e.getPath().getLastPathComponent();
        if (keepChildrenOnCollapse && !jDynamicTree_isInDummyState(node)) ret;
        
        queue.add(r {
          print("Calling: " + makeChildren);
          B raw = callF(makeChildren, (A) node.getUserObject());
          print("raw => " + className(raw));
          fL<A> l = asList(raw);
          if (debug) print("Have children: " + l(l));
          swing {
            if (replaceTreeNodeChildren_withDummyChild(node, l, jDynamicTree_dummy()))
              ((DefaultTreeModel) tree.getModel()).nodeStructureChanged(node);
          }
        });
      }
    });
    
    ret tree;
  });
}

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: 313 / 321
Version history: 8 change(s)
Referenced in: [show references]