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  import java.io.IOException;
23  import java.io.Serializable;
24  
25  import javax.faces.component.UIComponent;
26  import javax.faces.context.FacesContext;
27  import javax.faces.render.Renderer;
28  
29  import org.apache.myfaces.custom.schedule.model.ScheduleModel;
30  
31  /**
32   * <p>
33   * Renderer for the Schedule component that delegates the actual rendering
34   * to a compact or detailed renderer, depending on the mode of the ScheduleModel
35   * </p>
36   * 
37   * @JSFRenderer
38   *   renderKitId = "HTML_BASIC" 
39   *   family = "javax.faces.Panel"
40   *   type = "org.apache.myfaces.Schedule"
41   * @since 1.1.7
42   * @author Jurgen Lust (latest modification by $Author: skitching $)
43   * @author Bruno Aranda (adaptation of Jurgen's code to myfaces)
44   * @version $Revision: 367444 $
45   */
46  public class ScheduleDelegatingRenderer extends Renderer implements Serializable
47  {
48      private static final long serialVersionUID = -837566590780480244L;
49      
50      //~ Instance fields --------------------------------------------------------
51  
52      private final ScheduleCompactMonthRenderer monthDelegate = new ScheduleCompactMonthRenderer();
53      private final ScheduleCompactWeekRenderer weekDelegate = new ScheduleCompactWeekRenderer();
54      private final ScheduleDetailedDayRenderer dayDelegate = new ScheduleDetailedDayRenderer();
55  
56      //~ Methods ----------------------------------------------------------------
57  
58      /**
59       * @see javax.faces.render.Renderer#decode(javax.faces.context.FacesContext,
60       *      javax.faces.component.UIComponent)
61       */
62      public void decode(FacesContext context, UIComponent component)
63      {
64          getDelegateRenderer(component).decode(context, component);
65      }
66  
67      /**
68       * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext,
69       *      javax.faces.component.UIComponent)
70       */
71      public void encodeBegin(FacesContext context, UIComponent component)
72              throws IOException
73      {
74          getDelegateRenderer(component).encodeBegin(context, component);
75      }
76  
77      /**
78       * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext,
79       *      javax.faces.component.UIComponent)
80       */
81      public void encodeChildren(FacesContext context, UIComponent component)
82              throws IOException
83      {
84          getDelegateRenderer(component).encodeChildren(context, component);
85      }
86  
87      /**
88       * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext,
89       *      javax.faces.component.UIComponent)
90       */
91      public void encodeEnd(FacesContext context, UIComponent component)
92              throws IOException
93      {
94          getDelegateRenderer(component).encodeEnd(context, component);
95      }
96  
97      protected Renderer getDelegateRenderer(UIComponent component)
98      {
99          HtmlSchedule schedule = (HtmlSchedule) component;
100 
101         if ((schedule == null) || (schedule.getModel() == null))
102         {
103             return dayDelegate;
104         }
105 
106         switch (schedule.getModel().getMode())
107         {
108         case ScheduleModel.WEEK:
109             return weekDelegate;
110 
111         case ScheduleModel.MONTH:
112             return monthDelegate;
113 
114         default:
115             return dayDelegate;
116         }
117     }
118 
119     /**
120      * @see javax.faces.render.Renderer#getRendersChildren()
121      */
122     public boolean getRendersChildren()
123     {
124         return true;
125     }
126 }
127 //The End