How do I tick a checkboxtree from within an application

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.

How do I tick a checkboxtree from within an application

Postby neverton » Sat Jul 24, 2010 2:48 pm

Hi,
I've probably looked at the answer several times, but it's been a long day and my brain is starting to bubble out of my ears now :shock:

I've just started using the JIDE community library today, after having tried the Ansir tristate library for an application, but the Ansir has too many 'quirks' that I can't use it within my application.

I've converted my Jtree to use the CheckBoxTree from within the JIDE libraries and the Jtree is displaying as expected, the only thing I cannot see if how I 'tick' a node as I build the tree? I keep a seperate Hashmap of values so I can track which items have been selected on the tree (basically they're all set to not ticked and when I select save it does a;

TreePath[] treePaths = checkboxTree.getCheckBoxTreeSelectionModel().getSelectionPaths();

and for all the matches it sets the HashMap corresponding values to ticked.

So all I want to do, is as I am building the JTree when a user goes back onto the pane, is be able to 'tick' certain nodes if they where selected previously. In the Ansir library I simply did;

DefaultMutableTreeNode node = new DefaultMutableTreeNode(description);
node.setState(Tristate.SELECTED);

for every node I wanted ticked.

Is there something similar in the JIDE to perform the same thing? as it's a very useful feature :)

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

Re: How do I tick a checkboxtree from within an application

Postby JIDE Support » Sat Jul 24, 2010 7:23 pm

I am not sure if I understand the question. Can you use checkboxTree.getCheckBoxTreeSelectionModel().addSelectionPath or setSelectionPath to pre-"tick" the check boxes?

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

Re: How do I tick a checkboxtree from within an application

Postby neverton » Sun Jul 25, 2010 1:34 am

Hi,
I basically want to be able to tick specific nodes as I build the checkboxTree.

In my old library I simply did;

DefaultMutableTreeNode node = new DefaultMutableTreeNode(description);
node.setState(Tristate.SELECTED);
rootNode.add(node);

and this added the node to the tree with the checkbox ticked.

I did have a look at addSelectionPath yesterday, but to be honest, my Java skills are not brilliant and I wasn't sure how I got a node converted so it would work with addSelectionPath, as I'm sure addSelectionPath wants a TreePath and my node is DefaultMutableNode.

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

Re: How do I tick a checkboxtree from within an application

Postby neverton » Sun Jul 25, 2010 4:07 am

Hi,
No worries, finally got it sorted, sleep does have its uses!!

I run this loop for each of the nodes under root, then if it passes the tests it uses addSelectionPath as you recommended;

Code: Select all
    e = legalGrpNode.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) {
            Integer checked = Integer.parseInt(consolLegalGrpMap.get(tmpNum).toString());
            if (checked != null && checked > 0) {
                checkboxTree.getCheckBoxTreeSelectionModel().addSelectionPath(path);
            }
        }
    }

public TreePath getPath(TreeNode node) {
    List list = new ArrayList();
// Add all nodes to list
    while (node != null) {
        list.add(node);
        node = node.getParent();
    }
    Collections.reverse(list);
// Convert array of nodes to TreePath
    return new TreePath(list.toArray());
}




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


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

Who is online

Users browsing this forum: No registered users and 61 guests