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

eu.future.earth.gwt.charts.client.event.EventBase Maven / Gradle / Ivy

There is a newer version: 3.0
Show newest version
package eu.future.earth.gwt.charts.client.event;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.SimpleEventBus;

public class EventBase {

	private SimpleEventBus handlerManager;

	public void fireEvent(GwtEvent event) {
		if (handlerManager != null) {
			handlerManager.fireEvent(event);
		}
	}

	/**
	 * Adds this handler to the widget.
	 * 
	 * @param 
	 *            the type of handler to add
	 * @param type
	 *            the event type
	 * @param handler
	 *            the handler
	 * @return {@link HandlerRegistration} used to remove the handler
	 */
	protected final  HandlerRegistration addHandler(final H handler, GwtEvent.Type type) {
		return ensureHandlers().addHandler(type, handler);
	}

	/**
	 * Ensures the existence of the handler manager.
	 * 
	 * @return the handler manager
	 * */
	SimpleEventBus ensureHandlers() {
		return handlerManager == null ? handlerManager = createHandlerManager() : handlerManager;
	}

	/**
	 * Creates the {@link HandlerManager} used by this Widget. You can overwrite this method to create a custom
	 * {@link HandlerManager}.
	 * 
	 * @return the {@link HandlerManager} you want to use
	 */
	protected SimpleEventBus createHandlerManager() {
		return new SimpleEventBus();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy