/ftr-gwt-library-date/src/main/java/eu/future/earth/gwt/client/date/CalendarEvent.java
Java | 295 lines | 133 code | 41 blank | 121 comment | 16 complexity | 2165996a771aaa5ab4911ebd7c9c1c86 MD5 | raw file
Possible License(s): Apache-2.0
1/* 2 * Copyright 2007 Future Earth, info@future-earth.eu 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17package eu.future.earth.gwt.client.date; 18 19import java.util.Date; 20 21import com.google.gwt.event.shared.GwtEvent; 22 23public class CalendarEvent<T> extends GwtEvent<CalendarEventListener<T>> { 24 25 private static final long serialVersionUID = -3798647759325157673L; 26 27 public enum CalendarEventActions { 28 29 ADD, 30 31 UPDATE, 32 33 REMOVE, 34 35 DRAG_DROP, 36 37 EDIT, 38 39 REPAINT, 40 41 SELECT_DAY, 42 43 SELECT_MONTH, 44 45 RELOAD 46 47 } 48 49 private T data = null; 50 51 private Date date = null; 52 53 private CalendarEventActions command = CalendarEventActions.ADD; 54 55 public CalendarEvent() { 56 super(); 57 } 58 59 /** 60 * Handler type. 61 */ 62 private static Type<DateEventListener<?>> TYPE; 63 64 /** 65 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this 66 * method will do nothing. 67 * 68 * @param source 69 * the source of the handlers 70 * @param navigator 71 * the navigator associated with this event 72 * @param token 73 * the navigation token associated with this event 74 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have 75 * been registered 76 */ 77 public static <T> CalendarEvent<T> fire(HasCalendarEventHandlers<T> source, Date navigator, T token) { 78 // If no handlers exist, then type can be null. 79 if (TYPE != null) { 80 final CalendarEvent<T> event = new CalendarEvent<T>(navigator, token); 81 source.fireEvent(event); 82 return event; 83 } 84 return null; 85 } 86 87 /** 88 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this 89 * method will do nothing. 90 * 91 * @param source 92 * the source of the handlers 93 * @param navigator 94 * the navigator associated with this event 95 * @param token 96 * the navigation token associated with this event 97 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have 98 * been registered 99 */ 100 public static <T> CalendarEvent<T> fire(HasCalendarEventHandlers<T> source, Date navigator) { 101 // If no handlers exist, then type can be null. 102 if (TYPE != null) { 103 final CalendarEvent<T> event = new CalendarEvent<T>(navigator); 104 source.fireEvent(event); 105 return event; 106 } 107 return null; 108 } 109 110 /** 111 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this 112 * method will do nothing. 113 * 114 * @param source 115 * the source of the handlers 116 * @param navigator 117 * the navigator associated with this event 118 * @param token 119 * the navigation token associated with this event 120 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have 121 * been registered 122 */ 123 public static <T> CalendarEvent<T> fire(HasCalendarEventHandlers<T> source, CalendarEvent<T> navigator) { 124 // If no handlers exist, then type can be null. 125 if (TYPE != null) { 126 source.fireEvent(navigator); 127 return navigator; 128 } 129 return null; 130 } 131 132 /** 133 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this 134 * method will do nothing. 135 * 136 * @param source 137 * the source of the handlers 138 * @param navigator 139 * the navigator associated with this event 140 * @param token 141 * the navigation token associated with this event 142 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have 143 * been registered 144 */ 145 public static <T> CalendarEvent<T> fire(HasCalendarEventHandlers<T> source, Date navigator, CalendarEventActions action) { 146 // If no handlers exist, then type can be null. 147 if (TYPE != null) { 148 final CalendarEvent<T> event = new CalendarEvent<T>(navigator, action); 149 source.fireEvent(event); 150 return event; 151 } 152 return null; 153 } 154 155 /** 156 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this 157 * method will do nothing. 158 * 159 * @param source 160 * the source of the handlers 161 * @param navigator 162 * the navigator associated with this event 163 * @param token 164 * the navigation token associated with this event 165 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have 166 * been registered 167 */ 168 public static <T> CalendarEvent<T> fire(HasCalendarEventHandlers<T> source, CalendarEventActions action) { 169 // If no handlers exist, then type can be null. 170 if (TYPE != null) { 171 final CalendarEvent<T> event = new CalendarEvent<T>(action); 172 source.fireEvent(event); 173 return event; 174 } 175 return null; 176 } 177 178 /** 179 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this 180 * method will do nothing. 181 * 182 * @param source 183 * the source of the handlers 184 * @param navigator 185 * the navigator associated with this event 186 * @param token 187 * the navigation token associated with this event 188 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have 189 * been registered 190 */ 191 public static <T> CalendarEvent<T> fire(HasCalendarEventHandlers<T> source, Date navigator, CalendarEventActions action, T newData) { 192 // If no handlers exist, then type can be null. 193 if (TYPE != null) { 194 final CalendarEvent<T> event = new CalendarEvent<T>(navigator, action, newData); 195 source.fireEvent(event); 196 return event; 197 } 198 return null; 199 } 200 201 /** 202 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this 203 * method will do nothing. 204 * 205 * @param source 206 * the source of the handlers 207 * @param navigator 208 * the navigator associated with this event 209 * @param token 210 * the navigation token associated with this event 211 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have 212 * been registered 213 */ 214 public static <T> CalendarEvent<T> fire(HasCalendarEventHandlers<T> source, CalendarEventActions action, T newData) { 215 // If no handlers exist, then type can be null. 216 if (TYPE != null) { 217 final CalendarEvent<T> event = new CalendarEvent<T>(action, newData); 218 source.fireEvent(event); 219 return event; 220 } 221 return null; 222 } 223 224 public T getData() { 225 return data; 226 } 227 228 public Date getDate() { 229 return date; 230 } 231 232 public CalendarEventActions getCommand() { 233 return command; 234 } 235 236 /** 237 * Gets the type associated with this event. 238 * 239 * @return returns the handler type 240 */ 241 public static <T> Type<DateEventListener<?>> getType() { 242 if (TYPE == null) { 243 TYPE = new Type<DateEventListener<?>>(); 244 } 245 return TYPE; 246 } 247 248 protected CalendarEvent(Date newDate, T token2) { 249 super(); 250 date = newDate; 251 data = token2; 252 } 253 254 protected CalendarEvent(Date newDate, CalendarEventActions newAction) { 255 super(); 256 date = newDate; 257 command = newAction; 258 } 259 260 protected CalendarEvent(CalendarEventActions newAction) { 261 super(); 262 command = newAction; 263 } 264 265 protected CalendarEvent(CalendarEventActions newAction, T newData) { 266 super(); 267 command = newAction; 268 data = newData; 269 } 270 271 protected CalendarEvent(Date newDate, CalendarEventActions newAction, T newData) { 272 super(); 273 date = newDate; 274 command = newAction; 275 data = newData; 276 } 277 278 protected CalendarEvent(Date newDate) { 279 super(); 280 date = newDate; 281 } 282 283 @SuppressWarnings({ 284 "unchecked", "rawtypes" 285 }) 286 @Override 287 public final Type<CalendarEventListener<T>> getAssociatedType() { 288 return (Type) TYPE; 289 } 290 291 protected void dispatch(CalendarEventListener<T> handler) { 292 handler.handleCalendarEvent(this); 293 } 294 295}