Page 1 of 1

Working with the underlying array

Posted: Wed Mar 31, 2010 8:18 am
by malte
Hi,

first of all congrats on a very nice product. Could you give an example on how to build a tree from the array? I would like to create it from scratch, fetching data from a database. A Demo tree could look like this

Code: Select all

root1
-test1
--test1a
--test1b
-test2
--test2a
root2
-test3
--test3a
---test3a1
How would the array need to look like and what would I need to do to construct the nodes?

Thanks,

Malte

Re: Working with the underlying array

Posted: Wed Mar 31, 2010 3:16 pm
by ibe
Hi Malte, I'm not Steve but to make such a tree by scipt you could do something like this:

Code: Select all

on mouseUp
   local tNodeDataArray
 
   set the dt_general["root nodes"] of group "datatree" to "R1,R2"
   
   put "root1" into tNodeDataArray["R1"]["label"]
   put true into tNodeDataArray["R1"]["expand"]
   put "T1,T2" into tNodeDataArray["R1"]["owns"]
   
   put "test1" into tNodeDataArray["T1"]["label"]
   put true into tNodeDataArray["T1"]["expand"]
   put "T1A,T1B" into tNodeDataArray["T1"]["owns"]
   
   put "test1" into tNodeDataArray["T1"]["label"]
   put true into tNodeDataArray["T1"]["expand"]
   put "T1A,T1B" into tNodeDataArray["T1"]["owns"]
   
   put "test1a" into tNodeDataArray["T1A"]["label"]
   put "test1b" into tNodeDataArray["T1B"]["label"]
   
   put "test2" into tNodeDataArray["T2"]["label"]
   put true into tNodeDataArray["T2"]["expand"]
   put "T2A" into tNodeDataArray["T2"]["owns"]
   
   put "test2a" into tNodeDataArray["T2A"]["label"]
   
   put "root2" into tNodeDataArray["R2"]["label"]
   put true into tNodeDataArray["R2"]["expand"]
   put "T3" into tNodeDataArray["R2"]["owns"]
   
   put "test3" into tNodeDataArray["T3"]["label"]
   put true into tNodeDataArray["T3"]["expand"]
   put "T3A" into tNodeDataArray["T3"]["owns"]
   
   put "test3a" into tNodeDataArray["T3A"]["label"]
   put true into tNodeDataArray["T3"]["expand"]
   put "T3A1" into tNodeDataArray["T3"]["owns"]
   
   put "test3a1" into tNodeDataArray["T3A1"]["label"]
   
   set the dt_general["node data"] of group "datatree" to tNodeDataArray
   set the dt_general["active node ID"] of group "datatree" to "R1"
   
   lock screen
   dt_paint (id of group "datatree")
   unlock screen
end mouseUp
Of course when reading from a database you woud just loop these commands to fill the array. Hope this helps.

-- ismo

Re: Working with the underlying array

Posted: Wed Mar 31, 2010 3:48 pm
by malte
Thanks ismo!

Helps a lot.

Re: Working with the underlying array

Posted: Wed Mar 31, 2010 10:08 pm
by worcestersource
Hi Malte, hi Ismo!

First up, thanks Malte for the kind words and thanks also to Ismo for answering Malte's question for me!

The only thing I could add is that you'd also use the same approach to fill out the other properties of the nodes, such as icons etc.

For example, adding the line:

Code: Select all

put "1144" into tNodeDataArray["R1"]["icon"]
would use an image with an id of 1144 as the icon of the first root node.

Any more questions then post away!

Cheers,


Steve
http://www.theworcestersource.com

Re: Working with the underlying array

Posted: Thu Apr 01, 2010 8:28 am
by malte
Is there a list of all properties you can set? THough I love your demo stacks, sometimes a list that I just could print out might be handy.

Cheers,

Malte

Re: Working with the underlying array

Posted: Thu Apr 01, 2010 9:33 pm
by worcestersource
Nice idea about the printable list... think I'll conjure that one up sometime soon. Another for all the commands, functions and messages should also be handy.

There's a section in the Manual called 'Node Properties', which contains a page per property.

I'll list them here with a few comments for reference, default values in brackets:

label
icon - the id of an image to be used as the node's icon
owns - a comma separated list of other node ids to be the children of this node (empty)
expand - true/false/empty although bear in mind that a root node will always display children when 'expand' is empty (empty)
command - contents of this node are passed when events are fired, to help you determine the kind of node interacted with (empty)
root style - root nodes with this property are given a special look, Mac OS X only (false)
indent - the number entered overrides the automatic indentation (empty)
accepts highlight - true/false when false, node does not highlight when clicked on (true)
direct click - true/false when true, node highlights on mouseDown... note no nodeUp message is sent (false)

Steve