Search in sources :

Example 36 with HandlerRegistration

use of com.google.gwt.event.shared.HandlerRegistration in project kie-wb-common by kiegroup.

the class ViewEventHandlerManagerTest method testMouseEnterHandler.

@Test
@SuppressWarnings("unchecked")
public void testMouseEnterHandler() {
    final ViewHandler<ViewEvent> clickHandler = mock(ViewHandler.class);
    final HandlerRegistration handlerRegistration = mock(HandlerRegistration.class);
    when(shape.addNodeMouseEnterHandler(any(NodeMouseEnterHandler.class))).thenReturn(handlerRegistration);
    tested.addHandler(ViewEventType.MOUSE_ENTER, clickHandler);
    final ArgumentCaptor<NodeMouseEnterHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseEnterHandler.class);
    verify(shape, times(1)).addNodeMouseEnterHandler(clickHandlerArgumentCaptor.capture());
    final NodeMouseEnterHandler nodeCLickHandler = clickHandlerArgumentCaptor.getValue();
    final NodeMouseEnterEvent clickEvent = mock(NodeMouseEnterEvent.class);
    final MouseEvent mouseEvent = mock(MouseEvent.class);
    final int x = 102;
    final int y = 410;
    when(clickEvent.getX()).thenReturn(x);
    when(clickEvent.getY()).thenReturn(y);
    when(clickEvent.isShiftKeyDown()).thenReturn(true);
    when(clickEvent.isAltKeyDown()).thenReturn(true);
    when(clickEvent.isMetaKeyDown()).thenReturn(true);
    when(clickEvent.getMouseEvent()).thenReturn(mouseEvent);
    when(mouseEvent.getClientX()).thenReturn(x);
    when(mouseEvent.getClientY()).thenReturn(y);
    nodeCLickHandler.onNodeMouseEnter(clickEvent);
    final ArgumentCaptor<ViewEvent> eventArgumentCaptor = ArgumentCaptor.forClass(ViewEvent.class);
    verify(clickHandler, times(1)).handle(eventArgumentCaptor.capture());
    final MouseEnterEvent viewEvent = (MouseEnterEvent) eventArgumentCaptor.getValue();
    assertEquals(x, viewEvent.getX(), 0d);
    assertEquals(y, viewEvent.getY(), 0d);
    assertEquals(x, viewEvent.getClientX(), 0d);
    assertEquals(y, viewEvent.getClientY(), 0d);
    assertTrue(viewEvent.isAltKeyDown());
    assertTrue(viewEvent.isMetaKeyDown());
    assertTrue(viewEvent.isShiftKeyDown());
    assertNotNull(tested.getRegistrationMap().get(ViewEventType.MOUSE_ENTER));
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) MouseEvent(com.google.gwt.event.dom.client.MouseEvent) ViewEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.ViewEvent) NodeMouseEnterEvent(com.ait.lienzo.client.core.event.NodeMouseEnterEvent) NodeMouseEnterEvent(com.ait.lienzo.client.core.event.NodeMouseEnterEvent) MouseEnterEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterEvent) NodeMouseEnterHandler(com.ait.lienzo.client.core.event.NodeMouseEnterHandler) Test(org.junit.Test)

Example 37 with HandlerRegistration

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

the class AnalyzerControllerImplTest method areHandlersTornDownOnTerminate.

@Test
public void areHandlersTornDownOnTerminate() throws Exception {
    final HandlerRegistration validateEvent = mock(HandlerRegistration.class);
    when(eventBus.addHandler(ValidateEvent.TYPE, controller)).thenReturn(validateEvent);
    final HandlerRegistration deleteRowEvent = mock(HandlerRegistration.class);
    when(eventBus.addHandler(DeleteRowEvent.TYPE, controller)).thenReturn(deleteRowEvent);
    final HandlerRegistration afterColumnDeleted = mock(HandlerRegistration.class);
    when(eventBus.addHandler(AfterColumnDeleted.TYPE, controller)).thenReturn(afterColumnDeleted);
    final HandlerRegistration updateColumnDataEvent = mock(HandlerRegistration.class);
    when(eventBus.addHandler(UpdateColumnDataEvent.TYPE, controller)).thenReturn(updateColumnDataEvent);
    final HandlerRegistration appendRowEvent = mock(HandlerRegistration.class);
    when(eventBus.addHandler(AppendRowEvent.TYPE, controller)).thenReturn(appendRowEvent);
    final HandlerRegistration insertRowEvent = mock(HandlerRegistration.class);
    when(eventBus.addHandler(InsertRowEvent.TYPE, controller)).thenReturn(insertRowEvent);
    final HandlerRegistration afterColumnInserted = mock(HandlerRegistration.class);
    when(eventBus.addHandler(AfterColumnInserted.TYPE, controller)).thenReturn(afterColumnInserted);
    controller.initialiseAnalysis();
    controller.terminateAnalysis();
    verify(validateEvent).removeHandler();
    verify(deleteRowEvent).removeHandler();
    verify(afterColumnDeleted).removeHandler();
    verify(updateColumnDataEvent).removeHandler();
    verify(appendRowEvent).removeHandler();
    verify(insertRowEvent).removeHandler();
    verify(afterColumnDeleted).removeHandler();
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) Test(org.junit.Test)

