KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > renderer > html > NodeTreeMenuRenderer


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.faces.core.renderer.html;
6
7 import java.util.List JavaDoc ;
8 import java.io.IOException JavaDoc;
9 import javax.faces.component.UIComponent;
10 import javax.faces.context.FacesContext;
11 import javax.faces.context.ExternalContext;
12 import javax.faces.context.ResponseWriter;
13 import org.exoplatform.faces.core.component.Node;
14 import org.exoplatform.faces.core.component.UINode;
15 import org.exoplatform.faces.core.component.model.Parameter;
16
17
18 public class NodeTreeMenuRenderer extends NodeMenuRenderer {
19   
20   public void encodeChildren( FacesContext context, UIComponent component ) throws IOException JavaDoc {
21     UINode uiNode = (UINode) component ;
22     
23     ExternalContext eContext = context.getExternalContext() ;
24     String JavaDoc baseURL = eContext.encodeActionURL("") ;
25     ResponseWriter w = context.getResponseWriter() ;
26     String JavaDoc clazz = uiNode.getClazz() ;
27     w.write("<table class='") ; w.write(clazz) ; w.write("'>") ;
28     w.write("<tr>");
29     w. write("<td class='UITreeMenu'>") ;
30     w. write("<div>"); w.write(uiNode.getName()); w.write("</div>");
31     renderNode(w, uiNode, baseURL) ;
32     w. write("</td style='vertical-align: top;'>") ;
33     w. write("<td>") ;
34     List JavaDoc children = uiNode.getChildren() ;
35     for(int i = 0; i < children.size(); i++) {
36         UIComponent uiChild = (UIComponent) children.get(i);
37         if(uiChild.isRendered()) {
38             uiChild.encodeBegin(context) ;
39             uiChild.encodeChildren(context) ;
40             uiChild.encodeEnd(context) ;
41         }
42     }
43     w. write("</td>");
44     w.write("</tr>");
45     w.write("</table>");
46   }
47   
48   public void renderNode(ResponseWriter w, Node node, String JavaDoc baseURL) throws IOException JavaDoc {
49     List JavaDoc children = node.getChildren();
50     if (children.size() == 0) return;
51     Parameter nodeIdParam = new Parameter("tabId", "");
52     Parameter[] changeNodeParams = {SELECT_TAB, nodeIdParam};
53     w.write("<ul>");
54     for (int i = 0; i < children.size(); i++) {
55         Object JavaDoc o = children.get(i) ;
56         if (o instanceof Node) {
57             Node child = (Node) o;
58         w.write("<li>");
59         nodeIdParam.setValue(child.getId());
60         appendLink(w, child.getName(), baseURL, changeNodeParams, "");
61         if (child.getChildren().size() > 0) {
62             renderNode(w, child, baseURL);
63         }
64         w.write("</li>");
65         }
66     }
67     w.write("</ul>");
68   }
69 }
Popular Tags