All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.future.earth.gwt.client.date.CalendarEvent Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2007 Future Earth, [email protected]
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package eu.future.earth.gwt.client.date;

import java.util.Date;

import com.google.gwt.event.shared.GwtEvent;

public class CalendarEvent extends GwtEvent> {

	public enum CalendarEventActions {

		ADD,

		UPDATE,

		REMOVE,

		DRAG_DROP,

		EDIT,

		REPAINT,

		SELECT_DAY,

		SELECT_MONTH,

		RELOAD

	}

	private T data = null;

	private Date date = null;

	private CalendarEventActions command = CalendarEventActions.ADD;

	public CalendarEvent() {
		super();
	}

	/**
	 * Handler type.
	 */
	private static Type> TYPE;

	/**
	 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this
	 * method will do nothing.
	 * 
	 * @param source
	 *            the source of the handlers
	 * @param navigator
	 *            the navigator associated with this event
	 * @param token
	 *            the navigation token associated with this event
	 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have
	 *         been registered
	 */
	public static  CalendarEvent fire(HasCalendarEventHandlers source, Date navigator, T token) {
		// If no handlers exist, then type can be null.
		if (TYPE != null) {
			final CalendarEvent event = new CalendarEvent(navigator, token);
			source.fireEvent(event);
			return event;
		}
		return null;
	}

	/**
	 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this
	 * method will do nothing.
	 * 
	 * @param source
	 *            the source of the handlers
	 * @param navigator
	 *            the navigator associated with this event
	 * @param token
	 *            the navigation token associated with this event
	 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have
	 *         been registered
	 */
	public static  CalendarEvent fire(HasCalendarEventHandlers source, Date navigator) {
		// If no handlers exist, then type can be null.
		if (TYPE != null) {
			final CalendarEvent event = new CalendarEvent(navigator);
			source.fireEvent(event);
			return event;
		}
		return null;
	}

	/**
	 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this
	 * method will do nothing.
	 * 
	 * @param source
	 *            the source of the handlers
	 * @param navigator
	 *            the navigator associated with this event
	 * @param token
	 *            the navigation token associated with this event
	 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have
	 *         been registered
	 */
	public static  CalendarEvent fire(HasCalendarEventHandlers source, CalendarEvent navigator) {
		// If no handlers exist, then type can be null.
		if (TYPE != null) {
			source.fireEvent(navigator);
			return navigator;
		}
		return null;
	}

	/**
	 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this
	 * method will do nothing.
	 * 
	 * @param source
	 *            the source of the handlers
	 * @param navigator
	 *            the navigator associated with this event
	 * @param token
	 *            the navigation token associated with this event
	 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have
	 *         been registered
	 */
	public static  CalendarEvent fire(HasCalendarEventHandlers source, Date navigator, CalendarEventActions action) {
		// If no handlers exist, then type can be null.
		if (TYPE != null) {
			final CalendarEvent event = new CalendarEvent(navigator, action);
			source.fireEvent(event);
			return event;
		}
		return null;
	}

	/**
	 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this
	 * method will do nothing.
	 * 
	 * @param source
	 *            the source of the handlers
	 * @param navigator
	 *            the navigator associated with this event
	 * @param token
	 *            the navigation token associated with this event
	 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have
	 *         been registered
	 */
	public static  CalendarEvent fire(HasCalendarEventHandlers source, CalendarEventActions action) {
		// If no handlers exist, then type can be null.
		if (TYPE != null) {
			final CalendarEvent event = new CalendarEvent(action);
			source.fireEvent(event);
			return event;
		}
		return null;
	}

	/**
	 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this
	 * method will do nothing.
	 * 
	 * @param source
	 *            the source of the handlers
	 * @param navigator
	 *            the navigator associated with this event
	 * @param token
	 *            the navigation token associated with this event
	 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have
	 *         been registered
	 */
	public static  CalendarEvent fire(HasCalendarEventHandlers source, Date navigator, CalendarEventActions action, T newData) {
		// If no handlers exist, then type can be null.
		if (TYPE != null) {
			final CalendarEvent event = new CalendarEvent(navigator, action, newData);
			source.fireEvent(event);
			return event;
		}
		return null;
	}

	/**
	 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this
	 * method will do nothing.
	 * 
	 * @param source
	 *            the source of the handlers
	 * @param navigator
	 *            the navigator associated with this event
	 * @param token
	 *            the navigation token associated with this event
	 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have
	 *         been registered
	 */
	public static  CalendarEvent fire(HasCalendarEventHandlers source, CalendarEventActions action, T newData) {
		// If no handlers exist, then type can be null.
		if (TYPE != null) {
			final CalendarEvent event = new CalendarEvent(action, newData);
			source.fireEvent(event);
			return event;
		}
		return null;
	}

	public T getData() {
		return data;
	}

	public Date getDate() {
		return date;
	}

	public CalendarEventActions getCommand() {
		return command;
	}

	/**
	 * Gets the type associated with this event.
	 * 
	 * @return returns the handler type
	 */
	public static  Type> getType() {
		if (TYPE == null) {
			TYPE = new Type>();
		}
		return TYPE;
	}

	protected CalendarEvent(Date newDate, T token2) {
		super();
		date = newDate;
		data = token2;
	}

	protected CalendarEvent(Date newDate, CalendarEventActions newAction) {
		super();
		date = newDate;
		command = newAction;
	}

	protected CalendarEvent(CalendarEventActions newAction) {
		super();
		command = newAction;
	}

	protected CalendarEvent(CalendarEventActions newAction, T newData) {
		super();
		command = newAction;
		data = newData;
	}

	protected CalendarEvent(Date newDate, CalendarEventActions newAction, T newData) {
		super();
		date = newDate;
		command = newAction;
		data = newData;
	}

	protected CalendarEvent(Date newDate) {
		super();
		date = newDate;
	}

	@SuppressWarnings({
			"unchecked", "rawtypes"
	})
	@Override
	public final Type> getAssociatedType() {
		return (Type) TYPE;
	}

	protected void dispatch(CalendarEventListener handler) {
		handler.handleCalendarEvent(this);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy