001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-app/src/java/org/sakaiproject/tool/messageforums/jsf/HideDivisionRenderer.java $
003: * $Id: HideDivisionRenderer.java 9227 2006-05-15 15:02:42Z cwen@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.messageforums.jsf;
021:
022: import java.io.IOException;
023: import java.util.Iterator;
024: import javax.faces.component.UIComponent;
025: import javax.faces.component.UIViewRoot;
026: import javax.faces.component.html.HtmlOutputText;
027: import javax.faces.context.FacesContext;
028: import javax.faces.context.ResponseWriter;
029: import javax.faces.render.Renderer;
030:
031: import java.util.List;
032:
033: /**
034: * @author Chen Wen
035: * @version $Id$
036: *
037: */
038: public class HideDivisionRenderer extends Renderer {
039: private static final String BARSTYLE = "msgMainHeadings";
040: private static final String BARTAG = "div";
041: private static final String RESOURCE_PATH;
042: private static final String FOLD_IMG_HIDE;
043: private static final String FOLD_IMG_SHOW;
044: private static final String CURSOR;
045:
046: static {
047: RESOURCE_PATH = "/" + "sakai-messageforums-tool";
048: FOLD_IMG_HIDE = RESOURCE_PATH + "/images/right_arrow.gif";
049: FOLD_IMG_SHOW = RESOURCE_PATH + "/images/down_arrow.gif";
050: CURSOR = "cursor:pointer";
051: /*ConfigurationResource cr = new ConfigurationResource();
052: RESOURCE_PATH = "/" + cr.get("resources");
053: BARIMG = RESOURCE_PATH + "/" +cr.get("hideDivisionRight");
054: CURSOR = cr.get("picker_style");*/
055: }
056:
057: public boolean supportsComponentType(UIComponent component) {
058: return (component instanceof org.sakaiproject.tool.messageforums.jsf.HideDivisionComponent);
059: }
060:
061: public void decode(FacesContext context, UIComponent component) {
062: }
063:
064: public void encodeChildren(FacesContext context,
065: UIComponent component) throws IOException {
066: if (!component.isRendered()) {
067: return;
068: }
069:
070: Iterator children = component.getChildren().iterator();
071: while (children.hasNext()) {
072: UIComponent child = (UIComponent) children.next();
073: if (!((child instanceof org.sakaiproject.tool.messageforums.jsf.BarLinkComponent) || (child instanceof HtmlOutputText))) {
074: child.encodeBegin(context);
075: child.encodeChildren(context);
076: child.encodeEnd(context);
077: }
078: }
079: }
080:
081: public void encodeBegin(FacesContext context, UIComponent component)
082: throws IOException {
083:
084: if (!component.isRendered()) {
085: return;
086: }
087:
088: ResponseWriter writer = context.getResponseWriter();
089: String jsfId = (String) RendererUtil.getAttribute(context,
090: component, "id");
091: String id = jsfId;
092:
093: if (component.getId() != null
094: && !component.getId().startsWith(
095: UIViewRoot.UNIQUE_ID_PREFIX)) {
096: id = component.getClientId(context);
097: }
098:
099: String title = (String) RendererUtil.getAttribute(context,
100: component, "title");
101: Object tmpFoldStr = RendererUtil.getAttribute(context,
102: component, "hideByDefault");
103: boolean foldDiv = tmpFoldStr != null
104: && tmpFoldStr.equals("true");
105: String foldImage = foldDiv ? FOLD_IMG_HIDE : FOLD_IMG_SHOW;
106: writer.write("<" + BARTAG + " class=\"" + BARSTYLE + "\">");
107: writer
108: .write("<table style=\"width: 100%;\" class=\"discTria\" cellpadding=\"0\" cellspacing=\"0\" summary=\"layout\">");
109: writer.write("<tr><td class=\"discTria\">");
110: writer.write(" <img id=\"" + id + "__img_hide_division_"
111: + "\" alt=\"" + title + "\""
112: + " onclick=\"javascript:showHideDivBlock('" + id
113: + "', '" + RESOURCE_PATH + "');\"");
114: writer.write(" src=\"" + foldImage + "\" style=\"" + CURSOR
115: + "\" />");
116: writer.write("<h4>" + title + "</h4>");
117: writer.write("</td><td class=\"discTria\"> </td>");
118: writer
119: .write("<td class=\"itemAction\" style=\"text-align: right;\">");
120: List childrenList = component.getChildren();
121: for (int i = 0; i < childrenList.size(); i++) {
122: UIComponent this Component = (UIComponent) childrenList
123: .get(i);
124: if (this Component instanceof org.sakaiproject.tool.messageforums.jsf.BarLinkComponent
125: || this Component instanceof HtmlOutputText) {
126: this Component.encodeBegin(context);
127: this Component.encodeChildren(context);
128: this Component.encodeEnd(context);
129: }
130: }
131: writer.write("</td></tr></table>");
132: writer.write("</" + BARTAG + ">");
133: if (foldDiv) {
134: writer.write("<div style=\"display:none\" " + " id=\"" + id
135: + "__hide_division_" + "\">");
136: } else {
137: writer.write("<div style=\"display:block\" " + " id=\""
138: + id + "__hide_division_" + "\">");
139: }
140: }
141:
142: public void encodeEnd(FacesContext context, UIComponent component)
143: throws IOException {
144: if (!component.isRendered()) {
145: return;
146: }
147:
148: ResponseWriter writer = context.getResponseWriter();
149:
150: String jsfId = (String) RendererUtil.getAttribute(context,
151: component, "id");
152: String id = jsfId;
153:
154: if (component.getId() != null
155: && !component.getId().startsWith(
156: UIViewRoot.UNIQUE_ID_PREFIX)) {
157: id = component.getClientId(context);
158: }
159:
160: writer.write("</div>");
161:
162: // writer.write("<script type=\"text/javascript\">");
163: // writer.write(" showHideDiv('" + id +
164: // "', '" + RESOURCE_PATH + "');");
165: // writer.write("</script>");
166: }
167:
168: }
|