From: Slobodan Blazeski
Subject: How to map tree on a data structure
Date: 
Message-ID: <256fd0f4-b94f-4ac2-9111-6f841d9d3d40@b40g2000prf.googlegroups.com>
I want to create treeview  widget something like
http://www.filebuzz.com/software_screenshot/full/23223-extended_treeview.gif
or
http://developer.emc.com/developer/obt/images/browser_tree.jpg  or
http://www.informationbuilders.com/new/newsletter/6-3/images/sitt1.jpg
The question is how to map the data from tree to hold the current
state .
The only thing that comes into my mind is   atom for the leaves and
list with a marker that shows up is the current node open or closed.
(root  (node1 open (leaf leaf (node11 closed leaf)))
          (node2 closed (node21 open leaf)
          leaf
         ....

thanks
Slobodan

From: Alessio
Subject: Re: How to map tree on a data structure
Date: 
Message-ID: <c90d278a-e101-4259-8f24-b6cb5b8731f5@a35g2000prf.googlegroups.com>
You could also use a structure, or class, representing nodes. Each
instance would contain references to its children, so you could build
a hierarchy. I'd say it depends on your personal preference & on the
kind of things you want to do with it, imho using classes it would be
more easily extensible (e.g. later adding slots with additional
information, such as icon, colour, etc.), probably at the cost of some
extra memory usage...

cheers
Alessio Stalla

On Dec 14, 4:19 pm, Slobodan Blazeski <·················@gmail.com>
wrote:
> I want to create treeview  widget something likehttp://www.filebuzz.com/software_screenshot/full/23223-extended_treev...
> orhttp://developer.emc.com/developer/obt/images/browser_tree.jpg orhttp://www.informationbuilders.com/new/newsletter/6-3/images/sitt1.jpg
> The question is how to map the data from tree to hold the current
> state .
> The only thing that comes into my mind is   atom for the leaves and
> list with a marker that shows up is the current node open or closed.
> (root  (node1 open (leaf leaf (node11 closed leaf)))
>           (node2 closed (node21 open leaf)
>           leaf
>          ....
>
> thanks
> Slobodan
From: Slobodan Blazeski
Subject: Re: How to map tree on a data structure
Date: 
Message-ID: <605572e7-9e6d-42e0-881a-29e6ffdab143@d21g2000prf.googlegroups.com>
On Dec 14, 5:09 pm, Alessio <·············@gmail.com> wrote:
> You could also use a structure, or class, representing nodes. Each
> instance would contain references to its children, so you could build
> a hierarchy. I'd say it depends on your personal preference & on the
> kind of things you want to do with it,imho using classes it would be
> more easily extensible (e.g. later adding slots with additional
> information, such as icon, colour, etc.), probably at the cost of some
> extra memory usage...
>
> cheers
> Alessio Stalla

I'm more concerned about the container structure that holds the nodes,
the nodes themselves could be anything, struct, class, string  depends
of data needed. I just want to get rid of that ugly marker. So if you
have some code or pseudo-code in mind, please share it.

Wait maybe if I write a class  containing below slots (among the
others needed)
a expanded (boolean t if node is expanded) and
b leafs    (list of child nodes, being null if it's a leaf node)
then I could keep my tree view in a simple list.
Thanks Alessio you're a genious  :)

cheers
Slobodan
From: Alessio
Subject: Re: How to map tree on a data structure
Date: 
Message-ID: <3090840a-3207-41ed-a291-c8556a10f280@i72g2000hsd.googlegroups.com>
> then I could keep my tree view in a simple list.

What I was thinking about was not using a list at all, but have a
"root" node containing references to its children, which would hold
references to their children and so on... (and of course additional
information such as expanded-p)... so probably I've not completely
understood what you wanted, but I'm glad I could help you in some way
or another ;)

Alessio Stalla
From: Andreas Thiele
Subject: Re: How to map tree on a data structure
Date: 
Message-ID: <fk34je$cg7$01$1@news.t-online.com>
"Slobodan Blazeski" <·················@gmail.com> schrieb im Newsbeitrag 
·········································@b40g2000prf.googlegroups.com...
>I want to create treeview  widget something like
> http://www.filebuzz.com/software_screenshot/full/23223-extended_treeview.gif
> or
> http://developer.emc.com/developer/obt/images/browser_tree.jpg  or
> http://www.informationbuilders.com/new/newsletter/6-3/images/sitt1.jpg
> The question is how to map the data from tree to hold the current
> state .
> The only thing that comes into my mind is   atom for the leaves and
> list with a marker that shows up is the current node open or closed.
> (root  (node1 open (leaf leaf (node11 closed leaf)))
>          (node2 closed (node21 open leaf)
>          leaf
>         ....
>
> thanks
> Slobodan

I'd allow arbitrary data to be presented, like i.e. LispWorks CAPI graphical UI library does.
Basically you give a list of root nodes to the treeview together with a item-child-function, an
item-get-function, item-count-function and such. These functions can have reasonable
defaults so you can at least pass a list of symbols or strings. With item-get-function and
item-count-function you can pass anything representing the root nodes.

Andreas
From: Slobodan Blazeski
Subject: Re: How to map tree on a data structure
Date: 
Message-ID: <6249ffc0-5b74-4486-95a6-59208a9dd9a7@l1g2000hsa.googlegroups.com>
On Dec 16, 4:10 am, "Andreas Thiele" <······@nospam.com> wrote:
> "Slobodan Blazeski" <·················@gmail.com> schrieb im ····················································@b40g2000prf.googlegroups.com...
>
>
>
> >I want to create treeview  widget something like
> >http://www.filebuzz.com/software_screenshot/full/23223-extended_treev...
> > or
> >http://developer.emc.com/developer/obt/images/browser_tree.jpg or
> >http://www.informationbuilders.com/new/newsletter/6-3/images/sitt1.jpg
> > The question is how to map the data from tree to hold the current
> > state .
> > The only thing that comes into my mind is   atom for the leaves and
> > list with a marker that shows up is the current node open or closed.
> > (root  (node1 open (leaf leaf (node11 closed leaf)))
> >          (node2 closed (node21 open leaf)
> >          leaf
> >         ....
>
> > thanks
> > Slobodan
>
> I'd allow arbitrary data to be presented, like i.e. LispWorks CAPI graphical UI library does.
> Basically you give a list of root nodes to the treeview together with a item-child-function, an
> item-get-function, item-count-function and such. These functions can have reasonable
> defaults so you can at least pass a list of symbols or strings. With item-get-function and
> item-count-function you can pass anything representing the root nodes.
>
> Andreas

I don't understand what are you trying to say. If I define node like
this:
(defstruct node
  (name nil)
  ;other slots you need
  (expanded nil)
  (leafs    nil))

Than i could use a simple recursion render all the leafs with snippet
like this:

(defun render-node (node &optional (i 0)); not tested
  (cond ((null node) nil)
        ((atom node)
         (progn
           (terpri)
           (princ (make-string i :initial-element #\_))
           (princ (node-name node))
           (if (and (node-expanded node)
                    (node-leafs node))
             (render-node (node-leafs node)))))
        (t (or
             (render-node (car node) (1+ i))
             (render-node (cdr node) (1+ i))))))

What are the benefits of your approach and please put some code or
pseudo code?
Efficiency doesn't concern me, as trees should be small.

Slobodan
From: Andreas Thiele
Subject: Re: How to map tree on a data structure
Date: 
Message-ID: <fk6puc$2dl$00$1@news.t-online.com>
"Slobodan Blazeski" <·················@gmail.com> schrieb im Newsbeitrag 
·········································@l1g2000hsa.googlegroups.com...
> On Dec 16, 4:10 am, "Andreas Thiele" <······@nospam.com> wrote:
>> "Slobodan Blazeski" <·················@gmail.com> schrieb im 
>> ····················································@b40g2000prf.googlegroups.com...
>>
>>
>>
>> >I want to create treeview  widget something like
>> >http://www.filebuzz.com/software_screenshot/full/23223-extended_treev...
>> > or
>> >http://developer.emc.com/developer/obt/images/browser_tree.jpg or
>> >http://www.informationbuilders.com/new/newsletter/6-3/images/sitt1.jpg
>> > The question is how to map the data from tree to hold the current
>> > state .
>> > The only thing that comes into my mind is   atom for the leaves and
>> > list with a marker that shows up is the current node open or closed.
>> > (root  (node1 open (leaf leaf (node11 closed leaf)))
>> >          (node2 closed (node21 open leaf)
>> >          leaf
>> >         ....
>>
>> > thanks
>> > Slobodan
>>
>> I'd allow arbitrary data to be presented, like i.e. LispWorks CAPI graphical UI library does.
>> Basically you give a list of root nodes to the treeview together with a item-child-function, an
>> item-get-function, item-count-function and such. These functions can have reasonable
>> defaults so you can at least pass a list of symbols or strings. With item-get-function and
>> item-count-function you can pass anything representing the root nodes.
>>
>> Andreas
>
> I don't understand what are you trying to say. If I define node like
> this:
> (defstruct node
>  (name nil)
>  ;other slots you need
>  (expanded nil)
>  (leafs    nil))
>
> Than i could use a simple recursion render all the leafs with snippet
> like this:
>
> (defun render-node (node &optional (i 0)); not tested
>  (cond ((null node) nil)
>        ((atom node)
>         (progn
>           (terpri)
>           (princ (make-string i :initial-element #\_))
>           (princ (node-name node))
>           (if (and (node-expanded node)
>                    (node-leafs node))
>             (render-node (node-leafs node)))))
>        (t (or
>             (render-node (car node) (1+ i))
>             (render-node (cdr node) (1+ i))))))
>
> What are the benefits of your approach and please put some code or
> pseudo code?
> Efficiency doesn't concern me, as trees should be small.
>
> Slobodan

I basically suggested to supply an interface similiar to LispWorks CAPI

s.

http://www.lispworks.com/documentation/lw50/CAPRM/html/capiref-386.htm#pgfId-1181992

and for :print-function

http://www.lispworks.com/documentation/lw50/CAPRM/html/capiref-39.htm#36673

With this it is up to the programmer, what he gives the treeview and how it has
to be understood.

Some application lines:

CL-USER 1 > (capi:contain (make-instance 'capi:tree-view :roots '(:billy :sam)))
#<CAPI:TREE-VIEW [2 items] 200C43B7>

Displays a tree-view with two root node, no further children.

CL-USER 2 > (capi:contain (make-instance 'capi:tree-view :roots '(:billy :sam) :children-function (lambda (node) (when (eq node 
:sam) '(1 2 3)))))
#<CAPI:TREE-VIEW [2 items] 217D928B>

With this :SAM has three children (1 2 3)

Now the programmer decides to use a struct for node representation

CL-USER 3 > (defstruct node (name nil) (leafs nil))
NODE

and displays the same tree-view by

CL-USER 20 > (capi:contain (make-instance 'capi:tree-view :roots (list (make-node :name :billy) (make-node :name :sam :leafs (list 
(make-node :name 1) (make-node :name 2) (make-node :name 3)))) :children-function #'node-leafs :print-function (lambda (n) (format 
nil "~a" (node-name n)))))
#<CAPI:TREE-VIEW [2 items] 2181BEB3>

Hope this is helpful. Sorry just copy'n'pasting from my repl.

Andreas

P.S. CAPI:CONTAIN is a helper which makes a window containing the control
From: Slobodan Blazeski
Subject: Re: How to map tree on a data structure
Date: 
Message-ID: <c2420b8a-37f5-48fe-bad3-478e0468d3a1@i3g2000hsf.googlegroups.com>
On Dec 17, 1:32 pm, "Andreas Thiele" <······@nospam.com> wrote:
> "Slobodan Blazeski" <·················@gmail.com> schrieb im ····················································@l1g2000hsa.googlegroups.com...
>
>
>
> > On Dec 16, 4:10 am, "Andreas Thiele" <······@nospam.com> wrote:
> >> "Slobodan Blazeski" <·················@gmail.com> schrieb im
> >> ····················································@b40g2000prf.googlegroups.com...
>
> >> >I want to create treeview  widget something like
> >> >http://www.filebuzz.com/software_screenshot/full/23223-extended_treev...
> >> > or
> >> >http://developer.emc.com/developer/obt/images/browser_tree.jpgor
> >> >http://www.informationbuilders.com/new/newsletter/6-3/images/sitt1.jpg
> >> > The question is how to map the data from tree to hold the current
> >> > state .
> >> > The only thing that comes into my mind is   atom for the leaves and
> >> > list with a marker that shows up is the current node open or closed.
> >> > (root  (node1 open (leaf leaf (node11 closed leaf)))
> >> >          (node2 closed (node21 open leaf)
> >> >          leaf
> >> >         ....
>
> >> > thanks
> >> > Slobodan
>
> >> I'd allow arbitrary data to be presented, like i.e. LispWorks CAPI graphical UI library does.
> >> Basically you give a list of root nodes to the treeview together with a item-child-function, an
> >> item-get-function, item-count-function and such. These functions can have reasonable
> >> defaults so you can at least pass a list of symbols or strings. With item-get-function and
> >> item-count-function you can pass anything representing the root nodes.
>
> >> Andreas
>
> > I don't understand what are you trying to say. If I define node like
> > this:
> > (defstruct node
> >  (name nil)
> >  ;other slots you need
> >  (expanded nil)
> >  (leafs    nil))
>
> > Than i could use a simple recursion render all the leafs with snippet
> > like this:
>
> > (defun render-node (node &optional (i 0)); not tested
> >  (cond ((null node) nil)
> >        ((atom node)
> >         (progn
> >           (terpri)
> >           (princ (make-string i :initial-element #\_))
> >           (princ (node-name node))
> >           (if (and (node-expanded node)
> >                    (node-leafs node))
> >             (render-node (node-leafs node)))))
> >        (t (or
> >             (render-node (car node) (1+ i))
> >             (render-node (cdr node) (1+ i))))))
>
> > What are the benefits of your approach and please put some code or
> > pseudo code?
> > Efficiency doesn't concern me, as trees should be small.
>
> > Slobodan
>
> I basically suggested to supply an interface similiar to LispWorks CAPI
>
> s.
>
> http://www.lispworks.com/documentation/lw50/CAPRM/html/capiref-386.ht...
>
> and for :print-function
>
> http://www.lispworks.com/documentation/lw50/CAPRM/html/capiref-39.htm...
>
> With this it is up to the programmer, what he gives the treeview and how it has
> to be understood.
>
> Some application lines:
>
> CL-USER 1 > (capi:contain (make-instance 'capi:tree-view :roots '(:billy :sam)))
> #<CAPI:TREE-VIEW [2 items] 200C43B7>
>
> Displays a tree-view with two root node, no further children.
>
> CL-USER 2 > (capi:contain (make-instance 'capi:tree-view :roots '(:billy :sam) :children-function (lambda (node) (when (eq node
> :sam) '(1 2 3)))))
> #<CAPI:TREE-VIEW [2 items] 217D928B>
>
> With this :SAM has three children (1 2 3)
>
> Now the programmer decides to use a struct for node representation
>
> CL-USER 3 > (defstruct node (name nil) (leafs nil))
> NODE
>
> and displays the same tree-view by
>
> CL-USER 20 > (capi:contain (make-instance 'capi:tree-view :roots (list (make-node :name :billy) (make-node :name :sam :leafs (list
> (make-node :name 1) (make-node :name 2) (make-node :name 3)))) :children-function #'node-leafs :print-function (lambda (n) (format
> nil "~a" (node-name n)))))
> #<CAPI:TREE-VIEW [2 items] 2181BEB3>
>
> Hope this is helpful. Sorry just copy'n'pasting from my repl.
>
> Andreas
>
> P.S. CAPI:CONTAIN is a helper which makes a window containing the control

Thanks I will look at it, but actually I was asking about internal
implementation of the tree.

cheers
Slobodan