001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/jsf/widgets/src/java/org/theospi/jsf/renderer/TabAreaRenderer.java $
003: * $Id: TabAreaRenderer.java 15703 2006-10-05 18:16:51Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 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.theospi.jsf.renderer;
021:
022: import java.io.IOException;
023: import java.util.Iterator;
024:
025: import javax.faces.component.UIComponent;
026: import javax.faces.component.UIOutput;
027: import javax.faces.context.FacesContext;
028: import javax.faces.context.ResponseWriter;
029: import javax.faces.render.Renderer;
030:
031: import org.sakaiproject.jsf.util.RendererUtil;
032: import org.theospi.jsf.component.TabComponent;
033: import org.theospi.jsf.util.ConfigurationResource;
034: import org.theospi.jsf.util.OspxTagHelper;
035:
036: /**
037: * This creates a split content area. It divides a space in two.
038: * This creates a table of size width x height. It the uses
039: * the divider position to give the first cell a height or width
040: * based on if the direction is vertical or horizontal, respectively.
041: * <br><br>
042: * This class depends on the splitdivider tag to create the actual divide
043: * The second class makes the second cell.
044: *
045: * @author andersjb
046: *
047: */
048:
049: public class TabAreaRenderer extends Renderer {
050:
051: private static final String RESOURCE_PATH;
052: private static final String CURSOR;
053: private static final String CSS_LOC;
054:
055: static {
056: ConfigurationResource cr = new ConfigurationResource();
057: RESOURCE_PATH = "/" + cr.get("resources");
058: CURSOR = cr.get("picker_style");
059: CSS_LOC = RESOURCE_PATH + "/" + cr.get("cssFile");
060: }
061:
062: public boolean supportsComponentType(UIComponent component) {
063: return (component instanceof UIOutput);
064: }
065:
066: /**
067: * This renders html for the beginning of the tag.
068: *
069: * @param context
070: * @param component
071: * @throws IOException
072: */
073: public void encodeBegin(FacesContext context, UIComponent component)
074: throws IOException {
075: ResponseWriter writer = context.getResponseWriter();
076:
077: String directionStr = (String) RendererUtil.getAttribute(
078: context, component, "direction");
079: String height = (String) RendererUtil.getAttribute(context,
080: component, "height");
081: String width = (String) RendererUtil.getAttribute(context,
082: component, "width");
083:
084: //checks for vertical, its abbr., and the y axis
085:
086: RendererUtil.writeExternalCSSDependencies(context, writer,
087: "osp.jsf.css", CSS_LOC);
088: writer.write("<table border=\"0\" ");
089: RendererUtil.writeAttr(writer, "height", height);
090: RendererUtil.writeAttr(writer, "width", width);
091:
092: //the tab cell needs to be small, it will be expanded
093: writer.write("><tr><td width=\"1%\">");
094:
095: }
096:
097: /**
098: * @param context FacesContext for the request we are processing
099: * @param component UIComponent to be rendered
100: * @exception IOException if an input/output error occurs while rendering
101: * @exception NullPointerException if <code>context</code> or <code>component</code> is null
102: */
103: public void encodeEnd(FacesContext context, UIComponent component)
104: throws IOException {
105: String directionStr = (String) RendererUtil.getAttribute(
106: context, component, "direction");
107: ResponseWriter writer = context.getResponseWriter();
108:
109: writer.write("</td>");
110: if (OspxTagHelper.isVertical(directionStr)) {
111: writer.write("<td width=\"*\">");
112: encodeTabContent(context, component);
113: writer.write("</td>");
114: } else {
115: writer.write("</tr><tr><td>");
116: encodeTabContent(context, component);
117: writer.write("</td>");
118: }
119:
120: writer.write("</tr></table>");
121:
122: }
123:
124: protected void encodeTabContent(FacesContext context,
125: UIComponent component) throws IOException {
126: Iterator iter = component.getChildren().iterator();
127:
128: while (iter.hasNext()) {
129: UIComponent step = (UIComponent) iter.next();
130: if (!(step instanceof TabComponent) || !step.isRendered()) {
131: continue;
132: }
133: TabComponent tab = (TabComponent) step;
134: if (tab.getSelected().equalsIgnoreCase("true")) {
135: for (Iterator i = tab.getChildren().iterator(); i
136: .hasNext();) {
137: UIComponent tab_content = (UIComponent) i.next();
138: RendererUtil.encodeRecursive(context, tab_content);
139: }
140: }
141: }
142: }
143:
144: public boolean getRendersChildren() {
145: return false;
146: }
147:
148: }
|