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