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

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

Introduction

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

Prototype

public <H extends EventHandler> void removeHandler(GwtEvent.Type<H> type, final H handler) 

Source Link

Document

Removes the given handler from the specified event type.

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
 *//*from  www .ja v  a  2  s .  c  o  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 2s. 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));
    }
}