How to tell what nodes in a tree have been selected?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to tell what nodes in a tree have been selected?

NelsonAz
Hello,

I've been trying to implement a tree for a few days, but have been unable to figure out how to tell what nodes of a tree have been selected by a user.

I've constructed a tree in the following manner:

=================================================================
=================================================================

var testTree = new qx.ui.tree.Tree();

var testRoot = new qx.ui.tree.TreeFolder("Root");

var testRootCheckBox = new qx.ui.form.CheckBox();
                       
testRoot.addWidget(testRootCheckBox);

testRoot.addWidget(new qx.ui.core.Spacer(4, 4));

testRoot.addLabel("My Root");

testTree.setRoot(testRoot);

testRoot.setOpen(true);

testTree.setSelectionMode("multi");

var test0 = new qx.ui.tree.TreeFolder();
var test1 = new qx.ui.tree.TreeFile();
var test2 = new qx.ui.tree.TreeFile();

var test0CheckBox = new qx.ui.form.CheckBox();
var test1CheckBox = new qx.ui.form.CheckBox();
var test2CheckBox = new qx.ui.form.CheckBox();

test0.addWidget(test0CheckBox);
test1.addWidget(test1CheckBox);
test2.addWidget(test2CheckBox);
                       
test0.addWidget(new qx.ui.core.Spacer(4, 4));
test1.addWidget(new qx.ui.core.Spacer(4, 4));
test2.addWidget(new qx.ui.core.Spacer(4, 4));
                       
test0.addLabel("Folder");
test1.addLabel("File 1");
test2.addLabel("File 2");

test0.add(test1, test2);

testRoot.add(test0);

testTree.addListener("changeSelection", function(e)
{
        //This code is most likely wrong//////////////////////////////////////////////////////////////////////////
        var selections = e.getData();

        for (selection in selections)
       {
              //Do something
       }
});

=================================================================
=================================================================

Any attempt at analyzing what node has been selected (via its label) or whether a check box has been checked, has been met with a run time error which leads to the tree freezing up (preventing the user from making any further selections after their initial selection).

Question 1: How would I traverse the tree to see what nodes were selected?

Question 2: How would I read / output the label of each selected node?

Question 3: How would I read / output whether a check box was checked or not?

Note: I made sure to look at various tree examples in the Demo Browser and also searched through various forum posts regarding trees, with no luck.

Any help would be greatly appreciated.

Thank you,
Nelson
Reply | Threaded
Open this post in threaded view
|

Re: How to tell what nodes in a tree have been selected?

N. Schröder
Hello Nelson,

I have created a little demo (based on your source code) showing how to iterate an array of selected tree nodes: http://tinyurl.com/nrssqw5

The example should, hopefully, answer the questions you asked below. One additional point regarding your first question: You shouldn't use "for ... in" loops with arrays in JavaScript (http://stackoverflow.com/questions/500504/why-is-using-for-in-with-array-iteration-such-a-bad-idea).

Cheers,

  Norbert


NelsonAz schrieb am 07.10.2015 19:00:

> [...]
>
> Question 1: How would I traverse the tree to see what nodes were selected?
>
> Question 2: How would I read / output the label of each selected node?
>
> Question 3: How would I read / output whether a check box was checked or
> not?
>


------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: How to tell what nodes in a tree have been selected?

NelsonAz
Hello Norbert,

Thank you very much for all your help.

Also, thank you for all your work on the revised Dark Theme.

Out of all the available themes, Dark Theme has been the most visually pleasing / functional theme I've seen thus far.

Nelson
Reply | Threaded
Open this post in threaded view
|

Re: How to tell what nodes in a tree have been selected?

N. Schröder
You're welcome - and thank you, too :-)

Norbert


NelsonAz schrieb am 08.10.2015 17:15:

> Hello Norbert,
>
> Thank you very much for all your help.
>
> Also, thank you for all your work on the revised Dark Theme.
>
> Out of all the available themes, Dark Theme has been the most visually
> pleasing / functional theme I've seen thus far.
>
> Nelson
>
>
>
> --
> View this message in context:
> http://qooxdoo.678.n2.nabble.com/How-to-tell-what-nodes-in-a-tree-have-been-selected-tp7587659p7587665.html
> Sent from the qooxdoo mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>


------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel