KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portal > faces > renderer > html > container > TabRenderer


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
6 package org.exoplatform.portal.faces.renderer.html.container;
7
8 import java.io.IOException JavaDoc;
9 import java.util.List JavaDoc;
10
11 import javax.faces.context.FacesContext;
12 import javax.faces.context.ResponseWriter;
13 import org.exoplatform.faces.core.component.model.Parameter;
14 import org.exoplatform.portal.PortalConstants;
15 import org.exoplatform.portal.faces.component.UIBasicComponent;
16 import org.exoplatform.portal.faces.component.UIBody;
17 import org.exoplatform.portal.faces.component.UIContainer;
18 import org.exoplatform.portal.faces.component.UIPortlet;
19
20
21 /**
22  * @author Benjamin Mestrallet
23  * benjamin.mestrallet@exoplatform.com
24  */

25 public class TabRenderer extends ContainerRenderer{
26   
27   final static protected Parameter CHANGE_TAB =
28     new Parameter(PortalConstants.PORTAL_ACTION, PortalConstants.CHANGE_CONTAINER_TAB_ACTION);
29   final static public String JavaDoc TAB_PARAMETER = "tab" ;
30   
31   protected void renderViewMode(FacesContext context, UIContainer uiContainer)
32       throws IOException JavaDoc {
33     ResponseWriter w = context.getResponseWriter();
34     List JavaDoc children = uiContainer.getChildren();
35     int childrenSize = children.size() ;
36     if(childrenSize == 0 ) return ;
37     w.write("<div class='"); w.write(uiContainer.getDecorator()); w.write("-container'");
38     w.write(" id='") ; w.write(uiContainer.getId());w.write("'>") ;
39     UIBasicComponent selectedComponent = null;
40     w. write("<div class='tabs'>");
41     for(int i=0 ; i < childrenSize; i++) {
42       UIBasicComponent uiChild = (UIBasicComponent) children.get(i) ;
43       if(uiChild.isRendered()) {
44         if(i == uiContainer.getSelectedComponent()){
45           w.write("<table><tr><td class='selected-tab-left' SRC='/skin/blank.gif'/>");
46           w.write("<td class='selected-tab-middle'>");
47           renderTabLink(w, uiContainer, uiChild);
48           w.write("</td>");
49           w.write("<td class='selected-tab-right' SRC='/skin/blank.gif'/></tr></table>\n");
50           selectedComponent = uiChild;
51         } else {
52           w.write("<table><tr><td class='tab-left' SRC='/skin/blank.gif'/>");
53           w.write("<td class='tab-middle'>");
54           renderTabLink(w, uiContainer, uiChild);
55           w.write("</td>");
56           w.write("<td class='tab-right' SRC='/skin/blank.gif'/></tr></table>\n");
57         }
58       }
59     }
60     w. write("</div>");
61     w. write("<div class='selected-body'>");
62     if(selectedComponent == null) {
63       selectedComponent = (UIBasicComponent) children.get(0) ;
64       selectedComponent.setRendered(true) ;
65     }
66     selectedComponent.encodeBegin(context);
67     selectedComponent.encodeChildren(context);
68     selectedComponent.encodeEnd(context);
69     w. write("</div>");
70     w.write("</div>") ;
71   }
72   
73   private void renderTabLink(ResponseWriter w, UIContainer uiContainer, UIBasicComponent uiChild)
74     throws IOException JavaDoc{
75     Parameter tab = new Parameter(TAB_PARAMETER, "");
76     Parameter[] changeTabParams = {CHANGE_TAB, tab };
77     String JavaDoc tabTitle = "";
78     String JavaDoc componentId = "";
79     if(uiChild instanceof UIContainer){
80       tabTitle = ((UIContainer)uiChild).getTitle();
81       componentId = uiChild.getId();
82     } else if (uiChild instanceof UIPortlet ){
83       tabTitle = ((UIPortlet)uiChild).getDisplayTitle();
84       componentId = uiChild.getId();
85     } else if (uiChild instanceof UIBody ){
86       tabTitle = uiChild.getId();
87       componentId = tabTitle;
88     }
89     tab.setValue(componentId);
90     if(tabTitle == null) tabTitle = componentId ;
91     linkRenderer_.render(w, uiContainer, tabTitle, changeTabParams);
92   }
93 }
Popular Tags