Search in sources :

Example 1 with HasValueChangeHandlers

use of com.google.gwt.event.logical.shared.HasValueChangeHandlers in project gwt-test-utils by gwt-test-utils.

the class UiBinderInvocationHandler method addHandlers.

@SuppressWarnings("unchecked")
private <H extends EventHandler> void addHandlers(Object owner) {
    Map<Method, UiHandler> uiHandlerMethods = GwtReflectionUtils.getAnnotatedMethod(owner.getClass(), UiHandler.class);
    for (Map.Entry<Method, UiHandler> entry : uiHandlerMethods.entrySet()) {
        for (String uiFieldName : entry.getValue().value()) {
            Widget uiField = GwtReflectionUtils.getPrivateFieldValue(owner, uiFieldName);
            GwtEvent.Type<H> eventType = (GwtEvent.Type<H>) getEventType(entry.getKey());
            H handler = (H) createHandler(uiField, entry.getKey(), owner);
            if (eventType instanceof DomEvent.Type) {
                uiField.addDomHandler(handler, (DomEvent.Type<H>) eventType);
            } else {
                if (uiField instanceof HasValueChangeHandlers && handler instanceof ValueChangeHandler) {
                    ((HasValueChangeHandlers<Object>) uiField).addValueChangeHandler((ValueChangeHandler<Object>) handler);
                } else {
                    uiField.addHandler(handler, eventType);
                }
            }
        }
    }
}
Also used : Widget(com.google.gwt.user.client.ui.Widget) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) Method(java.lang.reflect.Method) UiHandler(com.google.gwt.uibinder.client.UiHandler) GwtEvent(com.google.gwt.event.shared.GwtEvent) HashMap(java.util.HashMap) Map(java.util.Map) HasValueChangeHandlers(com.google.gwt.event.logical.shared.HasValueChangeHandlers) DomEvent(com.google.gwt.event.dom.client.DomEvent)

Aggregations

DomEvent (com.google.gwt.event.dom.client.DomEvent)1 HasValueChangeHandlers (com.google.gwt.event.logical.shared.HasValueChangeHandlers)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 GwtEvent (com.google.gwt.event.shared.GwtEvent)1 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 Widget (com.google.gwt.user.client.ui.Widget)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1