Search in sources :

Example 1 with EventHandler

use of com.google.gwt.event.shared.EventHandler in project rstudio by rstudio.

the class EventBus method addHandler.

/**
    * Similar to 2-arg form of addHandler, but automatically removes handler
    * when the HasAttachHandlers object detaches.
    *
    * If the HasAttachHandlers object detaches and reattaches, the handler
    * will NOT automatically resubscribe.
    */
public <H extends EventHandler> void addHandler(HasAttachHandlers removeWhenDetached, Type<H> type, H handler) {
    final HandlerRegistration reg = addHandler(type, handler);
    removeWhenDetached.addAttachHandler(new Handler() {

        @Override
        public void onAttachOrDetach(AttachEvent event) {
            if (!event.isAttached())
                reg.removeHandler();
        }
    });
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) AttachEvent(com.google.gwt.event.logical.shared.AttachEvent) EventHandler(com.google.gwt.event.shared.EventHandler) Handler(com.google.gwt.event.logical.shared.AttachEvent.Handler)

Example 2 with EventHandler

use of com.google.gwt.event.shared.EventHandler in project opennms by OpenNMS.

the class SearchControl method doOnAdd.

public Element doOnAdd() {
    LOG.info("SearchControl.onAdd() called");
    this.add(m_inputBox);
    this.add(m_autoComplete);
    /* If the backend sends a new search string, set it on the input box
         * to make sure we're in sync, but don't re-fire events.
         */
    m_eventManager.addHandler(SearchStringSetEvent.TYPE, this);
    m_eventManager.addHandler(FilteredMarkersUpdatedEvent.TYPE, this);
    final SearchEventHandler searchEventHandler = new SearchEventHandler() {

        @Override
        protected void onEvent(final DomEvent<? extends EventHandler> event) {
            m_stateManager.handleInputEvent(event.getNativeEvent());
        }
    };
    m_autoComplete.addHandler(new KeyDownHandler() {

        @Override
        public void onKeyDown(final KeyDownEvent event) {
            m_stateManager.handleAutocompleteEvent(event.getNativeEvent());
        }
    }, KeyDownEvent.getType());
    m_inputBox.addKeyDownHandler(searchEventHandler);
    m_inputBox.addChangeHandler(searchEventHandler);
    m_inputBox.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(final ClickEvent event) {
            SearchEvent.fireNativeEvent(Document.get().createChangeEvent(), m_inputBox);
        }
    });
    m_inputBox.addHandler(searchEventHandler, CutEvent.getType());
    m_inputBox.addHandler(searchEventHandler, PasteEvent.getType());
    m_inputBox.addHandler(searchEventHandler, SearchEvent.getType());
    m_componentTracker.ready(getClass());
    return this.getElement();
}
Also used : KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) SearchEventHandler(org.opennms.features.vaadin.nodemaps.internal.gwt.client.event.SearchEventHandler) EventHandler(com.google.gwt.event.shared.EventHandler) SearchStringSetEventHandler(org.opennms.features.vaadin.nodemaps.internal.gwt.client.event.SearchStringSetEventHandler) FilteredMarkersUpdatedEventHandler(org.opennms.features.vaadin.nodemaps.internal.gwt.client.event.FilteredMarkersUpdatedEventHandler) SearchEventHandler(org.opennms.features.vaadin.nodemaps.internal.gwt.client.event.SearchEventHandler) DomEvent(com.google.gwt.event.dom.client.DomEvent)

Example 3 with EventHandler

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

the class UiBinderInvocationHandler method createHandler.

private EventHandler createHandler(Widget uiField, Method uiHandlerMethod, Object uiHandlerOwner) {
    Class<EventHandler> eventHandlerClass = findHandlerClass(uiHandlerMethod);
    InvocationHandler eventHandlerInvocationHandler = createEventHandlerInvocationHandler(uiHandlerMethod, uiHandlerOwner);
    return (EventHandler) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { eventHandlerClass }, eventHandlerInvocationHandler);
}
Also used : EventHandler(com.google.gwt.event.shared.EventHandler) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 4 with EventHandler

