You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Uday Kumar <ud...@eself.com> on 2001/07/17 16:43:40 UTC

my tree

hi Tim

i did write a code to print out a tree, but i am sure no one wud want to see
that, as it is such a lousy code. wrote it just to serve the purpose,
debugging it wud be a pain for new-comers. my problem is... i have a
vectorof objects and they are arranged in order. i have to print them out
one by one, but with the only condition that some of them might have
subcategories, i can call some methods on it(ex. hasSubCategories( ) ) and
then according to the result, i print out with indentations. as i cud not do
the indentations, i made tables and each time i changed the width and
printed it out...

lemme give an example. actually, the categories would be like---

main1
   test1
   test2
      test22
      test23
  test3
main2

if this was my tree, the vector i have to recurse thru would be
[main1,test1,test2,test22,test23,test3,main2]. all the things are in order,
ready to be printed straightaway, but i have to identify whether each of
them has subcategories and then print it as above.

now, i made u my problem more clear, tell me if this works in the SAME WAY u
did? if that is the case, i wud replace my code with yours. please let me
know

thanks in advance

-Uday



----- Original Message -----
From: "Tim Joyce" <ti...@hoop.co.uk>
To: <ve...@jakarta.apache.org>
Sent: Monday, July 16, 2001 11:47 PM
Subject: Re: tree structure


> Uday,
>
> > i wanna know if any one of u has already implemented a tree structure
> > (similar to windows explorer, atleast indentation, if not collapsing and
> > expanding)
>
> if you are after collapsing and expanding, one of the melati developers
> (mylesc) has written some funky javascript dhtml dynamic tree thiggy
widget.
> maps to
>
>
http://www.paneris.org/cgi-bin/cvsweb.cgi/org/melati/util/JSDynamicTree.java
>
> on the back end.  I have never seen it in action, so would be prepared to
> try and get a demo working if you are interested.  you may also want to
look
> at the following resources:
>
> http://www.paneris.org/cgi-bin/cvsweb.cgi/org/melati/admin/trees.js
>
http://www.paneris.org/cgi-bin/cvsweb.cgi/org/melati/template/webmacro/templ
> ets/html/org.melati.util.JSDynamicTree.wm
> http://www.paneris.org/cgi-bin/cvsweb.cgi/org/melati/util/Tree.java
> http://www.paneris.org/cgi-bin/cvsweb.cgi/org/melati/util/Treeable.java
>
> (i know the last resource is webmacro, but that is trivial to change).
>
> let me know if you want to see this.
>
> cheers
>
> timj
>
>
>


Re: my tree

Posted by Jonathan Revusky <jr...@terra.es>.
Simon Christian wrote:
> 
> Uday Kumar wrote:
> >
> > hi Tim
> >
> > i did write a code to print out a tree, but i am sure no one wud want to see
> > that, as it is such a lousy code. wrote it just to serve the purpose,
> > debugging it wud be a pain for new-comers. my problem is... i have a
> > vectorof objects and they are arranged in order. i have to print them out
> > one by one, but with the only condition that some of them might have
> > subcategories, i can call some methods on it(ex. hasSubCategories( ) ) and
> > then according to the result, i print out with indentations. as i cud not do
> > the indentations, i made tables and each time i changed the width and
> > printed it out...
> >
> > lemme give an example. actually, the categories would be like---
> >
> > main1
> >    test1
> >    test2
> >       test22
> >       test23
> >   test3
> > main2
> >
> > if this was my tree, the vector i have to recurse thru would be
> > [main1,test1,test2,test22,test23,test3,main2]. all the things are in order,
> > ready to be printed straightaway, but i have to identify whether each of
> > them has subcategories and then print it as above.
> >
> > now, i made u my problem more clear, tell me if this works in the SAME WAY u
> > did? if that is the case, i wud replace my code with yours. please let me
> > know
> 
> Is it possible for the objects in your vector to report how many nodes
> there are in the tree between themselves and the 'root'? If so this is
> the easy way to tackle your problem. e.g. from your example, test22
> would have 2 nodes above it, hence indent it with two units. The
> simplest unit to use might be a non-breaking-space. Example vm code:
> 
> #foreach( $node in $myVector )
> #foreach( $i in $node.countParentNodes() )&nbsp;&nbsp;&nbsp;#end
> $node.Name
> #end
> 
> Given it's a brute force approach, but it would work ok (or am i missing
> something?)

Here is a snippet of template code that I wrote for a (free) forum app
that is downloadable from my site. The template syntax is freemarker but
it would surprise me if the basic approach doesn't work in velocity. The
<function> would correspond to a "velocimacro" or whatever they call it
and the <call ..> is the invocation syntax. The <list> directive and
<if> are #foreach and #if in Velocity. And of course, the article and
item objects are things exposed on the tree.

<function showSummary(item)>
    <if item.unique_id == article.unique_id>
    <B><FONT COLOR="red">
    <else>
    <A HREF="${item.URL}">
    </if>
        &quot;${item.title}&quot; by ${item.author_id}
        <BR><EM>${item.FirstLine}</EM>
    <if item.unique_id == article.unique_id>
    </FONT></B>
    <else>
    </A>
    </if>
</function>

<function showChildren(item)>
<OL>
<list item.children as child>
<LI>
    <call showSummary(child)>
    <call showChildren(child)>
</LI>     
</list>
</OL>
</function>

It would be sort of interesting to see how hard it is to translate from
one syntax to the other. (I suspect not very.) 

Hope that helps.

-- 
Jonathan Revusky
--
available for Java/Delphi/Internet consulting
If you want to...
- make your .class files double-clickable with SmartJ
- do Delphi/Java mixed programming with easy-to-use JNI wrapper classes
- build robust web applications with the Niggle Application Framework
then...
check out the Revusky Hacks Page: http://www.revusky.com/hacks/

Re: my tree

Posted by Simon Christian <si...@cpd.co.uk>.

Uday Kumar wrote:
> 
> hi Tim
> 
> i did write a code to print out a tree, but i am sure no one wud want to see
> that, as it is such a lousy code. wrote it just to serve the purpose,
> debugging it wud be a pain for new-comers. my problem is... i have a
> vectorof objects and they are arranged in order. i have to print them out
> one by one, but with the only condition that some of them might have
> subcategories, i can call some methods on it(ex. hasSubCategories( ) ) and
> then according to the result, i print out with indentations. as i cud not do
> the indentations, i made tables and each time i changed the width and
> printed it out...
> 
> lemme give an example. actually, the categories would be like---
> 
> main1
>    test1
>    test2
>       test22
>       test23
>   test3
> main2
> 
> if this was my tree, the vector i have to recurse thru would be
> [main1,test1,test2,test22,test23,test3,main2]. all the things are in order,
> ready to be printed straightaway, but i have to identify whether each of
> them has subcategories and then print it as above.
> 
> now, i made u my problem more clear, tell me if this works in the SAME WAY u
> did? if that is the case, i wud replace my code with yours. please let me
> know

Is it possible for the objects in your vector to report how many nodes
there are in the tree between themselves and the 'root'? If so this is
the easy way to tackle your problem. e.g. from your example, test22
would have 2 nodes above it, hence indent it with two units. The
simplest unit to use might be a non-breaking-space. Example vm code:

#foreach( $node in $myVector )
#foreach( $i in $node.countParentNodes() )&nbsp;&nbsp;&nbsp;#end
$node.Name
#end

Given it's a brute force approach, but it would work ok (or am i missing
something?)

- simon