KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.ResourceBundle JavaDoc;
10 import javax.faces.component.UIComponent;
11 import javax.faces.context.FacesContext;
12 import javax.faces.context.ResponseWriter;
13 import org.exoplatform.commons.utils.ExpressionUtil;
14 import org.exoplatform.faces.core.component.UIExoComponent;
15 import org.exoplatform.faces.core.component.Node ;
16 import org.exoplatform.faces.core.component.model.Parameter;
17
18 public class SimpleTabRenderer extends NodeMenuRenderer {
19   final public void encodeChildren( FacesContext context, UIComponent component ) throws IOException JavaDoc {
20     ResponseWriter w = context.getResponseWriter() ;
21     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext());
22     UIExoComponent uiComponent = (UIExoComponent) component ;
23     List JavaDoc children = uiComponent.getChildren() ;
24     if(children.size() == 0 ) return ;
25     UIExoComponent uiSelectTab = null ;
26     
27     String JavaDoc clazz = uiComponent.getClazz() ;
28     if (clazz == null) {
29       w.write("<div>") ;
30     } else {
31       w.write("<div class='") ; w.write(clazz) ; w.write("'>") ;
32     }
33     if (children.size() > 1) {
34       Parameter tabIdParam = new Parameter("tabId" , "");
35       Parameter[] params = {SELECT_TAB , tabIdParam} ;
36       w.write("<ul class='"); w.write(getTabCssClass()) ; w.write("'>") ;
37       for(int i =0; i < children.size(); i++) {
38         UIExoComponent uiChild = (UIExoComponent) children.get(i) ;
39         tabIdParam.setValue(uiChild.getId()) ;
40         String JavaDoc label = null ;
41         if(uiChild instanceof Node) {
42           Node uiNode = (Node) uiChild ;
43           label = uiNode.getName() ;
44         }
45         if(label == null) {
46           label = ExpressionUtil.getValue(res, "UINode.label." + uiChild.getId()) ;
47         }
48         w.write("<li>") ;
49         if(uiChild.isRendered()) {
50           linkRenderer_.renderSelect(w, uiComponent, label, params) ;
51           uiSelectTab = uiChild ;
52         } else {
53           linkRenderer_.render(w, uiComponent, label, params) ;
54         }
55         w.write("</li>") ;
56       }
57       w.write("</ul>") ;
58     } else {
59       uiSelectTab = (UIExoComponent) children.get(0) ;
60     }
61     w.write("<div class='"); w.write(getTabBodyCssClass()) ; w.write("'>") ;
62     uiSelectTab.encodeBegin(context) ;
63     uiSelectTab.encodeChildren(context) ;
64     uiSelectTab.encodeEnd(context) ;
65     w.write("</div>") ;
66     w.write("</div>") ;
67   }
68   
69   protected String JavaDoc getTabCssClass() { return "UISimpleTabs" ; }
70   
71   protected String JavaDoc getTabBodyCssClass() { return "UISimpleTabBody" ; }
72 }
Popular Tags