You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jl...@apache.org on 2007/06/19 01:16:18 UTC
svn commit: r548528 [1/4] - in /myfaces/tomahawk/trunk/core: ./
src/main/java/org/apache/myfaces/custom/schedule/
src/main/java/org/apache/myfaces/custom/schedule/renderer/
src/main/java/org/apache/myfaces/custom/schedule/util/
src/main/resources-faces...
Author: jlust
Date: Mon Jun 18 16:16:17 2007
New Revision: 548528
URL: http://svn.apache.org/viewvc?view=rev&rev=548528
Log:
refactoring of the schedule component to make it more maintainable and to improve compatibility with Facelets.
Added:
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractCompactScheduleRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractScheduleRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/DefaultScheduleEntryRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactMonthRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactWeekRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDelegatingRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDetailedDayRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleEntryRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/UIScheduleBase.java
Removed:
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/renderer/
Modified:
myfaces/tomahawk/trunk/core/pom.xml
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/HtmlSchedule.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleTag.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/UISchedule.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleUtil.java
myfaces/tomahawk/trunk/core/src/main/resources-facesconfig/META-INF/faces-config.xml
myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/schedule/HtmlSchedule.xml
myfaces/tomahawk/trunk/core/src/main/tld/tomahawk-entities/tomahawk_html_schedule_attributes.xml
myfaces/tomahawk/trunk/core/src/main/tld/tomahawk-entities/tomahawk_ui_schedule_attributes.xml
myfaces/tomahawk/trunk/core/src/main/tld/tomahawk.tld
myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/test/utils/TestUtils.java
Modified: myfaces/tomahawk/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/pom.xml?view=diff&rev=548528&r1=548527&r2=548528
==============================================================================
--- myfaces/tomahawk/trunk/core/pom.xml (original)
+++ myfaces/tomahawk/trunk/core/pom.xml Mon Jun 18 16:16:17 2007
@@ -28,6 +28,7 @@
<version>1.0.4</version>
<scope>compile</scope>
</dependency>
+
<dependency>
<groupId>commons-validator</groupId>
Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractCompactScheduleRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractCompactScheduleRenderer.java?view=auto&rev=548528
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractCompactScheduleRenderer.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractCompactScheduleRenderer.java Mon Jun 18 16:16:17 2007
@@ -0,0 +1,383 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.custom.schedule;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.custom.schedule.model.ScheduleDay;
+import org.apache.myfaces.custom.schedule.model.ScheduleEntry;
+import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.*;
+
+/**
+ * <p>
+ * Abstract superclass for the week and month view renderers.
+ * </p>
+ *
+ * @author Jurgen Lust (latest modification by $Author: jlust $)
+ * @author Bruno Aranda (adaptation of Jurgen's code to myfaces)
+ * @version $Revision: 398348 $
+ */
+public abstract class AbstractCompactScheduleRenderer extends
+ AbstractScheduleRenderer implements Serializable
+{
+ private static final Log log = LogFactory.getLog(AbstractCompactScheduleRenderer.class);
+
+ // ~ Methods
+ // ----------------------------------------------------------------
+
+ /**
+ * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void encodeChildren(FacesContext context, UIComponent component)
+ throws IOException
+ {
+ // the children are rendered in the encodeBegin phase
+ }
+
+ /**
+ * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void encodeEnd(FacesContext context, UIComponent component)
+ throws IOException
+ {
+ // all rendering is done in the begin phase
+ }
+
+ /**
+ * @return The default height, in pixels, of one row in the schedule grid
+ */
+ protected abstract int getDefaultRowHeight();
+
+ /**
+ * <p>
+ * Draw one day in the schedule
+ * </p>
+ *
+ * @param context
+ * the FacesContext
+ * @param writer
+ * the ResponseWriter
+ * @param schedule
+ * the schedule
+ * @param day
+ * the day that should be drawn
+ * @param cellWidth
+ * the width of the cell
+ * @param dayOfWeek
+ * the day of the week
+ * @param dayOfMonth
+ * the day of the month
+ * @param isWeekend
+ * is it a weekend day?
+ * @param isCurrentMonth
+ * is the day in the currently selected month?
+ * @param rowspan
+ * the rowspan for the table cell
+ *
+ * @throws IOException
+ * when the cell could not be drawn
+ */
+ protected void writeDayCell(FacesContext context, ResponseWriter writer,
+ HtmlSchedule schedule, ScheduleDay day, float cellWidth,
+ int dayOfWeek, int dayOfMonth, boolean isWeekend,
+ boolean isCurrentMonth, int rowspan) throws IOException
+ {
+ final String clientId = schedule.getClientId(context);
+ final Map attributes = schedule.getAttributes();
+ final FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context);
+ final String formId = parentFormInfo == null ? null : parentFormInfo.getFormName();
+ final String dayHeaderId = clientId + "_header_" + ScheduleUtil.getDateId(day.getDate());
+ final String dayBodyId = clientId + "_body_" + ScheduleUtil.getDateId(day.getDate());
+ writer.startElement(HTML.TD_ELEM, schedule);
+
+ writer.writeAttribute("rowspan", String.valueOf(rowspan), null);
+
+ String dayClass = getStyleClass(schedule, isCurrentMonth ? "day" : "inactive-day") +
+ " " + getStyleClass(schedule, isWeekend ? "weekend" : "workday");
+
+ writer.writeAttribute(HTML.CLASS_ATTR, dayClass, null);
+
+ // determine the height of the day in pixels
+ StringBuffer styleBuffer = new StringBuffer();
+
+ int rowHeight = getRowHeight(schedule);
+ String myRowHeight = "height: ";
+ String myContentHeight = "height: ";
+
+ if (rowHeight > 0)
+ {
+ if (isWeekend)
+ {
+ myRowHeight += (rowHeight / 2) + "px;";
+ myContentHeight += ((rowHeight / 2) - 19) + "px;";
+ }
+ else
+ {
+ myRowHeight += (rowHeight + 1) + "px;"; //need to add 1 to get the weekends right
+ myContentHeight += ((rowHeight + 1) - 18) + "px;"; //18 instead of 19, to get the weekends right
+ }
+ }
+ else
+ {
+ myRowHeight += "100%;";
+ myContentHeight += "100%;";
+ }
+
+ styleBuffer.append(myRowHeight);
+
+ writer.writeAttribute(HTML.STYLE_ATTR, styleBuffer.toString()
+ + " width: " + cellWidth + "%;", null);
+
+ writer.startElement(HTML.TABLE_ELEM, schedule);
+
+ writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "day"),
+ null);
+ writer.writeAttribute(HTML.STYLE_ATTR, styleBuffer.toString()
+ + " width: 100%;", null);
+
+ writer.writeAttribute(HTML.CELLPADDING_ATTR, "0", null);
+ writer.writeAttribute(HTML.CELLSPACING_ATTR, "0", null);
+
+ // day header
+ writer.startElement(HTML.TR_ELEM, schedule);
+ writer.startElement(HTML.TD_ELEM, schedule);
+ writer.writeAttribute(HTML.CLASS_ATTR,
+ getStyleClass(schedule, "header"), null);
+ writer.writeAttribute(HTML.STYLE_ATTR,
+ "height: 18px; width: 100%; overflow: hidden", null);
+ writer.writeAttribute(HTML.ID_ATTR, dayHeaderId, null);
+ //register an onclick event listener to a day header which will capture
+ //the date
+ if (!schedule.isReadonly() && schedule.isSubmitOnClick()) {
+ writer.writeAttribute(
+ HTML.ONMOUSEUP_ATTR,
+ "fireScheduleDateClicked(this, event, '"
+ + formId + "', '"
+ + clientId
+ + "');",
+ null);
+ }
+
+
+
+ writer.writeText(getDateString(context, schedule, day.getDate()), null);
+ writer.endElement(HTML.TD_ELEM);
+ writer.endElement(HTML.TR_ELEM);
+
+ // day content
+ writer.startElement(HTML.TR_ELEM, schedule);
+ writer.startElement(HTML.TD_ELEM, schedule);
+
+ writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
+ "content"), null);
+
+ // determine the height of the day content in pixels
+ StringBuffer contentStyleBuffer = new StringBuffer();
+ contentStyleBuffer.append(myContentHeight);
+ contentStyleBuffer.append(" width: 100%;");
+ writer.writeAttribute(HTML.STYLE_ATTR, contentStyleBuffer.toString(),
+ null);
+
+ writer.startElement(HTML.DIV_ELEM, schedule);
+ writer.writeAttribute(HTML.CLASS_ATTR,
+ getStyleClass(schedule, "contentview"), null);
+ writer
+ .writeAttribute(
+ HTML.STYLE_ATTR,
+ "width: 100%; height: 100%; overflow: auto; vertical-align: top;",
+ null);
+
+ //this extra div is required, because when a scrollbar is visible and
+ //it is clicked, the fireScheduleTimeClicked() method is fired.
+ writer.startElement(HTML.DIV_ELEM, schedule);
+ writer
+ .writeAttribute(
+ HTML.STYLE_ATTR,
+ "width: 100%; height: 100%; vertical-align: top;",
+ null);
+
+ writer.writeAttribute(HTML.ID_ATTR, dayBodyId, null);
+
+ //register an onclick event listener to a day cell which will capture
+ //the date
+ if (!schedule.isReadonly() && schedule.isSubmitOnClick()) {
+ writer.writeAttribute(
+ HTML.ONMOUSEUP_ATTR,
+ "fireScheduleTimeClicked(this, event, '"
+ + formId + "', '"
+ + clientId
+ + "');",
+ null);
+ }
+
+ writer.startElement(HTML.TABLE_ELEM, schedule);
+ writer.writeAttribute(HTML.STYLE_ATTR, "width: 100%;", null);
+
+ writeEntries(context, schedule, day, writer);
+
+ writer.endElement(HTML.TABLE_ELEM);
+ writer.endElement(HTML.DIV_ELEM);
+ writer.endElement(HTML.DIV_ELEM);
+ writer.endElement(HTML.TD_ELEM);
+ writer.endElement(HTML.TR_ELEM);
+ writer.endElement(HTML.TABLE_ELEM);
+ writer.endElement(HTML.TD_ELEM);
+ }
+
+ /**
+ * <p>
+ * Draw the schedule entries in the specified day cell
+ * </p>
+ *
+ * @param context
+ * the FacesContext
+ * @param schedule
+ * the schedule
+ * @param day
+ * the day
+ * @param writer
+ * the ResponseWriter
+ *
+ * @throws IOException
+ * when the entries could not be drawn
+ */
+ protected void writeEntries(FacesContext context, HtmlSchedule schedule,
+ ScheduleDay day, ResponseWriter writer) throws IOException
+ {
+ final String clientId = schedule.getClientId(context);
+ final FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context);
+ final String formId = parentFormInfo == null ? null : parentFormInfo.getFormName();
+ final TreeSet entrySet = new TreeSet(comparator);
+
+ for (Iterator entryIterator = day.iterator(); entryIterator.hasNext();)
+ {
+ ScheduleEntry entry = (ScheduleEntry) entryIterator.next();
+ entrySet.add(entry);
+ }
+
+ for (Iterator entryIterator = entrySet.iterator(); entryIterator
+ .hasNext();)
+ {
+ ScheduleEntry entry = (ScheduleEntry) entryIterator.next();
+ writer.startElement(HTML.TR_ELEM, schedule);
+ writer.startElement(HTML.TD_ELEM, schedule);
+
+ if (isSelected(schedule, entry))
+ {
+ writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
+ "selected"), null);
+ }
+
+ //compose the CSS style for the entry box
+ StringBuffer entryStyle = new StringBuffer();
+ entryStyle.append("width: 100%;");
+ String entryColor = getEntryRenderer(schedule).getColor(context, schedule, entry, isSelected(schedule, entry));
+ if (isSelected(schedule, entry) && entryColor != null) {
+ entryStyle.append(" background-color: ");
+ entryStyle.append(entryColor);
+ entryStyle.append(";");
+ entryStyle.append(" border-color: ");
+ entryStyle.append(entryColor);
+ entryStyle.append(";");
+ }
+
+ writer.writeAttribute(HTML.STYLE_ATTR, entryStyle.toString(), null);
+
+ // draw the tooltip
+ if (schedule.isTooltip())
+ {
+ getEntryRenderer(schedule).renderToolTip(context, writer,
+ schedule, entry, isSelected(schedule, entry));
+ }
+
+ if (!isSelected(schedule, entry) && !schedule.isReadonly())
+ {
+ writer.startElement("a", schedule);
+ writer.writeAttribute("href", "#", null);
+
+ writer.writeAttribute(
+ HTML.ONMOUSEUP_ATTR,
+ "fireEntrySelected('"
+ + formId + "', '"
+ + clientId + "', '"
+ + entry.getId()
+ + "');",
+ null);
+ }
+
+ // draw the content
+ getEntryRenderer(schedule).renderContent(context, writer, schedule,
+ day, entry, true, isSelected(schedule, entry));
+
+ if (!isSelected(schedule, entry) && !schedule.isReadonly())
+ {
+ writer.endElement("a");
+ }
+
+ writer.endElement(HTML.TD_ELEM);
+ writer.endElement(HTML.TR_ELEM);
+ }
+ }
+
+ private boolean isSelected(HtmlSchedule schedule, ScheduleEntry entry)
+ {
+ ScheduleEntry selectedEntry = schedule.getModel().getSelectedEntry();
+
+ if (selectedEntry == null)
+ {
+ return false;
+ }
+
+ return selectedEntry.getId().equals(entry.getId());
+ }
+
+ /**
+ * In the compact renderer, we don't take the y coordinate of the mouse
+ * into account when determining the last clicked date.
+ */
+ protected Date determineLastClickedDate(HtmlSchedule schedule, String dateId, String yPos) {
+ Calendar cal = GregorianCalendar.getInstance();
+ //the dateId is the schedule client id + "_" + yyyyMMdd
+ String day = dateId.substring(dateId.lastIndexOf("_") + 1);
+ Date date = ScheduleUtil.getDateFromId(day);
+
+ if (date != null) cal.setTime(date);
+ cal.set(Calendar.HOUR_OF_DAY, schedule.getVisibleStartHour());
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+ log.debug("last clicked datetime: " + cal.getTime());
+ return cal.getTime();
+ }
+
+}
+// The End
Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractScheduleRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractScheduleRenderer.java?view=auto&rev=548528
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractScheduleRenderer.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/AbstractScheduleRenderer.java Mon Jun 18 16:16:17 2007
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.custom.schedule;
+
+import org.apache.myfaces.custom.schedule.model.ScheduleEntry;
+import org.apache.myfaces.custom.schedule.util.ScheduleEntryComparator;
+import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
+import org.apache.myfaces.renderkit.html.util.AddResource;
+import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.el.ValueBinding;
+import javax.faces.event.ActionEvent;
+import javax.faces.render.Renderer;
+import java.io.IOException;
+import java.io.Serializable;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * <p>
+ * Abstract superclass for all renderer of the UISchedule component
+ * </p>
+ *
+ * @author Jurgen Lust (latest modification by $Author: mkienenb $)
+ * @author Bruno Aranda (adaptation of Jurgen's code to myfaces)
+ * @version $Revision: 389938 $
+ */
+public abstract class AbstractScheduleRenderer extends Renderer implements
+ Serializable
+{
+ //~ Static fields/initializers ---------------------------------------------
+ protected static final ScheduleEntryComparator comparator = new ScheduleEntryComparator();
+ protected static final String LAST_CLICKED_DATE = "_last_clicked_date";
+ protected static final String LAST_CLICKED_Y = "_last_clicked_y";
+ private static final String CSS_RESOURCE = "css/schedule.css";
+ public static final String DEFAULT_THEME = "default";
+ public static final String OUTLOOK_THEME = "outlookxp";
+ public static final String EVOLUTION_THEME = "evolution";
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * @see javax.faces.render.Renderer#decode(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void decode(FacesContext context, UIComponent component)
+ {
+ HtmlSchedule schedule = (HtmlSchedule) component;
+ boolean queueAction = false;
+ if (ScheduleUtil.canModifyValue(component))
+ {
+ Map parameters = context.getExternalContext()
+ .getRequestParameterMap();
+ String selectedEntryId = (String) parameters.get((String) schedule
+ .getClientId(context));
+ String lastClickedDateId = (String) parameters
+ .get((String) schedule.getClientId(context)
+ + LAST_CLICKED_DATE);
+ String lastClickedY = (String) parameters.get((String) schedule
+ .getClientId(context)
+ + LAST_CLICKED_Y);
+
+ ScheduleMouseEvent mouseEvent = null;
+
+ if ((selectedEntryId != null) && (selectedEntryId.length() > 0))
+ {
+ ScheduleEntry entry = schedule.findEntry(selectedEntryId);
+ schedule.setSubmittedEntry(entry);
+ mouseEvent = new ScheduleMouseEvent(schedule,
+ ScheduleMouseEvent.SCHEDULE_ENTRY_CLICKED);
+ queueAction = true;
+ }
+
+ if (schedule.isSubmitOnClick())
+ {
+ schedule.resetMouseEvents();
+ if ((lastClickedY != null) && (lastClickedY.length() > 0))
+ {
+ //the body of the schedule was clicked
+ schedule
+ .setLastClickedDateAndTime(determineLastClickedDate(
+ schedule, lastClickedDateId, lastClickedY));
+ mouseEvent = new ScheduleMouseEvent(schedule,
+ ScheduleMouseEvent.SCHEDULE_BODY_CLICKED);
+ queueAction = true;
+ }
+ else if ((lastClickedDateId != null)
+ && (lastClickedDateId.length() > 0))
+ {
+ //the header of the schedule was clicked
+ schedule
+ .setLastClickedDateAndTime(determineLastClickedDate(
+ schedule, lastClickedDateId, "0"));
+ mouseEvent = new ScheduleMouseEvent(schedule,
+ ScheduleMouseEvent.SCHEDULE_HEADER_CLICKED);
+ queueAction = true;
+ }
+ else if (mouseEvent == null)
+ {
+ //the form was posted without mouse events on the schedule
+ mouseEvent = new ScheduleMouseEvent(schedule,
+ ScheduleMouseEvent.SCHEDULE_NOTHING_CLICKED);
+ }
+ }
+
+ if (mouseEvent != null)
+ schedule.queueEvent(mouseEvent);
+ }
+ if (queueAction)
+ {
+ schedule.queueEvent(new ActionEvent(schedule));
+ }
+ }
+
+ /**
+ * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void encodeBegin(FacesContext context, UIComponent component)
+ throws IOException
+ {
+ if (!component.isRendered())
+ {
+ return;
+ }
+
+ HtmlSchedule schedule = (HtmlSchedule) component;
+ ResponseWriter writer = context.getResponseWriter();
+
+ //add needed CSS and Javascript files to the header
+
+ AddResource addResource = AddResourceFactory.getInstance(context);
+ String theme = schedule.getTheme();
+ //The default css file is only loaded if the theme is one of the provided
+ //themes.
+ if (DEFAULT_THEME.equals(theme) || OUTLOOK_THEME.equals(theme)
+ || EVOLUTION_THEME.equals(theme))
+ {
+ addResource.addStyleSheet(context, AddResource.HEADER_BEGIN,
+ HtmlSchedule.class, CSS_RESOURCE);
+ }
+ addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN,
+ HtmlSchedule.class, "javascript/schedule.js");
+ addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN,
+ HtmlSchedule.class, "javascript/alphaAPI.js");
+ addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN,
+ HtmlSchedule.class, "javascript/domLib.js");
+ addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN,
+ HtmlSchedule.class, "javascript/domTT.js");
+ addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN,
+ HtmlSchedule.class, "javascript/fadomatic.js");
+
+ //hidden input field containing the id of the selected entry
+ writer.startElement(HTML.INPUT_ELEM, schedule);
+ writer.writeAttribute(HTML.TYPE_ATTR, "hidden", null);
+ writer.writeAttribute(HTML.NAME_ATTR, schedule.getClientId(context),
+ "clientId");
+ writer.endElement(HTML.INPUT_ELEM);
+ //hidden input field containing the id of the last clicked date
+ writer.startElement(HTML.INPUT_ELEM, schedule);
+ writer.writeAttribute(HTML.TYPE_ATTR, "hidden", null);
+ writer.writeAttribute(HTML.NAME_ATTR, schedule.getClientId(context)
+ + "_last_clicked_date", "clicked_date");
+ writer.endElement(HTML.INPUT_ELEM);
+ //hidden input field containing the y coordinate of the mouse when
+ //the schedule was clicked. This will be used to determine the hour
+ //of day.
+ writer.startElement(HTML.INPUT_ELEM, schedule);
+ writer.writeAttribute(HTML.TYPE_ATTR, "hidden", null);
+ writer.writeAttribute(HTML.NAME_ATTR, schedule.getClientId(context)
+ + "_last_clicked_y", "clicked_y");
+ writer.endElement(HTML.INPUT_ELEM);
+ }
+
+ /**
+ * <p>
+ * Get the String representation of a date, taking into account the
+ * specified date format or the current Locale.
+ * </p>
+ *
+ * @param context the FacesContext
+ * @param schedule the component
+ * @param date the date
+ *
+ * @return the date string
+ */
+ protected String getDateString(FacesContext context, UIScheduleBase schedule,
+ Date date)
+ {
+ DateFormat format;
+ String pattern = schedule.getHeaderDateFormat();
+ Locale viewLocale = context.getViewRoot().getLocale();
+
+ if ((pattern != null) && (pattern.length() > 0))
+ {
+ format = new SimpleDateFormat(pattern, viewLocale);
+ }
+ else
+ {
+ format = DateFormat.getDateInstance(DateFormat.MEDIUM, viewLocale);
+ }
+
+ return format.format(date);
+ }
+
+ /**
+ * <p>
+ * Allow the developer to specify custom CSS classnames for the schedule
+ * component.
+ * </p>
+ * @param component the component
+ * @param className the default CSS classname
+ * @return the custom classname
+ */
+ protected String getStyleClass(UIComponent component, String className)
+ {
+ //first check if the styleClass property is a value binding expression
+ ValueBinding binding = component.getValueBinding(className);
+ if (binding != null)
+ {
+ String value = (String) binding.getValue(FacesContext
+ .getCurrentInstance());
+
+ if (value != null)
+ {
+ return value;
+ }
+ }
+ //it's not a value binding expression, so check for the string value
+ //in the attributes
+ Map attributes = component.getAttributes();
+ String returnValue = (String) attributes.get(className);
+ return returnValue == null ? className : returnValue;
+ }
+
+ /**
+ * The user of the Schedule component can customize the look and feel
+ * by specifying a custom implementation of the ScheduleEntryRenderer.
+ * This method gets an instance of the specified class, or if none
+ * was specified, takes the default.
+ *
+ * @param component the Schedule component
+ * @return a ScheduleEntryRenderer instance
+ */
+ protected ScheduleEntryRenderer getEntryRenderer(HtmlSchedule schedule)
+ {
+ Object entryRenderer = schedule.getEntryRenderer();
+ if (entryRenderer instanceof ScheduleEntryRenderer)
+ {
+ return (ScheduleEntryRenderer) entryRenderer;
+ } else {
+ return new DefaultScheduleEntryRenderer();
+ }
+ }
+
+ /**
+ * @return The default height, in pixels, of one row in the schedule grid
+ */
+ protected abstract int getDefaultRowHeight();
+
+ /**
+ * @param schedule
+ * The schedule
+ *
+ * @return The row height, in pixels
+ */
+ protected abstract int getRowHeight(UIScheduleBase schedule);
+
+ /**
+ * Determine the last clicked date
+ * @param schedule the schedule component
+ * @param dateId the string identifying the date
+ * @param yPos the y coordinate of the mouse
+ * @return the clicked date
+ */
+ protected abstract Date determineLastClickedDate(HtmlSchedule schedule,
+ String dateId, String yPos);
+
+ /**
+ * @see javax.faces.render.Renderer#getRendersChildren()
+ */
+ public boolean getRendersChildren()
+ {
+ return true;
+ }
+}
+//The End
Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/DefaultScheduleEntryRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/DefaultScheduleEntryRenderer.java?view=auto&rev=548528
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/DefaultScheduleEntryRenderer.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/DefaultScheduleEntryRenderer.java Mon Jun 18 16:16:17 2007
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.custom.schedule;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.el.ValueBinding;
+
+import org.apache.myfaces.custom.schedule.model.ScheduleDay;
+import org.apache.myfaces.custom.schedule.model.ScheduleEntry;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+
+/**
+ * The default implementation of the ScheduleEntryRenderer
+ *
+ * @author Jurgen Lust (latest modification by $Author$)
+ * @version $Revision$
+ */
+public class DefaultScheduleEntryRenderer implements ScheduleEntryRenderer,
+ Serializable
+{
+ private static final long serialVersionUID = 4987926168243581739L;
+
+ /**
+ * @see org.apache.myfaces.custom.schedule.ScheduleEntryRenderer#renderContent(javax.faces.context.FacesContext, javax.faces.context.ResponseWriter, org.apache.myfaces.custom.schedule.HtmlSchedule, org.apache.myfaces.custom.schedule.model.ScheduleDay, org.apache.myfaces.custom.schedule.model.ScheduleEntry, boolean, boolean)
+ */
+ public void renderContent(FacesContext context, ResponseWriter writer,
+ HtmlSchedule schedule, ScheduleDay day, ScheduleEntry entry,
+ boolean compact, boolean selected) throws IOException
+ {
+ if (compact)
+ {
+ renderCompactContent(context, writer, schedule, day, entry, selected);
+ } else
+ {
+ if (selected)
+ {
+ StringBuffer entryStyle = new StringBuffer();
+ entryStyle.append("height: 100%; width: 100%;");
+ //the left border of a selected entry should have the same
+ //color as the entry border
+ String entryColor = getColor(context, schedule, entry, selected);
+ if (entryColor != null) {
+ entryStyle.append("border-color: ");
+ entryStyle.append(entryColor);
+ entryStyle.append(";");
+ }
+ // draw the contents of the selected entry
+ writer.startElement(HTML.DIV_ELEM, null);
+ writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
+ "text"), null);
+ writer.writeAttribute(HTML.STYLE_ATTR,entryStyle.toString(), null);
+
+ renderDetailedContentText(context, writer, schedule, day, entry, selected);
+
+ writer.endElement(HTML.DIV_ELEM);
+ } else
+ {
+ renderDetailedContentText(context, writer, schedule, day, entry, selected);
+ }
+ }
+
+ }
+
+ protected void renderCompactContent(FacesContext context, ResponseWriter writer, HtmlSchedule schedule, ScheduleDay day, ScheduleEntry entry, boolean selected) throws IOException
+ {
+ StringBuffer text = new StringBuffer();
+ Date startTime = entry.getStartTime();
+
+ if (day.getDayStart().after(entry.getStartTime()))
+ {
+ startTime = day.getDayStart();
+ }
+
+ Date endTime = entry.getEndTime();
+
+ if (day.getDayEnd().before(entry.getEndTime()))
+ {
+ endTime = day.getDayEnd();
+ }
+
+ if (!entry.isAllDay())
+ {
+ DateFormat format = DateFormat.getTimeInstance(DateFormat.SHORT);
+ text.append(format.format(startTime));
+ if (!startTime.equals(endTime)) {
+ text.append("-");
+ text.append(format.format(endTime));
+ }
+ text.append(": ");
+ }
+ text.append(entry.getTitle());
+
+ writer.writeText(text.toString(), null);
+ }
+
+ protected void renderDetailedContentText(FacesContext context, ResponseWriter writer,
+ HtmlSchedule schedule, ScheduleDay day, ScheduleEntry entry, boolean selected) throws IOException
+ {
+ // write the title of the entry
+ if (entry.getTitle() != null)
+ {
+ writer.startElement(HTML.SPAN_ELEM, schedule);
+ writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(
+ schedule, "title"), null);
+ writer.writeText(entry.getTitle(), null);
+ writer.endElement(HTML.SPAN_ELEM);
+ }
+ if (entry.getSubtitle() != null)
+ {
+ writer.startElement("br", schedule);
+ writer.endElement("br");
+ writer.startElement(HTML.SPAN_ELEM, schedule);
+ writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(
+ schedule, "subtitle"), null);
+ writer.writeText(entry.getSubtitle(), null);
+ writer.endElement(HTML.SPAN_ELEM);
+ }
+ }
+
+ /**
+ * @see org.apache.myfaces.custom.schedule.ScheduleEntryRenderer#getColor(javax.faces.context.FacesContext, org.apache.myfaces.custom.schedule.HtmlSchedule, org.apache.myfaces.custom.schedule.model.ScheduleEntry, boolean)
+ */
+ public String getColor(FacesContext context, HtmlSchedule schedule,
+ ScheduleEntry entry, boolean selected)
+ {
+ return null;
+ }
+
+ /**
+ * @see org.apache.myfaces.custom.schedule.ScheduleEntryRenderer#renderToolTip(javax.faces.context.FacesContext, javax.faces.context.ResponseWriter, org.apache.myfaces.custom.schedule.HtmlSchedule, org.apache.myfaces.custom.schedule.model.ScheduleEntry, boolean)
+ */
+ public void renderToolTip(FacesContext context, ResponseWriter writer,
+ HtmlSchedule schedule, ScheduleEntry entry, boolean selected)
+ throws IOException
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer
+ .append("return makeTrue(domTT_activate(this, event, 'caption', '");
+
+ if (entry.getTitle() != null)
+ {
+ buffer.append(escape(entry.getTitle()));
+ }
+
+ buffer.append("', 'content', '<i>");
+
+ if (entry.getSubtitle() != null)
+ {
+ buffer.append(escape(entry.getSubtitle()));
+ }
+
+ buffer.append("</i>");
+
+ if (entry.getDescription() != null)
+ {
+ buffer.append("<br/>");
+ buffer.append(escape(entry.getDescription()));
+ }
+
+ buffer.append("', 'trail', true));");
+ writer.writeAttribute("onmouseover", buffer.toString(), null);
+ }
+
+ private String escape(String text)
+ {
+ if (text == null)
+ {
+ return null;
+ }
+
+ return text.replaceAll("'", "\\\\\'").replaceAll("\n", "\\\\n").replaceAll("\r", "\\\\r");
+ }
+
+ /**
+ * <p>
+ * Allow the developer to specify custom CSS classnames for the schedule
+ * component.
+ * </p>
+ *
+ * @param component
+ * the component
+ * @param className
+ * the default CSS classname
+ * @return the custom classname
+ */
+ protected String getStyleClass(UIComponent component, String className)
+ {
+ // first check if the styleClass property is a value binding expression
+ ValueBinding binding = component.getValueBinding(className);
+ if (binding != null)
+ {
+ String value = (String) binding.getValue(FacesContext
+ .getCurrentInstance());
+
+ if (value != null)
+ {
+ return value;
+ }
+ }
+ // it's not a value binding expression, so check for the string value
+ // in the attributes
+ Map attributes = component.getAttributes();
+ String returnValue = (String) attributes.get(className);
+ return returnValue == null ? className : returnValue;
+ }
+
+}
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/HtmlSchedule.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/HtmlSchedule.java?view=diff&rev=548528&r1=548527&r2=548528
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/HtmlSchedule.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/HtmlSchedule.java Mon Jun 18 16:16:17 2007
@@ -20,245 +20,541 @@
package org.apache.myfaces.custom.schedule;
import java.io.Serializable;
-import java.util.Date;
import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
-import javax.faces.el.ValueBinding;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.PhaseId;
import org.apache.myfaces.component.UserRoleAware;
import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
-import org.apache.myfaces.shared_tomahawk.util._ComponentUtils;
/**
+ * This class holds all properties specific to the HTML version of the Schedule component.
*
* @author Bruno Aranda (latest modification by $Author: jlust $)
* @author Jurgen Lust
+ *
* @version $Revision: 392301 $
*/
public class HtmlSchedule extends UISchedule implements UserRoleAware,
Serializable
{
- public static final String COMPONENT_FAMILY = "javax.faces.Panel";
-
- public static final String COMPONENT_TYPE = "org.apache.myfaces.Schedule";
- private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Schedule";
private static final long serialVersionUID = 5859593107442371656L;
- // ------------------ GENERATED CODE BEGIN (do not modify!) --------------------
+ //UserRoleAware properties
private String _enabledOnUserRole = null;
- private Date _lastClickedDateAndTime = null;
- private MethodBinding _mouseListener = null;
- private Boolean _submitOnClick = null;
private String _visibleOnUserRole = null;
+ //CSS style classes
+ private String _backgroundClass;
+ private String _columnClass;
+ private String _contentClass;
+ private String _dateClass;
+ private String _dayClass;
+ private String _entryClass;
+ private Object _entryRenderer;
+ private String _evenClass;
+ private String _foregroundClass;
+ private String _freeClass;
+ private String _gutterClass;
+ private String _headerClass;
+ private String _holidayClass;
+ private String _hoursClass;
+ private String _inactiveDayClass;
+ private String _minutesClass;
+ private String _monthClass;
+ private String _selectedClass;
+ private String _selectedEntryClass;
+ private String _subtitleClass;
+ private String _textClass;
+ private String _titleClass;
+ private String _unevenClass;
+ private String _weekClass;
- public HtmlSchedule()
+ /**
+ * @return the _enabledOnUserRole
+ */
+ public String getEnabledOnUserRole()
{
- setRendererType(DEFAULT_RENDERER_TYPE);
+ return ScheduleUtil.getStringProperty(this, _enabledOnUserRole, "enabledOnUserRole", DEFAULT_ENABLED_ON_USER_ROLE);
}
/**
- * @see javax.faces.component.UIComponent#broadcast(javax.faces.event.FacesEvent)
+ * @return the _visibleOnUserRole
*/
- public void broadcast(FacesEvent event) throws AbortProcessingException
+ public String getVisibleOnUserRole()
{
- // First invoke the mouse listener, before any other listener
- if (event instanceof ScheduleMouseEvent)
- {
- FacesContext context = getFacesContext();
- ScheduleMouseEvent mouseEvent = (ScheduleMouseEvent) event;
- MethodBinding mouseListenerBinding = getMouseListener();
+ return ScheduleUtil.getStringProperty(this, _visibleOnUserRole, "visibleOnUserRole", DEFAULT_VISIBLE_ON_USER_ROLE);
+ }
- if (mouseListenerBinding != null)
- {
- mouseListenerBinding.invoke(context,
- new Object[] { mouseEvent });
- }
- }
- //now invoke the other listeners
- super.broadcast(event);
+ /**
+ * @see org.apache.myfaces.custom.schedule.UISchedule#restoreState(javax.faces.context.FacesContext, java.lang.Object)
+ */
+ public void restoreState(FacesContext context, Object state)
+ {
+ Object[] values = (Object[]) state;
+ super.restoreState(context, values[0]);
+ _enabledOnUserRole = (String)values[1];
+ _visibleOnUserRole = (String)values[2];
+ _backgroundClass = (String)values[3];
+ _columnClass = (String)values[4];
+ _contentClass = (String)values[5];
+ _dateClass = (String)values[6];
+ _dayClass = (String)values[7];
+ _entryClass = (String)values[8];
+ _entryRenderer = (Object)values[9];
+ _evenClass = (String)values[10];
+ _foregroundClass = (String)values[11];
+ _freeClass = (String)values[12];
+ _gutterClass = (String)values[13];
+ _headerClass = (String)values[14];
+ _holidayClass = (String)values[15];
+ _hoursClass = (String)values[16];
+ _inactiveDayClass = (String)values[17];
+ _minutesClass = (String)values[18];
+ _monthClass = (String)values[19];
+ _selectedClass = (String)values[20];
+ _selectedEntryClass = (String)values[21];
+ _subtitleClass = (String)values[22];
+ _textClass = (String)values[23];
+ _titleClass = (String)values[24];
+ _unevenClass = (String)values[25];
+ _weekClass = (String)values[26];
}
/**
- * @see org.apache.myfaces.component.UserRoleAware#getEnabledOnUserRole()
+ * @see org.apache.myfaces.custom.schedule.UISchedule#saveState(javax.faces.context.FacesContext)
*/
- public String getEnabledOnUserRole()
+ public Object saveState(FacesContext context)
{
- if (_enabledOnUserRole != null)
- return _enabledOnUserRole;
- ValueBinding vb = getValueBinding("enabledOnUserRole");
- return vb != null ? _ComponentUtils.getStringValue(getFacesContext(),
- vb) : null;
+ Object[] values = new Object[27];
+ values[0] = super.saveState(context);
+ values[1] = _enabledOnUserRole;
+ values[2] = _visibleOnUserRole;
+ values[3] = _backgroundClass;
+ values[4] = _columnClass;
+ values[5] = _contentClass;
+ values[6] = _dateClass;
+ values[7] = _dayClass;
+ values[8] = _entryClass;
+ values[9] = _entryRenderer;
+ values[10] = _evenClass;
+ values[11] = _foregroundClass;
+ values[12] = _freeClass;
+ values[13] = _gutterClass;
+ values[14] = _headerClass;
+ values[15] = _holidayClass;
+ values[16] = _hoursClass;
+ values[17] = _inactiveDayClass;
+ values[18] = _minutesClass;
+ values[19] = _monthClass;
+ values[20] = _selectedClass;
+ values[21] = _selectedEntryClass;
+ values[22] = _subtitleClass;
+ values[23] = _textClass;
+ values[24] = _titleClass;
+ values[25] = _unevenClass;
+ values[26] = _weekClass;
+
+ return values;
}
/**
- * @see javax.faces.component.UIComponent#getFamily()
+ * @param enabledOnUserRole the _enabledOnUserRole to set
*/
- public String getFamily()
+ public void setEnabledOnUserRole(String enabledOnUserRole)
{
- return COMPONENT_FAMILY;
+ _enabledOnUserRole = enabledOnUserRole;
}
/**
- * <p>
- * The last date and time of day that was clicked. This is set when
- * submitOnClick is true, and the schedule is clicked by the user.
- * </p>
- *
- * @return the last clicked date and time
+ * @param onUserRole the _visibleOnUserRole to set
*/
- public Date getLastClickedDateAndTime()
+ public void setVisibleOnUserRole(String onUserRole)
{
- return _lastClickedDateAndTime;
+ _visibleOnUserRole = onUserRole;
}
/**
- * @return the method binding to the mouse listener method
+ * @return the backgroundClass
*/
- public MethodBinding getMouseListener()
+ public String getBackgroundClass()
{
- return _mouseListener;
+ return ScheduleUtil.getStringProperty(this, _backgroundClass, "backgroundClass", null);
}
/**
- * @see org.apache.myfaces.component.UserRoleAware#getVisibleOnUserRole()
+ * @return the columnClass
*/
- public String getVisibleOnUserRole()
+ public String getColumnClass()
{
- if (_visibleOnUserRole != null)
- return _visibleOnUserRole;
- ValueBinding vb = getValueBinding("visibleOnUserRole");
- return vb != null ? _ComponentUtils.getStringValue(getFacesContext(),
- vb) : null;
+ return ScheduleUtil.getStringProperty(this, _columnClass, "columnClass", null);
}
/**
- * <p>
- * Should the parent form of this schedule be submitted when the user
- * clicks on a day? Note that this will only work when the readonly
- * property is set to false.
- * </p>
- *
- * @return submit the form on mouse click
+ * @return the contentClass
*/
- public boolean isSubmitOnClick()
+ public String getContentClass()
{
- return ScheduleUtil.getBooleanProperty(this, _submitOnClick,
- "submitOnClick", false);
+ return ScheduleUtil.getStringProperty(this, _contentClass, "contentClass", null);
}
/**
- * @see javax.faces.component.UIComponent#queueEvent(javax.faces.event.FacesEvent)
+ * @return the dateClass
*/
- public void queueEvent(FacesEvent event)
+ public String getDateClass()
{
- if (event instanceof ScheduleMouseEvent)
- {
- if (isImmediate())
- {
- event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
- }
- else
- {
- event.setPhaseId(PhaseId.INVOKE_APPLICATION);
- }
- }
- super.queueEvent(event);
+ return ScheduleUtil.getStringProperty(this, _dateClass, "dateClass", null);
}
/**
- * This method is invoked at the beginning of the restore view phase,
- * resetting all mouse event variables that were left from the previous
- * request
+ * @return the dayClass
*/
- public void resetMouseEvents()
+ public String getDayClass()
{
- this._lastClickedDateAndTime = null;
+ return ScheduleUtil.getStringProperty(this, _dayClass, "dayClass", null);
}
/**
- * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
+ * @return the entryClass
*/
- public void restoreState(FacesContext context, Object state)
+ public String getEntryClass()
{
- Object values[] = (Object[]) state;
- super.restoreState(context, values[0]);
- _enabledOnUserRole = (String) values[1];
- _visibleOnUserRole = (String) values[2];
- _submitOnClick = (Boolean) values[3];
- _lastClickedDateAndTime = (Date) values[4];
- _mouseListener = (MethodBinding) restoreAttachedState(context,
- values[5]);
+ return ScheduleUtil.getStringProperty(this, _entryClass, "entryClass", null);
}
- // ------------------ GENERATED CODE END ---------------------------------------
+ /**
+ * @return the entryRenderer
+ */
+ public Object getEntryRenderer()
+ {
+ return ScheduleUtil.getObjectProperty(this, _entryRenderer, "entryRenderer", null);
+ }
/**
- * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
+ * @return the evenClass
*/
- public Object saveState(FacesContext context)
+ public String getEvenClass()
{
- Object values[] = new Object[6];
- values[0] = super.saveState(context);
- values[1] = _enabledOnUserRole;
- values[2] = _visibleOnUserRole;
- values[3] = _submitOnClick;
- values[4] = _lastClickedDateAndTime;
- values[5] = saveAttachedState(context, _mouseListener);
- return ((Object) (values));
+ return ScheduleUtil.getStringProperty(this, _evenClass, "evenClass", null);
}
/**
- * @see org.apache.myfaces.component.UserRoleAware#setEnabledOnUserRole(java.lang.String)
+ * @return the foregroundClass
*/
- public void setEnabledOnUserRole(String enabledOnUserRole)
+ public String getForegroundClass()
{
- _enabledOnUserRole = enabledOnUserRole;
+ return ScheduleUtil.getStringProperty(this, _foregroundClass, "foregroundClass", null);
+ }
+
+ /**
+ * @return the freeClass
+ */
+ public String getFreeClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _freeClass, "freeClass", null);
+ }
+
+ /**
+ * @return the gutterClass
+ */
+ public String getGutterClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _gutterClass, "gutterClass", null);
+ }
+
+ /**
+ * @return the headerClass
+ */
+ public String getHeaderClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _headerClass, "headerClass", null);
+ }
+
+ /**
+ * @return the holidayClass
+ */
+ public String getHolidayClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _holidayClass, "holidayClass", null);
+ }
+
+ /**
+ * @return the hoursClass
+ */
+ public String getHoursClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _hoursClass, "hoursClass", null);
+ }
+
+ /**
+ * @return the inactiveDayClass
+ */
+ public String getInactiveDayClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _inactiveDayClass, "inactiveDayClass", null);
+ }
+
+ /**
+ * @return the minutesClass
+ */
+ public String getMinutesClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _minutesClass, "minutesClass", null);
+ }
+
+ /**
+ * @return the monthClass
+ */
+ public String getMonthClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _monthClass, "monthClass", null);
+ }
+
+ /**
+ * @return the selectedClass
+ */
+ public String getSelectedClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _selectedClass, "selectedClass", null);
+ }
+
+ /**
+ * @return the selectedEntryClass
+ */
+ public String getSelectedEntryClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _selectedEntryClass, "selectedEntryClass", null);
+ }
+
+ /**
+ * @return the subtitleClass
+ */
+ public String getSubtitleClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _subtitleClass, "subtitleClass", null);
+ }
+
+ /**
+ * @return the textClass
+ */
+ public String getTextClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _textClass, "textClass", null);
+ }
+
+ /**
+ * @return the titleClass
+ */
+ public String getTitleClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _titleClass, "titleClass", null);
+ }
+
+ /**
+ * @return the unevenClass
+ */
+ public String getUnevenClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _unevenClass, "unevenClass", null);
+ }
+
+ /**
+ * @return the weekClass
+ */
+ public String getWeekClass()
+ {
+ return ScheduleUtil.getStringProperty(this, _weekClass, "weekClass", null);
+ }
+
+ /**
+ * @param backgroundClass the backgroundClass to set
+ */
+ public void setBackgroundClass(String backgroundClass)
+ {
+ this._backgroundClass = backgroundClass;
+ }
+
+ /**
+ * @param columnClass the columnClass to set
+ */
+ public void setColumnClass(String columnClass)
+ {
+ this._columnClass = columnClass;
+ }
+
+ /**
+ * @param contentClass the contentClass to set
+ */
+ public void setContentClass(String contentClass)
+ {
+ this._contentClass = contentClass;
+ }
+
+ /**
+ * @param dateClass the dateClass to set
+ */
+ public void setDateClass(String dateClass)
+ {
+ this._dateClass = dateClass;
+ }
+
+ /**
+ * @param dayClass the dayClass to set
+ */
+ public void setDayClass(String dayClass)
+ {
+ this._dayClass = dayClass;
+ }
+
+ /**
+ * @param entryClass the entryClass to set
+ */
+ public void setEntryClass(String entryClass)
+ {
+ this._entryClass = entryClass;
+ }
+
+ /**
+ * @param entryRenderer the entryRenderer to set
+ */
+ public void setEntryRenderer(Object entryRenderer)
+ {
+ this._entryRenderer = entryRenderer;
+ }
+
+ /**
+ * @param evenClass the evenClass to set
+ */
+ public void setEvenClass(String evenClass)
+ {
+ this._evenClass = evenClass;
+ }
+
+ /**
+ * @param foregroundClass the foregroundClass to set
+ */
+ public void setForegroundClass(String foregroundClass)
+ {
+ this._foregroundClass = foregroundClass;
+ }
+
+ /**
+ * @param freeClass the freeClass to set
+ */
+ public void setFreeClass(String freeClass)
+ {
+ this._freeClass = freeClass;
}
/**
- * <p>
- * The last date and time of day that was clicked. This is set when
- * submitOnClick is true, and the schedule is clicked by the user.
- * </p>
- *
- * @return the last clicked date and time
+ * @param gutterClass the gutterClass to set
*/
- public void setLastClickedDateAndTime(Date lastClickedDateAndTime)
+ public void setGutterClass(String gutterClass)
{
- this._lastClickedDateAndTime = lastClickedDateAndTime;
+ this._gutterClass = gutterClass;
}
/**
- * @param listener the method binding to the mouse listener method
+ * @param headerClass the headerClass to set
*/
- public void setMouseListener(MethodBinding listener)
+ public void setHeaderClass(String headerClass)
{
- _mouseListener = listener;
+ this._headerClass = headerClass;
}
/**
- * <p>
- * Should the parent form of this schedule be submitted when the user
- * clicks on a day? Note that this will only work when the readonly
- * property is set to false.
- * </p>
- *
- *
- * @param submitOnClick submit the form on mouse click
+ * @param holidayClass the holidayClass to set
*/
- public void setSubmitOnClick(boolean submitOnClick)
+ public void setHolidayClass(String holidayClass)
{
- this._submitOnClick = Boolean.valueOf(submitOnClick);
+ this._holidayClass = holidayClass;
}
- public void setVisibleOnUserRole(String visibleOnUserRole)
+ /**
+ * @param hoursClass the hoursClass to set
+ */
+ public void setHoursClass(String hoursClass)
+ {
+ this._hoursClass = hoursClass;
+ }
+
+ /**
+ * @param inactiveDayClass the inactiveDayClass to set
+ */
+ public void setInactiveDayClass(String inactiveDayClass)
+ {
+ this._inactiveDayClass = inactiveDayClass;
+ }
+
+ /**
+ * @param minutesClass the minutesClass to set
+ */
+ public void setMinutesClass(String minutesClass)
+ {
+ this._minutesClass = minutesClass;
+ }
+
+ /**
+ * @param monthClass the monthClass to set
+ */
+ public void setMonthClass(String monthClass)
+ {
+ this._monthClass = monthClass;
+ }
+
+ /**
+ * @param selectedClass the selectedClass to set
+ */
+ public void setSelectedClass(String selectedClass)
+ {
+ this._selectedClass = selectedClass;
+ }
+
+ /**
+ * @param selectedEntryClass the selectedEntryClass to set
+ */
+ public void setSelectedEntryClass(String selectedEntryClass)
+ {
+ this._selectedEntryClass = selectedEntryClass;
+ }
+
+ /**
+ * @param subtitleClass the subtitleClass to set
+ */
+ public void setSubtitleClass(String subtitleClass)
+ {
+ this._subtitleClass = subtitleClass;
+ }
+
+ /**
+ * @param textClass the textClass to set
+ */
+ public void setTextClass(String textClass)
+ {
+ this._textClass = textClass;
+ }
+
+ /**
+ * @param titleClass the titleClass to set
+ */
+ public void setTitleClass(String titleClass)
+ {
+ this._titleClass = titleClass;
+ }
+
+ /**
+ * @param unevenClass the unevenClass to set
+ */
+ public void setUnevenClass(String unevenClass)
+ {
+ this._unevenClass = unevenClass;
+ }
+
+ /**
+ * @param weekClass the weekClass to set
+ */
+ public void setWeekClass(String weekClass)
{
- _visibleOnUserRole = visibleOnUserRole;
+ this._weekClass = weekClass;
}
}
Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactMonthRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactMonthRenderer.java?view=auto&rev=548528
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactMonthRenderer.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactMonthRenderer.java Mon Jun 18 16:16:17 2007
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.custom.schedule;
+
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.apache.myfaces.custom.schedule.model.ScheduleDay;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+
+
+/**
+ * <p>
+ * Renderer for the month view of the Schedule component
+ * </p>
+ *
+ * @author Jurgen Lust (latest modification by $Author: schof $)
+ * @author Bruno Aranda (adaptation of Jurgen's code to myfaces)
+ * @version $Revision: 382051 $
+ */
+public class ScheduleCompactMonthRenderer
+ extends AbstractCompactScheduleRenderer
+ implements Serializable
+{
+
+ private static final long serialVersionUID = 2926607881214603314L;
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void encodeBegin(
+ FacesContext context,
+ UIComponent component
+ )
+ throws IOException
+ {
+ if (!component.isRendered()) {
+ return;
+ }
+
+ super.encodeBegin(context, component);
+
+ HtmlSchedule schedule = (HtmlSchedule) component;
+ ResponseWriter writer = context.getResponseWriter();
+
+ //container div for the schedule grid
+ writer.startElement(HTML.DIV_ELEM, schedule);
+ writer.writeAttribute(HTML.CLASS_ATTR, "schedule-compact-" + schedule.getTheme(), null);
+ writer.writeAttribute(
+ HTML.STYLE_ATTR, "border-style: none; overflow: hidden;", null
+ );
+
+ writer.startElement(HTML.TABLE_ELEM, schedule);
+ writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "month"), null);
+ writer.writeAttribute(
+ HTML.STYLE_ATTR, "position: relative; left: 0px; top: 0px; width: 100%;",
+ null
+ );
+ writer.writeAttribute(HTML.CELLPADDING_ATTR, "0", null);
+ writer.writeAttribute(HTML.CELLSPACING_ATTR, "1", null);
+ writer.writeAttribute("border", "0", null);
+ writer.writeAttribute(HTML.WIDTH_ATTR, "100%", null);
+ writer.startElement(HTML.TBODY_ELEM, schedule);
+
+ Calendar cal = GregorianCalendar.getInstance();
+ cal.setTime(schedule.getModel().getSelectedDate());
+ int selectedMonth = cal.get(Calendar.MONTH);
+
+ for (
+ Iterator dayIterator = schedule.getModel().iterator();
+ dayIterator.hasNext();
+ ) {
+ ScheduleDay day = (ScheduleDay) dayIterator.next();
+ cal.setTime(day.getDate());
+
+ int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
+ int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
+ int currentMonth = cal.get(Calendar.MONTH);
+ boolean isWeekend =
+ (dayOfWeek == Calendar.SATURDAY) ||
+ (dayOfWeek == Calendar.SUNDAY);
+
+ cal.setTime(day.getDate());
+
+ writeDayCell(
+ context, writer, schedule, day, dayOfWeek, dayOfMonth, isWeekend,
+ currentMonth == selectedMonth, isWeekend ? 1 : 2
+ );
+
+ }
+
+ writer.endElement(HTML.TBODY_ELEM);
+ writer.endElement(HTML.TABLE_ELEM);
+
+ writer.endElement(HTML.DIV_ELEM);
+ }
+
+ /**
+ * @see AbstractCompactScheduleRenderer#getDefaultRowHeight()
+ */
+ protected int getDefaultRowHeight()
+ {
+ return 120;
+ }
+
+
+ /**
+ */
+ protected void writeDayCell(
+ FacesContext context,
+ ResponseWriter writer,
+ HtmlSchedule schedule,
+ ScheduleDay day,
+ int dayOfWeek,
+ int dayOfMonth,
+ boolean isWeekend,
+ boolean isCurrentMonth,
+ int rowspan
+ )
+ throws IOException
+ {
+ if ((dayOfWeek == Calendar.MONDAY) || (dayOfWeek == Calendar.SUNDAY)) {
+ writer.startElement(HTML.TR_ELEM, schedule);
+ }
+
+ super.writeDayCell(
+ context, writer, schedule, day, 100f / 6, dayOfWeek, dayOfMonth,
+ isWeekend, isCurrentMonth, rowspan
+ );
+
+ if ((dayOfWeek == Calendar.SATURDAY) || (dayOfWeek == Calendar.SUNDAY)) {
+ writer.endElement(HTML.TR_ELEM);
+ }
+ }
+
+ protected int getRowHeight(UIScheduleBase schedule)
+ {
+ if (schedule != null) {
+ int height = schedule.getCompactMonthRowHeight();
+ return height <= 0 ? getDefaultRowHeight() : height;
+ }
+ return getDefaultRowHeight();
+ }
+}
+//The End
Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactWeekRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactWeekRenderer.java?view=auto&rev=548528
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactWeekRenderer.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleCompactWeekRenderer.java Mon Jun 18 16:16:17 2007
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.custom.schedule;
+
+
+import org.apache.myfaces.custom.schedule.model.ScheduleDay;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Iterator;
+
+
+/**
+ * <p>
+ * Renderer for the week view of the UISchedule component
+ * </p>
+ *
+ * @author Jurgen Lust (latest modification by $Author: schof $)
+ * @author Bruno Aranda (adaptation of Jurgen's code to myfaces)
+ * @version $Revision: 382051 $
+ */
+public class ScheduleCompactWeekRenderer
+ extends AbstractCompactScheduleRenderer
+ implements Serializable
+{
+ private static final long serialVersionUID = 5504081783797695487L;
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void encodeBegin(
+ FacesContext context,
+ UIComponent component
+ )
+ throws IOException
+ {
+ if (!component.isRendered()) {
+ return;
+ }
+
+ super.encodeBegin(context, component);
+
+ HtmlSchedule schedule = (HtmlSchedule) component;
+ ResponseWriter writer = context.getResponseWriter();
+
+ //container div for the schedule grid
+ writer.startElement(HTML.DIV_ELEM, schedule);
+ writer.writeAttribute(HTML.CLASS_ATTR, "schedule-compact-" + schedule.getTheme(), null);
+ writer.writeAttribute(
+ HTML.STYLE_ATTR, "border-style: none; overflow: hidden;", null
+ );
+
+ writer.startElement(HTML.TABLE_ELEM, schedule);
+ writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "week"), null);
+ writer.writeAttribute(
+ HTML.STYLE_ATTR, "position: relative; left: 0px; top: 0px; width: 100%;",
+ null
+ );
+ writer.writeAttribute(HTML.CELLPADDING_ATTR, "0", null);
+ writer.writeAttribute(HTML.CELLSPACING_ATTR, "1", null);
+ writer.writeAttribute("border", "0", null);
+ writer.writeAttribute(HTML.WIDTH_ATTR, "100%", null);
+ writer.startElement(HTML.TBODY_ELEM, schedule);
+
+ Calendar cal = GregorianCalendar.getInstance();
+
+ for (
+ Iterator dayIterator = schedule.getModel().iterator();
+ dayIterator.hasNext();
+ ) {
+ ScheduleDay day = (ScheduleDay) dayIterator.next();
+ cal.setTime(day.getDate());
+
+ int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
+ int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
+ boolean isWeekend =
+ (dayOfWeek == Calendar.SATURDAY) ||
+ (dayOfWeek == Calendar.SUNDAY);
+
+ if (
+ (dayOfWeek == Calendar.MONDAY) ||
+ (dayOfWeek == Calendar.WEDNESDAY) ||
+ (dayOfWeek == Calendar.FRIDAY) ||
+ (dayOfWeek == Calendar.SUNDAY)
+ ) {
+ writer.startElement(HTML.TR_ELEM, schedule);
+ }
+
+ writeDayCell(
+ context, writer, schedule, day, 50f, dayOfWeek, dayOfMonth,
+ isWeekend, true, (dayOfWeek == Calendar.FRIDAY) ? 2 : 1
+ );
+
+ if (
+ (dayOfWeek == Calendar.TUESDAY) ||
+ (dayOfWeek == Calendar.THURSDAY) ||
+ (dayOfWeek == Calendar.SATURDAY) ||
+ (dayOfWeek == Calendar.SUNDAY)
+ ) {
+ writer.endElement(HTML.TR_ELEM);
+ }
+ }
+
+ writer.endElement(HTML.TBODY_ELEM);
+ writer.endElement(HTML.TABLE_ELEM);
+
+ writer.endElement(HTML.DIV_ELEM);
+ }
+
+ /**
+ * @see org.apache.myfaces.custom.schedule.AbstractCompactScheduleRenderer#getDefaultRowHeight()
+ */
+ protected int getDefaultRowHeight()
+ {
+ return 200;
+ }
+
+ protected int getRowHeight(UIScheduleBase schedule)
+ {
+ if (schedule != null) {
+ int height = schedule.getCompactWeekRowHeight();
+ return height <= 0 ? getDefaultRowHeight() : height;
+ }
+ return getDefaultRowHeight();
+ }
+
+}
+//The End
Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDelegatingRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDelegatingRenderer.java?view=auto&rev=548528
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDelegatingRenderer.java (added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDelegatingRenderer.java Mon Jun 18 16:16:17 2007
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.custom.schedule;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;
+
+import org.apache.myfaces.custom.schedule.model.ScheduleModel;
+
+/**
+ * <p>
+ * Renderer for the Schedule component that delegates the actual rendering
+ * to a compact or detailed renderer, depending on the mode of the ScheduleModel
+ * </p>
+ *
+ * @author Jurgen Lust (latest modification by $Author: skitching $)
+ * @author Bruno Aranda (adaptation of Jurgen's code to myfaces)
+ * @version $Revision: 367444 $
+ */
+public class ScheduleDelegatingRenderer extends Renderer implements Serializable
+{
+ private static final long serialVersionUID = -837566590780480244L;
+
+ //~ Instance fields --------------------------------------------------------
+
+ private final ScheduleCompactMonthRenderer monthDelegate = new ScheduleCompactMonthRenderer();
+ private final ScheduleCompactWeekRenderer weekDelegate = new ScheduleCompactWeekRenderer();
+ private final ScheduleDetailedDayRenderer dayDelegate = new ScheduleDetailedDayRenderer();
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * @see javax.faces.render.Renderer#decode(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void decode(FacesContext context, UIComponent component)
+ {
+ getDelegateRenderer(component).decode(context, component);
+ }
+
+ /**
+ * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void encodeBegin(FacesContext context, UIComponent component)
+ throws IOException
+ {
+ getDelegateRenderer(component).encodeBegin(context, component);
+ }
+
+ /**
+ * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void encodeChildren(FacesContext context, UIComponent component)
+ throws IOException
+ {
+ getDelegateRenderer(component).encodeChildren(context, component);
+ }
+
+ /**
+ * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void encodeEnd(FacesContext context, UIComponent component)
+ throws IOException
+ {
+ getDelegateRenderer(component).encodeEnd(context, component);
+ }
+
+ protected Renderer getDelegateRenderer(UIComponent component)
+ {
+ HtmlSchedule schedule = (HtmlSchedule) component;
+
+ if ((schedule == null) || (schedule.getModel() == null))
+ {
+ return dayDelegate;
+ }
+
+ switch (schedule.getModel().getMode())
+ {
+ case ScheduleModel.WEEK:
+ return weekDelegate;
+
+ case ScheduleModel.MONTH:
+ return monthDelegate;
+
+ default:
+ return dayDelegate;
+ }
+ }
+
+ /**
+ * @see javax.faces.render.Renderer#getRendersChildren()
+ */
+ public boolean getRendersChildren()
+ {
+ return true;
+ }
+}
+//The End