001: /**********************************************************************************
002: *
003: * $Id: DhtmlPopupComponent.java 9271 2006-05-10 21:52:49Z ray@media.berkeley.edu $
004: *
005: ***********************************************************************************
006: *
007: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
008: *
009: * Licensed under the Educational Community License, Version 1.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.opensource.org/licenses/ecl1.php
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: *
021: **********************************************************************************/package org.sakaiproject.tool.gradebook.jsf.dhtmlpopup;
022:
023: import java.io.IOException;
024: import java.util.Iterator;
025: import java.util.List;
026:
027: import javax.faces.component.NamingContainer;
028: import javax.faces.component.UIComponent;
029: import javax.faces.context.FacesContext;
030: import javax.faces.context.ResponseWriter;
031:
032: import org.apache.commons.logging.Log;
033: import org.apache.commons.logging.LogFactory;
034: import org.sakaiproject.tool.gradebook.jsf.iterator.IteratorComponent;
035:
036: /*
037: * <gbx:dhtmlPopup popupId="#{scoreRowIndex}"
038: * columns="2"
039: * value="#{scoreRow.events}" var="eventRow"
040: * titleText="#{scoreRow.eventsLogTitle}"
041: * closeIconUrl="dhtmlpopup/dhtmlPopClose.gif"
042: * styleClass="dhtmlPopup" titleBarClass="dhtmlPopupTitleBar" closeClass="dhtmlPopupClose" dataRowClass="dhtmlPopupDataRow">
043: * <h:outputText value="#{eventRow.date}/>
044: * <h:outputText value="#{eventRow.description}/>
045: * </gbx:dhtmlPopup>
046: */
047:
048: public class DhtmlPopupComponent extends IteratorComponent implements
049: NamingContainer {
050: private static final Log log = LogFactory
051: .getLog(DhtmlPopupComponent.class);
052:
053: public final static String COMPONENT_TYPE = "org.sakaiproject.tool.gradebook.jsf.dhtmlpopup";
054:
055: // These must agree with the JavaScript logic.
056: public final static String POPUP_ID_DIV_PREFIX = "dhtmlPopup_";
057:
058: private String popupId = null;
059: private Integer numberOfColumns = null;
060: private String titleText = null;
061: private String closeIconUrl = null;
062: private String styleClass = null;
063: private String titleBarClass = null;
064: private String closeClass = null;
065: private String dataRowClass = null;
066:
067: public void encodeBegin(FacesContext context) throws IOException {
068: String popupId = getPopupId();
069: String titleText = getTitleText();
070: String closeIconUrl = getCloseIconUrl();
071:
072: ResponseWriter writer = context.getResponseWriter();
073: writer.startElement("div", null);
074: writer
075: .writeAttribute("id", POPUP_ID_DIV_PREFIX + popupId,
076: null);
077: if (styleClass != null) {
078: writer.writeAttribute("class", styleClass, "styleClass");
079: }
080: writer.writeAttribute("style", "visibility:hidden;", null);
081: startBareTable(writer);
082:
083: // The title bar is an inner table.
084: writer.startElement("tr", null);
085: writer.startElement("td", null);
086: if (numberOfColumns != null) {
087: writer
088: .writeAttribute("colspan", numberOfColumns,
089: "columns");
090: }
091:
092: startBareTable(writer);
093: writer.writeAttribute("width", "100%", null);
094: writer.startElement("tr", null);
095: writer.startElement("td", null);
096: writer.writeAttribute("width", "100%", null);
097: writer.startElement("div", null);
098: if (titleBarClass != null) {
099: writer.writeAttribute("class", titleBarClass,
100: "titleBarClass");
101: }
102: writer.writeAttribute("onmouseover",
103: "javascript:dhtmlPopupMouseover('" + popupId
104: + "', event);", null);
105: writer.writeAttribute("onmouseout",
106: "javascript:dhtmlPopupMouseout(event);", null);
107: if (titleText != null) {
108: writer.writeText(titleText, "titleText");
109: }
110: writer.endElement("div");
111: writer.endElement("td");
112:
113: writer.startElement("td", null);
114: writer.startElement("div", null);
115: if (closeClass != null) {
116: writer.writeAttribute("class", closeClass, "closeClass");
117: }
118: writer.startElement("a", null);
119: writer.writeAttribute("href", "#", null);
120: writer.writeAttribute("title", "Close", null);
121: writer.writeAttribute("onClick", "javascript:dhtmlPopupHide('"
122: + popupId + "', event); return false;", null);
123: if (closeIconUrl != null) {
124: writer.startElement("img", null);
125: writer.writeAttribute("src", closeIconUrl, "closeIconUrl");
126: writer.writeAttribute("alt", "Close", null);
127: writer.writeAttribute("border", "0", null);
128: writer.endElement("img");
129: }
130: writer.endElement("a");
131: writer.endElement("div");
132: writer.endElement("td");
133: writer.endElement("tr");
134: writer.endElement("table");
135:
136: writer.endElement("td");
137: writer.endElement("tr");
138: }
139:
140: private void startBareTable(ResponseWriter writer)
141: throws IOException {
142: writer.startElement("table", null);
143: writer.writeAttribute("border", "0", null);
144: writer.writeAttribute("cellspacing", "0", null);
145: writer.writeAttribute("cellpadding", "0", null);
146: }
147:
148: public void encodeEnd(FacesContext context) throws IOException {
149: ResponseWriter writer = context.getResponseWriter();
150: writer.endElement("table");
151: writer.endElement("div");
152: writer.flush();
153: return;
154: }
155:
156: protected void renderRowChildren(FacesContext context)
157: throws IOException {
158: List children = getChildren();
159: if (children.size() > 0) {
160: ResponseWriter writer = context.getResponseWriter();
161: writer.startElement("tr", null);
162: if (dataRowClass != null) {
163: writer.writeAttribute("class", dataRowClass,
164: "dataRowClass");
165: }
166: for (Iterator iter = children.iterator(); iter.hasNext();) {
167: writer.startElement("td", null);
168: encodeRecursive(context, (UIComponent) iter.next());
169: writer.endElement("td");
170: }
171: writer.endElement("tr");
172: }
173: }
174:
175: public String getPopupId() {
176: return getFieldOrBinding(popupId, "popupId").toString();
177: }
178:
179: public void setPopupId(String popupId) {
180: this .popupId = popupId;
181: }
182:
183: public Integer getNumberOfColumns() {
184: return (Integer) getFieldOrBinding(numberOfColumns, "columns");
185: }
186:
187: public void setNumberOfColumns(Integer numberOfColumns) {
188: this .numberOfColumns = numberOfColumns;
189: }
190:
191: public String getTitleText() {
192: return (String) getFieldOrBinding(titleText, "titleText");
193: }
194:
195: public void setTitleText(String titleText) {
196: this .titleText = titleText;
197: }
198:
199: public String getCloseIconUrl() {
200: return (String) getFieldOrBinding(closeIconUrl, "closeIconUrl");
201: }
202:
203: public void setCloseIconUrl(String closeIconUrl) {
204: this .closeIconUrl = closeIconUrl;
205: }
206:
207: public void setStyleClass(String styleClass) {
208: this .styleClass = styleClass;
209: }
210:
211: public void setTitleBarClass(String titleBarClass) {
212: this .titleBarClass = titleBarClass;
213: }
214:
215: public void setCloseClass(String closeClass) {
216: this .closeClass = closeClass;
217: }
218:
219: public void setDataRowClass(String dataRowClass) {
220: this .dataRowClass = dataRowClass;
221: }
222:
223: public Object saveState(FacesContext context) {
224: Object values[] = new Object[9];
225: values[0] = super .saveState(context);
226: values[1] = popupId;
227: values[2] = titleText;
228: values[3] = numberOfColumns;
229: values[4] = styleClass;
230: values[5] = titleBarClass;
231: values[6] = closeClass;
232: values[7] = closeIconUrl;
233: values[8] = dataRowClass;
234: return values;
235: }
236:
237: public void restoreState(FacesContext context, Object state) {
238: Object values[] = (Object[]) state;
239: super .restoreState(context, values[0]);
240: popupId = (String) values[1];
241: titleText = (String) values[2];
242: numberOfColumns = (Integer) values[3];
243: styleClass = (String) values[4];
244: titleBarClass = (String) values[5];
245: closeClass = (String) values[6];
246: closeIconUrl = (String) values[7];
247: dataRowClass = (String) values[8];
248: }
249: }
|