View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.custom.schedule;
21  
22  
23  import org.apache.myfaces.custom.schedule.model.ScheduleDay;
24  import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
25  
26  import javax.faces.component.UIComponent;
27  import javax.faces.context.FacesContext;
28  import javax.faces.context.ResponseWriter;
29  import java.io.IOException;
30  import java.io.Serializable;
31  import java.util.Calendar;
32  import java.util.Iterator;
33  
34  
35  /**
36   * <p>
37   * Renderer for the week view of the UISchedule component
38   * </p>
39   * @since 1.1.7
40   * @author Jurgen Lust (latest modification by $Author: schof $)
41   * @author Bruno Aranda (adaptation of Jurgen's code to myfaces)
42   * @version $Revision: 382051 $
43   */
44  public class ScheduleCompactWeekRenderer
45      extends AbstractCompactScheduleRenderer
46      implements Serializable
47  {
48      private static final long serialVersionUID = 5504081783797695487L;
49  
50      //~ Methods ----------------------------------------------------------------
51  
52      /**
53       * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext,
54       *      javax.faces.component.UIComponent)
55       */
56      public void encodeBegin(
57          FacesContext context,
58          UIComponent component
59      )
60          throws IOException
61      {
62          if (!component.isRendered()) {
63              return;
64          }
65  
66          super.encodeBegin(context, component);
67  
68          HtmlSchedule schedule = (HtmlSchedule) component;
69          ResponseWriter writer = context.getResponseWriter();
70  
71          //container div for the schedule grid
72          writer.startElement(HTML.DIV_ELEM, schedule);
73          writer.writeAttribute(HTML.CLASS_ATTR, "schedule-compact-" + schedule.getTheme(), null);
74          writer.writeAttribute(
75              HTML.STYLE_ATTR, "border-style: none; overflow: hidden;", null
76          );
77  
78          writer.startElement(HTML.TABLE_ELEM, schedule);
79          writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "week"), null);
80          writer.writeAttribute(
81              HTML.STYLE_ATTR, "position: relative; left: 0px; top: 0px; width: 100%;",
82              null
83          );
84          writer.writeAttribute(HTML.CELLPADDING_ATTR, "0", null);
85          writer.writeAttribute(HTML.CELLSPACING_ATTR, "1", null);
86          writer.writeAttribute("border", "0", null);
87          writer.writeAttribute(HTML.WIDTH_ATTR, "100%", null);
88          writer.startElement(HTML.TBODY_ELEM, schedule);
89  
90          for (
91              Iterator dayIterator = schedule.getModel().iterator();
92                  dayIterator.hasNext();
93          ) {
94              ScheduleDay day = (ScheduleDay) dayIterator.next();
95              Calendar cal = getCalendarInstance(schedule, day.getDate());
96  
97              int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
98              int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
99              boolean isWeekend =
100                 (dayOfWeek == Calendar.SATURDAY) ||
101                 (dayOfWeek == Calendar.SUNDAY);
102 
103             if (
104                 (dayOfWeek == Calendar.MONDAY) ||
105                     (dayOfWeek == Calendar.WEDNESDAY) ||
106                     (dayOfWeek == Calendar.FRIDAY) ||
107                     (dayOfWeek == Calendar.SUNDAY)
108             ) {
109                 writer.startElement(HTML.TR_ELEM, schedule);
110             }
111 
112             writeDayCell(
113                 context, writer, schedule, day, 50f, dayOfWeek, dayOfMonth,
114                 isWeekend, true, (dayOfWeek == Calendar.FRIDAY) ? (schedule.isSplitWeekend() ? 2 : 1) : 1
115             );
116 
117             if (
118                 (dayOfWeek == Calendar.TUESDAY) ||
119                     (dayOfWeek == Calendar.THURSDAY) ||
120                     (dayOfWeek == Calendar.SATURDAY) ||
121                     (dayOfWeek == Calendar.SUNDAY)
122             ) {
123                 writer.endElement(HTML.TR_ELEM);
124             }
125         }
126 
127         writer.endElement(HTML.TBODY_ELEM);
128         writer.endElement(HTML.TABLE_ELEM);
129 
130         writer.endElement(HTML.DIV_ELEM);
131     }
132 
133     /**
134      * @see org.apache.myfaces.custom.schedule.AbstractCompactScheduleRenderer#getDefaultRowHeight()
135      */
136     protected int getDefaultRowHeight()
137     {
138         return 200;
139     }
140 
141     protected int getRowHeight(UIScheduleBase schedule)
142     {
143         if (schedule != null) {
144             int height = schedule.getCompactWeekRowHeight();
145             return height == 0 ? getDefaultRowHeight() : height;
146         }
147         return getDefaultRowHeight();
148     }
149 
150 }
151 //The End