velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Priatel <mpria...@espial.com>
Subject RE: tree structure
Date Mon, 16 Jul 2001 20:15:31 GMT
What I've done in the case of showing a thread tree in a message forum is to
create a tree object, then make the tree implement Iterator.  Your iterator
implementation should return tree nodes in a depth-first (uh...I think
that's the right term) fashion so that each call to next() returns nodes
from left to right, top to bottom.

Afterwards, your tree, given a node, should be able to tell you what that
node's depth is ( or add aa depth property to your node so that you can
create proper indentation)...Any rate, here's my velocity template (you can
see this in action at: http://www.devicetop.com/site/forum/viewmsg/msg-8026
(bottom of page), as an example..)

Hope if helps...

---template----

<!-- Begin forum_thread_snapshot -->
<hr size=1 noshade>
<b>Message Thread</b>
#set($MAX = 8)   #* max levels of indentation *#
<table width=400 border=0 cellpadding=0 cellspacing=0>
 <tr>
#foreach( $i in [1..$MAX])
<td width=10><img src=/DT/images/spacer.gif width=10 height=1></td>
#end
 <td width=100%></td>
</tr>

#foreach( $node in $tree.getTreeIterator() )
 #set($m = $node.getValue()) #* msg subject *#
 #set($d = $tree.getDepth($node)) #*
 #set($diff = $MAX - $d + 1 )
<tr>
 #if($d > $MAX) #set($d = $MAX) #end
 #if($d != 0)
    #foreach($i in [1..$d])
      <td> </td>
    #end
 #end
    <td colspan=$diff>
    <a href=$context/forum/viewmsg/msg-$m.getID()>$m.getSubject()</a>
    #if($m.getID() == $msg.getID()) (viewed) #end 
    </td>
</tr>
#end

</table>
<hr size=1 noshade>

<!-- End forum_thread_snapshot -->

-----Original Message-----
From: Uday Kumar [mailto:uday@eself.com]
Sent: Monday, July 16, 2001 3:19 PM
To: velocity-user@jakarta.apache.org
Subject: tree structure


hi guys

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) in velocity? i mean if i have a vector thru which i need to loop
using foreach and print out as a tree.

-Uday


----- Original Message -----
From: "Jon Stevens" <jon@latchkey.com>
To: "velocity-user" <velocity-user@jakarta.apache.org>
Sent: Monday, July 16, 2001 12:11 PM
Subject: Re: Can I write a macro that can call itself?


> on 7/14/01 6:15 AM, "Brad Cox" <bcox@virtualschool.edu> wrote:
>
> > And he wonders why more people don't pitch in to help. Sigh.
>
> I don't wonder that.
>
> -jon
>
>

Mime
View raw message