Slow selection of node,can I make it quicker?

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Slow selection of node,can I make it quicker?

Postby neverton » Mon Aug 16, 2010 7:56 am

Hi,
I've created an application in Java, and the selecting of node's is very very slow when there are thousands of nodes that need to be ticked. I guess I'm not doing it the correct way, so I thought I would post on here and see if people have a better solution.

Basically, I have used the JIDE community library and I create a treemodel and add each node in turn as I read through a database of accounts, manufacturers, products, etc. with each table (accounts, manufacturers, products) displayed under their respective parent node. This all works fine and although a little slow, it's fast enough for the needs. This is built by doing the following;

Code: Select all
accountNode.removeAllChildren();
productNode.removeAllChilder();
rootNode.removeAllChildren();

rootNode.add(accountNode);
rootNode.add(productNode);

ResetSet rs = select code,description from products;
while (rs.next()) {
  number = rs.getString("code");
  name = rs.getString("description");

  if (search == true) { // If I'm looking for a specific product
    if (name.toString().toLowerCase().contains(tmpSearch.toLowerCase())) {
      DefaultMutableTreeNode node = new DefaultMutableTreeNode(description);
      productsNode.add( node);
  }
  else {
      DefaultMutableTreeNode node = new DefaultMutableTreeNode(description);
      productsNode.add( node);
  }
}


This works fine and builds my tree with all the correct data.

I also have a Map of any products selected, which is built from the listener and is also working fine, its just a list of the product codes and I add or remove products based on the listener events.

Now, I haven't found a way to add a tick at the time of building the tree (the above code), so what I am currently doing is, once the above has run I am doing;

Code: Select all
    treeModel = new DefaultTreeModel(rootNode);
    checkboxTree.setModel(treeModel);
    checkboxTree.setRootVisible(true);
    checkboxTree.getCheckBoxTreeSelectionModel().setDigIn(true);


and then I run a routine called populateCheckBoxes, which does this;

Code: Select all
   
    e = productsNode.preorderEnumeration();

    while(e.hasMoreElements()){
        DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) e.nextElement();
        TreeNode [] ptr = dmtn.getPath();
        TreePath path = new TreePath(ptr);

        tmpNum = Utils.getBracketedNumber(path.toString());

        if (tmpNum >= 0) {
            if (consolProductsMap.containsKey(tmpNum)) {
               checkboxTree.getCheckBoxTreeSelectionModel().addSelectionPath(path);
            }
        }
    }


This final bit of code is really slow, taking up to 6 minutes if there are over 8000 products to be selected.

This is the bit I need help with, is there a way to actually set the node as selected while I am building the nodes (the first bit of code), or is it better to build an array of TreePaths and use setSelectionPaths to set the whole list of selected paths, or am I doing this completely wrong and should be doing this another way?

Any help, pointers or comments (pref. constructive) are welcome :)

Thanks
neverton
 
Posts: 4
Joined: Fri Jul 16, 2010 4:36 am

Re: Slow selection of node,can I make it quicker?

Postby JIDE Support » Mon Aug 16, 2010 9:22 am

Please update to the latest release if you are on a older release. We did improve performance at this part since 2.9.0. Please also try to create an array and add them in a batch using addSelectionPaths(). It will also improve the performance. If not, a profilter image to show the hot spot would be appreciated for us to investigate further.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Slow selection of node,can I make it quicker?

Postby Walter Laan » Tue Aug 17, 2010 1:01 am

Building up a list of TreePaths first then calling addSelectionPaths() once might be faster as less events should be generated.

Since you use digIn, you could also skip all children if you select a parent path.
Walter Laan
 
Posts: 383
Joined: Mon May 01, 2006 12:13 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 48 guests