001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/jsf/widgets/src/java/org/theospi/jsf/renderer/WizardStepRenderer.java $
003: * $Id: WizardStepRenderer.java 10835 2006-06-17 03:25:03Z lance@indiana.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:
024: import javax.faces.component.UIComponent;
025: import javax.faces.component.UIOutput;
026: import javax.faces.context.FacesContext;
027: import javax.faces.context.ResponseWriter;
028: import javax.faces.render.Renderer;
029:
030: import org.sakaiproject.jsf.util.RendererUtil;
031:
032: public class WizardStepRenderer extends Renderer {
033: public boolean supportsComponentType(UIComponent component) {
034: return (component instanceof UIOutput);
035: }
036:
037: protected String getStepClass(FacesContext context,
038: UIComponent component) {
039: //Note: currentStep is zero-based and step is 1 one-based
040: String stepNumber = (String) RendererUtil.getAttribute(context,
041: component, "stepNumber");
042: String currentStep = (String) RendererUtil.getAttribute(
043: context, component.getParent(), "currentStep");
044: int curStep = Integer.parseInt(currentStep);
045: int loopStep = Integer.parseInt(stepNumber) - 1;
046:
047: String retVal = "";
048: if (RendererUtil.isDisabledOrReadonly(context, component))
049: retVal = "disabled_state";
050: else if (loopStep < curStep)
051: retVal = "previous_state";
052: else if (loopStep == curStep)
053: retVal = "current_state";
054: else
055: retVal = "next_state";
056:
057: return retVal;
058: }
059:
060: /**
061: * This renders html for the beginning of the tag.
062: *
063: * @param context
064: * @param component
065: * @throws IOException
066: */
067: public void encodeBegin(FacesContext context, UIComponent component)
068: throws IOException {
069: ResponseWriter writer = context.getResponseWriter();
070: String state = getStepClass(context, component);
071: writer.write("<td class=\"" + state + "\">");
072: }
073:
074: /**
075: * @param context FacesContext for the request we are processing
076: * @param component UIComponent to be rendered
077: * @exception IOException if an input/output error occurs while rendering
078: * @exception NullPointerException if <code>context</code> or <code>component</code> is null
079: */
080: public void encodeEnd(FacesContext context, UIComponent component)
081: throws IOException {
082: ResponseWriter writer = context.getResponseWriter();
083:
084: String stepNumber = (String) RendererUtil.getAttribute(context,
085: component, "stepNumber");
086: String label = (String) RendererUtil.getAttribute(context,
087: component, "label");
088: String state = getStepClass(context, component);
089:
090: if (stepNumber != null) {
091: writer.write("<div class=\"" + state + "\">");
092: writer.write(stepNumber);
093: writer.write("</div>");
094: }
095:
096: if (label != null) {
097: writer.write(" ");
098: writer.write(label);
099: writer.write(" ");
100: }
101: writer.write("</td>");
102: }
103: }
|