Example usage for com.google.gwt.event.shared HandlerManager getHandler

List of usage examples for com.google.gwt.event.shared HandlerManager getHandler

Introduction

In this page you can find the example usage for com.google.gwt.event.shared HandlerManager getHandler.

Prototype

public <H extends EventHandler> H getHandler(GwtEvent.Type<H> type, int index) 

Source Link

Document

Gets the handler at the given index.

Usage

From source file:sk.turn.gwtmvp.client.EventManager.java

License:Apache License

/**
 * Sets an event handler for an {@code Element}. All previous event handlers of this type of event are removed.
 * @param element The element to bind the event handler for
 * @param eventType The event type (e.g. {@code ClickEvent.getType()})
 * @param handler The handler that handler the event
 *//*ww w.  ja  va 2 s . co m*/
public static <H extends EventHandler> void setEventHandler(final Element element, DomEvent.Type<H> eventType,
        H handler) {
    if (element == null) {
        return;
    }
    HandlerManager hm = handlerManagers.get(element);
    if (hm == null) {
        handlerManagers.put(element, hm = new HandlerManager(element));
        DOM.setEventListener(element, new EventListener() {
            @Override
            public void onBrowserEvent(Event event) {
                DomEvent.fireNativeEvent(event, handlerManagers.get(element), element);
            }
        });
    }
    DOM.sinkBitlessEvent(element, eventType.getName());
    while (hm.getHandlerCount(eventType) > 0) {
        hm.removeHandler(eventType, hm.getHandler(eventType, 0));
    }
    hm.addHandler(eventType, handler);
}

From source file:sk.turn.gwtmvp.client.EventManager.java

License:Apache License

/**
 * Clears all event handlers of a specific event type from an element.
 * @param element The element to clear the event handlers from
 * @param eventType The event type//from   ww  w  .j  a  v  a  2  s  .c  o  m
 */
public static <H extends EventHandler> void clearEventHandlers(Element element, GwtEvent.Type<H> eventType) {
    HandlerManager hm = handlerManagers.get(element);
    while (hm != null && hm.getHandlerCount(eventType) > 0) {
        hm.removeHandler(eventType, hm.getHandler(eventType, 0));
    }
}