Example 38 with HandlerRegistration

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

the class EventsTest method tearDownRemovesHandlers.

@Test
public void tearDownRemovesHandlers() throws Exception {
    final HandlerRegistration registration = mock(HandlerRegistration.class);
    when(eventBus.addHandler(ValidateEvent.TYPE, analyzerController)).thenReturn(registration);
    mockOtherEventHandlerRegistrations();
    events.setup();
    events.teardown();
    verify(registration).removeHandler();
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) Test(org.junit.Test)

Example 39 with HandlerRegistration

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

the class FieldDatePicker method addValueChangeHandler.

public HandlerRegistration addValueChangeHandler(final ValueChangeHandler<String> handler) {
    HandlerRegistration registration = new HandlerRegistration() {

        @Override
        public void removeHandler() {
            handlerManager.removeHandler(ValueChangeEvent.getType(), handler);
        }
    };
    handlerManager.addHandler(ValueChangeEvent.getType(), handler);
    return registration;
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration)

Example 40 with HandlerRegistration

use of com.google.gwt.event.shared.HandlerRegistration in project gwt-ol3 by TDesjardins.

the class Map method addMapMoveListener.

/**
 * Adds a map move listener for the given map.
 */
@JsOverlay
public final HandlerRegistration addMapMoveListener(final EventListener<MapEvent> listener) {
    final HandlerRegistration handlerMap = OLUtil.observe(this, "moveend", listener);
    View view = getView();
    if (view == null)
        return handlerMap;
    // if we have a view, fire events while the map is moving
    // try to set up an event handler for the change of the view center
    // as "moveend" will be only fired when the map stops moving
    final HandlerRegistration handlerView = OLUtil.observe(view, "change:center", event -> {
        // create an artificial move event
        ol.events.Event e2 = OLUtil.createLinkedEvent(event, "move", Map.this);
        MapEvent mapEvent = OLUtil.initMapEvent(e2, Map.this);
        listener.onEvent(mapEvent);
    });
    // return a handler registration, which detaches both event handlers
    return () -> {
        handlerMap.removeHandler();
        handlerView.removeHandler();
    };
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) JsOverlay(jsinterop.annotations.JsOverlay)

Aggregations

HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)48 Test (org.junit.Test)7 MouseEvent (com.google.gwt.event.dom.client.MouseEvent)4 ViewEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.ViewEvent)4 NodeMouseEnterEvent (com.ait.lienzo.client.core.event.NodeMouseEnterEvent)2 NodeMouseEnterHandler (com.ait.lienzo.client.core.event.NodeMouseEnterHandler)2 NodeMouseExitEvent (com.ait.lienzo.client.core.event.NodeMouseExitEvent)2 NodeMouseExitHandler (com.ait.lienzo.client.core.event.NodeMouseExitHandler)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 Widget (com.google.gwt.user.client.ui.Widget)2 Map (java.util.Map)2 MouseDoubleClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseDoubleClickEvent)2 MouseEnterEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterEvent)2 CommandWithArg (org.rstudio.core.client.CommandWithArg)2 Mutable (org.rstudio.core.client.Mutable)2 Attribute (com.ait.lienzo.client.core.Attribute)1 AbstractNodeGestureEvent (com.ait.lienzo.client.core.event.AbstractNodeGestureEvent)1 NodeGestureChangeEvent (com.ait.lienzo.client.core.event.NodeGestureChangeEvent)1 NodeGestureChangeHandler (com.ait.lienzo.client.core.event.NodeGestureChangeHandler)1