Working with the underlying array

Discussion and support relating to Data Tree

Moderators: worcestersource, heatherlaine

Post Reply
malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Working with the underlying array

Post by malte » Wed Mar 31, 2010 8:18 am

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

ibe
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 61
Joined: Sun Oct 04, 2009 12:15 pm

Re: Working with the underlying array

Post by ibe » Wed Mar 31, 2010 3:16 pm

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

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: Working with the underlying array

Post by malte » Wed Mar 31, 2010 3:48 pm

Thanks ismo!

Helps a lot.

worcestersource
Posts: 24
Joined: Wed Mar 17, 2010 3:51 pm
Location: Worcester, UK
Contact:

Re: Working with the underlying array

Post by worcestersource » Wed Mar 31, 2010 10:08 pm

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

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: Working with the underlying array

Post by malte » Thu Apr 01, 2010 8:28 am

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

worcestersource
Posts: 24
Joined: Wed Mar 17, 2010 3:51 pm
Location: Worcester, UK
Contact:

Re: Working with the underlying array

Post by worcestersource » Thu Apr 01, 2010 9:33 pm

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

Post Reply

Return to “Data Tree”