KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > user > renderer > html > GroupExplorerRenderer


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.portlets.user.renderer.html;
6
7 import java.io.IOException JavaDoc;
8 import java.util.*;
9 import javax.faces.component.UIComponent;
10 import javax.faces.context.FacesContext;
11 import javax.faces.context.ResponseWriter;
12 import org.exoplatform.faces.core.component.model.Parameter;
13 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
14 import org.exoplatform.portlets.user.component.UIGroupExplorer;
15 import org.exoplatform.services.organization.Group;
16 /**
17  * @email: tuan08@users.sourceforge.net
18  * @version: $Id: GroupExplorerRenderer.java,v 1.12 2004/10/22 14:23:31 tuan08 Exp $
19  */

20 public class GroupExplorerRenderer extends HtmlBasicRenderer {
21   private static Parameter CHANGE_GROUP = new Parameter(ACTION , "changeGroup") ;
22   private static Parameter ADD_GROUP = new Parameter(ACTION , "addGroup") ;
23   private static Parameter[] deleteGroupParams_ = { new Parameter(ACTION , "deleteGroup")} ;
24
25   final public void encodeBegin( FacesContext context, UIComponent component ) throws IOException JavaDoc {
26     ResourceBundle res = getApplicationResourceBundle(context.getExternalContext()) ;
27     ResponseWriter w = context.getResponseWriter() ;
28     UIGroupExplorer uiExplorer = (UIGroupExplorer) component ;
29     Collection childrenGroup = uiExplorer.getChildrenGroup() ;
30     Group currentGroup = uiExplorer.getCurrentGroup() ;
31     Group parentGroup = uiExplorer.getParentGroup() ;
32     String JavaDoc groupLabel = "/" ;
33     if (currentGroup != null) groupLabel = currentGroup.getId();
34     Object JavaDoc[] args = { groupLabel } ;
35     w.write("<table class='UIGroupExplorer'>");
36     w. write("<tr>");
37     w. write("<th class='header' colspan='2'>");
38     w. write(ft_.format(res.getString("UIGroupExplorer.label.group"), args));
39     w. write("</th>");
40     w. write("</tr>");
41     w. write("<tr>");
42     w. write("<td class='group-tree'>");
43     addGroupTreeTable(parentGroup, childrenGroup, w, res, uiExplorer) ;
44     w. write("</td>");
45     w. write("<td>");
46     renderChildren(context, uiExplorer) ;
47     w. write("</td>");
48     w. write("</tr>");
49     w. write("<tr>");
50     w. write("<td colspan='2' class='footer'>");
51     String JavaDoc parentGroupId = "" ;
52     if (currentGroup != null) parentGroupId = currentGroup.getId() ;
53     Parameter groupParam = new Parameter(UIGroupExplorer.GROUP_ID, parentGroupId) ;
54     Parameter[] addGroupParams = { ADD_GROUP,groupParam } ;
55     linkRenderer_.render(w, uiExplorer, res.getString("UIGroupExplorer.button.add-group"), addGroupParams) ;
56     linkRenderer_.render(w, uiExplorer, res.getString("UIGroupExplorer.button.delete-group"), deleteGroupParams_) ;
57     w. write("</td>");
58     w. write("</tr>");
59     w.write("</table>");
60   }
61
62   private void addGroupTreeTable(Group parentGroup, Collection childrenGroup, ResponseWriter w,
63                                  ResourceBundle res, UIGroupExplorer uiExplorer) throws IOException JavaDoc {
64     Parameter groupIdParam = new Parameter(UIGroupExplorer.GROUP_ID, "") ;
65     Parameter[] changeGroupParams = { CHANGE_GROUP,groupIdParam } ;
66     Iterator i = childrenGroup.iterator() ;
67     String JavaDoc parentGroupId = "" ;
68     if (parentGroup != null) parentGroupId = parentGroup.getId() ;
69     String JavaDoc groupIcon = res.getString("UIGroupExplorer.img.group-icon") ;
70     w.write("<table>");
71     w. write("<tr>");
72     w. write("<td>");
73     groupIdParam.setValue(parentGroupId) ;
74     linkRenderer_.render(w, uiExplorer, "[..]", changeGroupParams) ;
75     w. write("</td>");
76     w. write("</tr>");
77     while(i.hasNext()) {
78       Group group = (Group)i.next() ;
79       w.write("<tr>");
80       w. write("<td style='padding-left: 10px'>");
81       w. write(groupIcon);
82       groupIdParam.setValue(group.getId()) ;
83       linkRenderer_.render(w, uiExplorer, group.getGroupName(), changeGroupParams) ;
84       w. write("</td>");
85       w.write("</tr>");
86     }
87     w.write("</table>");
88   }
89 }
Popular Tags