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  package org.apache.myfaces.custom.schedule;
20  
21  import java.io.Serializable;
22  import java.util.Date;
23  import java.util.Iterator;
24  
25  import javax.faces.event.FacesEvent;
26  import javax.faces.event.FacesListener;
27  
28  import org.apache.myfaces.custom.schedule.model.Interval;
29  import org.apache.myfaces.custom.schedule.model.ScheduleDay;
30  
31  /**
32   * An event that is fired when the schedule is clicked, and the submitOnClick
33   * property on the schedule is set to true.
34   * 
35   * @author Jurgen Lust (latest modification by $Author$)
36   * @version $Revision$
37   */
38  public class ScheduleMouseEvent extends FacesEvent implements Serializable
39  {
40      public static final int SCHEDULE_NOTHING_CLICKED = 0;
41      public static final int SCHEDULE_BODY_CLICKED = 1;
42      public static final int SCHEDULE_HEADER_CLICKED = 2;
43      public static final int SCHEDULE_ENTRY_CLICKED = 3;
44  
45      private static final long serialVersionUID = -2810582008938303475L;
46  
47      private final int eventType;
48  
49      public ScheduleMouseEvent(final HtmlSchedule source, final int eventType)
50      {
51          super(source);
52          //the FacesEvent throws an IllegalArgumentException when source == null
53          //so don't bother here
54          this.eventType = eventType;
55      }
56  
57      public Date getClickedDate()
58      {
59          return getSchedule().getLastClickedDateAndTime();
60      }
61  
62      public Date getClickedTime()
63      {
64          return getSchedule().getLastClickedDateAndTime();
65      }
66     
67      public Interval getClickedInterval()
68      {
69          Date clickedDate = getClickedDate();
70          
71          for (Iterator intervalIt = getSchedule().getModel().iterator(); intervalIt.hasNext(); ) {
72              ScheduleDay day = (ScheduleDay) intervalIt.next();
73  
74              if (day.equalsDate(clickedDate))
75              {
76                  return day.getInterval(clickedDate);
77              }
78          }
79          
80          return null;
81      }
82  
83      public int getEventType()
84      {
85          return eventType;
86      }
87  
88      /**
89       * @return The schedule component where the mouse event originated
90       */
91      public HtmlSchedule getSchedule()
92      {
93          return (HtmlSchedule) getSource();
94      }
95  
96      /**
97       * @see javax.faces.event.FacesEvent#isAppropriateListener(javax.faces.event.FacesListener)
98       */
99      public boolean isAppropriateListener(FacesListener listener)
100     {
101         return (listener instanceof ScheduleMouseListener);
102     }
103 
104     /**
105      * @see javax.faces.event.FacesEvent#processListener(javax.faces.event.FacesListener)
106      */
107     public void processListener(FacesListener listener)
108     {
109         if (listener instanceof ScheduleMouseListener)
110         {
111             ScheduleMouseListener mouseListener = (ScheduleMouseListener) listener;
112             mouseListener.processMouseEvent(this);
113         }
114     }
115 
116 }