use of com.google.gwt.event.shared.EventHandler in project drools-wb by kiegroup.

the class ListBoxSingletonDOMElementFactoryTest method checkDOMElementCreationBlurHandler.

@Test
@SuppressWarnings("unchecked")
public void checkDOMElementCreationBlurHandler() {
    final GridBodyCellRenderContext context = mock(GridBodyCellRenderContext.class);
    final Consumer<ListBoxDOMElement<String, ListBox>> onCreation = mock(Consumer.class);
    final Consumer<ListBoxDOMElement<String, ListBox>> onDisplay = mock(Consumer.class);
    when(context.getTransform()).thenReturn(mock(Transform.class));
    factory.attachDomElement(context, onCreation, onDisplay);
    final ArgumentCaptor<EventHandler> handlerCaptor = ArgumentCaptor.forClass(EventHandler.class);
    verify(listBox, times(4)).addDomHandler(handlerCaptor.capture(), any(DomEvent.Type.class));
    // KeyDownHandlerCommon
    Assertions.assertThat(handlerCaptor.getAllValues().get(0)).isInstanceOf(KeyDownHandlerCommon.class);
    // KeyDownHandler - stopPropagation
    final KeyDownEvent keyDownEventMock = mock(KeyDownEvent.class);
    Assertions.assertThat(handlerCaptor.getAllValues().get(1)).isInstanceOf(KeyDownHandler.class);
    ((KeyDownHandler) handlerCaptor.getAllValues().get(1)).onKeyDown(keyDownEventMock);
    verify(keyDownEventMock).stopPropagation();
    // MouseDownHandler - stopPropagation
    final MouseDownEvent mouseDownEventMock = mock(MouseDownEvent.class);
    Assertions.assertThat(handlerCaptor.getAllValues().get(2)).isInstanceOf(MouseDownHandler.class);
    ((MouseDownHandler) handlerCaptor.getAllValues().get(2)).onMouseDown(mouseDownEventMock);
    verify(mouseDownEventMock).stopPropagation();
    // BlurHandler
    final BlurEvent blurEventMock = mock(BlurEvent.class);
    Assertions.assertThat(handlerCaptor.getAllValues().get(3)).isInstanceOf(BlurHandler.class);
    ((BlurHandler) handlerCaptor.getAllValues().get(3)).onBlur(blurEventMock);
    verify(factory).flush();
    verify(gridLayer).batch();
    verify(gridLienzoPanel).setFocus(true);
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) EventHandler(com.google.gwt.event.shared.EventHandler) MouseDownEvent(com.google.gwt.event.dom.client.MouseDownEvent) GridBodyCellRenderContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellRenderContext) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) BlurEvent(com.google.gwt.event.dom.client.BlurEvent) Transform(com.ait.lienzo.client.core.types.Transform) MouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler) Test(org.junit.Test)

Aggregations

EventHandler (com.google.gwt.event.shared.EventHandler)4 KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)2 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)2 Transform (com.ait.lienzo.client.core.types.Transform)1 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)1 BlurHandler (com.google.gwt.event.dom.client.BlurHandler)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 DomEvent (com.google.gwt.event.dom.client.DomEvent)1 MouseDownEvent (com.google.gwt.event.dom.client.MouseDownEvent)1 MouseDownHandler (com.google.gwt.event.dom.client.MouseDownHandler)1 AttachEvent (com.google.gwt.event.logical.shared.AttachEvent)1 Handler (com.google.gwt.event.logical.shared.AttachEvent.Handler)1 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Test (org.junit.Test)1 FilteredMarkersUpdatedEventHandler (org.opennms.features.vaadin.nodemaps.internal.gwt.client.event.FilteredMarkersUpdatedEventHandler)1 SearchEventHandler (org.opennms.features.vaadin.nodemaps.internal.gwt.client.event.SearchEventHandler)1 SearchStringSetEventHandler (org.opennms.features.vaadin.nodemaps.internal.gwt.client.event.SearchStringSetEventHandler)1 GridBodyCellRenderContext (org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellRenderContext)1