Search in sources :

Example 6 with HandlerRegistration

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

the class ViewEventHandlerManager method registerClickHandler.

protected HandlerRegistration[] registerClickHandler(final ViewHandler<ViewEvent> eventHandler) {
    return new HandlerRegistration[] { node.addNodeMouseClickHandler(nodeMouseClickEvent -> {
        if (ViewEventHandlerManager.this.isEnabled()) {
            restoreClickHandler();
            final int x = nodeMouseClickEvent.getX();
            final int y = nodeMouseClickEvent.getY();
            final int clientX = nodeMouseClickEvent.getMouseEvent().getClientX();
            final int clientY = nodeMouseClickEvent.getMouseEvent().getClientY();
            final boolean isShiftKeyDown = nodeMouseClickEvent.isShiftKeyDown();
            final boolean isAltKeyDown = nodeMouseClickEvent.isAltKeyDown();
            final boolean isMetaKeyDown = nodeMouseClickEvent.isMetaKeyDown();
            final boolean isButtonLeft = nodeMouseClickEvent.isButtonLeft();
            final boolean isButtonMiddle = nodeMouseClickEvent.isButtonMiddle();
            final boolean isButtonRight = nodeMouseClickEvent.isButtonRight();
            timer.apply(() -> {
                if (fireClickHandler) {
                    ViewEventHandlerManager.this.onMouseClick(eventHandler, x, y, clientX, clientY, isShiftKeyDown, isAltKeyDown, isMetaKeyDown, isButtonLeft, isButtonMiddle, isButtonRight);
                }
            }, CLICK_HANDLER_TIMER_DURATION);
        }
    }) };
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) TouchPoint(com.ait.lienzo.client.core.event.TouchPoint)

Example 7 with HandlerRegistration

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

the class WiresTextDecorator method registerTextExitHandler.

private void registerTextExitHandler() {
    HandlerRegistration registration = text.addNodeMouseExitHandler(event -> {
        if (null != textOutEventViewHandler && hasText()) {
            final TextExitEvent textOutEvent = new TextExitEvent(event.getX(), event.getY(), event.getMouseEvent().getClientX(), event.getMouseEvent().getClientY());
            textOutEventViewHandler.handle(textOutEvent);
        }
    });
    eventHandlerManager.get().addHandlersRegistration(ViewEventType.TEXT_EXIT, registration);
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) TextExitEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.TextExitEvent)

Example 8 with HandlerRegistration

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

the class LienzoMultipleSelectionControlTest method testCustomSelectionShapeProvider.

@Test
public void testCustomSelectionShapeProvider() {
    final com.ait.lienzo.client.core.shape.Shape shape = mock(com.ait.lienzo.client.core.shape.Shape.class);
    final HandlerRegistration enterHandlerReg = mock(HandlerRegistration.class);
    final HandlerRegistration exitHandlerReg = mock(HandlerRegistration.class);
    when(delegateShapeProvider.getShape()).thenReturn(shape);
    when(shape.addNodeMouseEnterHandler(any(NodeMouseEnterHandler.class))).thenReturn(enterHandlerReg);
    when(shape.addNodeMouseExitHandler(any(NodeMouseExitHandler.class))).thenReturn(exitHandlerReg);
    // Test location.
    final Point2D location = new Point2D(10d, 20d);
    delegateShapeProvider.setLocation(location);
    verify(delegateShapeProvider, times(1)).setLocation(eq(location));
    // Test build & event handlers.
    assertEquals(selectionShapeProvider, selectionShapeProvider.build());
    verify(delegateShapeProvider, times(1)).build();
    ArgumentCaptor<NodeMouseEnterHandler> enterHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseEnterHandler.class);
    ArgumentCaptor<NodeMouseExitHandler> enterExitArgumentCaptor = ArgumentCaptor.forClass(NodeMouseExitHandler.class);
    verify(shape, times(1)).addNodeMouseEnterHandler(enterHandlerArgumentCaptor.capture());
    verify(shape, times(1)).addNodeMouseExitHandler(enterExitArgumentCaptor.capture());
    enterHandlerArgumentCaptor.getValue().onNodeMouseEnter(mock(NodeMouseEnterEvent.class));
    verify(canvasView, times(1)).setCursor(eq(AbstractCanvas.Cursors.MOVE));
    enterExitArgumentCaptor.getValue().onNodeMouseExit(mock(NodeMouseExitEvent.class));
    verify(canvasView, times(1)).setCursor(eq(AbstractCanvas.Cursors.AUTO));
    // Test shape move to top.
    selectionShapeProvider.moveShapeToTop();
    verify(shape, times(1)).moveToTop();
    // Test clear.
    selectionShapeProvider.clear();
    verify(delegateShapeProvider, times(1)).clear();
    verify(enterHandlerReg, times(1)).removeHandler();
    verify(exitHandlerReg, times(1)).removeHandler();
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) Point2D(com.ait.lienzo.client.core.types.Point2D) NodeMouseEnterEvent(com.ait.lienzo.client.core.event.NodeMouseEnterEvent) NodeMouseExitHandler(com.ait.lienzo.client.core.event.NodeMouseExitHandler) NodeMouseEnterHandler(com.ait.lienzo.client.core.event.NodeMouseEnterHandler) NodeMouseExitEvent(com.ait.lienzo.client.core.event.NodeMouseExitEvent) Test(org.junit.Test)

Example 9 with HandlerRegistration

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

the class ViewEventHandlerManagerTest method testClickHandler.

@Test
@SuppressWarnings("unchecked")
public void testClickHandler() {
    final ViewHandler<ViewEvent> clickHandler = mock(ViewHandler.class);
    final HandlerRegistration handlerRegistration = mock(HandlerRegistration.class);
    when(node.addNodeMouseClickHandler(any(NodeMouseClickHandler.class))).thenReturn(handlerRegistration);
    tested.addHandler(ViewEventType.MOUSE_CLICK, clickHandler);
    final ArgumentCaptor<NodeMouseClickHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseClickHandler.class);
    verify(node, times(1)).addNodeMouseClickHandler(clickHandlerArgumentCaptor.capture());
    final NodeMouseClickHandler nodeCLickHandler = clickHandlerArgumentCaptor.getValue();
    final NodeMouseClickEvent clickEvent = mock(NodeMouseClickEvent.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.isButtonLeft()).thenReturn(true);
    when(clickEvent.isButtonRight()).thenReturn(true);
    when(clickEvent.isButtonMiddle()).thenReturn(true);
    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.onNodeMouseClick(clickEvent);
    final ArgumentCaptor<ViewEvent> eventArgumentCaptor = ArgumentCaptor.forClass(ViewEvent.class);
    verify(clickHandler, times(1)).handle(eventArgumentCaptor.capture());
    final MouseClickEvent viewEvent = (MouseClickEvent) eventArgumentCaptor.getValue();
    assertEquals(x, viewEvent.getX(), 0d);
    assertEquals(y, viewEvent.getY(), 0d);
    assertEquals(x, viewEvent.getClientX(), 0d);
    assertEquals(y, viewEvent.getClientY(), 0d);
    assertTrue(viewEvent.isButtonLeft());
    assertTrue(viewEvent.isButtonRight());
    assertTrue(viewEvent.isButtonMiddle());
    assertTrue(viewEvent.isAltKeyDown());
    assertTrue(viewEvent.isMetaKeyDown());
    assertTrue(viewEvent.isShiftKeyDown());
    assertNotNull(tested.getRegistrationMap().get(ViewEventType.MOUSE_CLICK));
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) NodeMouseClickHandler(com.ait.lienzo.client.core.event.NodeMouseClickHandler) MouseEvent(com.google.gwt.event.dom.client.MouseEvent) ViewEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.ViewEvent) NodeMouseClickEvent(com.ait.lienzo.client.core.event.NodeMouseClickEvent) NodeMouseClickEvent(com.ait.lienzo.client.core.event.NodeMouseClickEvent) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Test(org.junit.Test)

Example 10 with HandlerRegistration

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

the class ViewEventHandlerManagerTest method testMouseEXitHandler.

@Test
@SuppressWarnings("unchecked")
public void testMouseEXitHandler() {
    final ViewHandler<ViewEvent> clickHandler = mock(ViewHandler.class);
    final HandlerRegistration handlerRegistration = mock(HandlerRegistration.class);
    when(shape.addNodeMouseExitHandler(any(NodeMouseExitHandler.class))).thenReturn(handlerRegistration);
    tested.addHandler(ViewEventType.MOUSE_EXIT, clickHandler);
    final ArgumentCaptor<NodeMouseExitHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseExitHandler.class);
    verify(shape, times(1)).addNodeMouseExitHandler(clickHandlerArgumentCaptor.capture());
    final NodeMouseExitHandler nodeCLickHandler = clickHandlerArgumentCaptor.getValue();
    final NodeMouseExitEvent clickEvent = mock(NodeMouseExitEvent.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.onNodeMouseExit(clickEvent);
    final ArgumentCaptor<ViewEvent> eventArgumentCaptor = ArgumentCaptor.forClass(ViewEvent.class);
    verify(clickHandler, times(1)).handle(eventArgumentCaptor.capture());
    final MouseExitEvent viewEvent = (MouseExitEvent) 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_EXIT));
}
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) NodeMouseExitHandler(com.ait.lienzo.client.core.event.NodeMouseExitHandler) MouseExitEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitEvent) NodeMouseExitEvent(com.ait.lienzo.client.core.event.NodeMouseExitEvent) NodeMouseExitEvent(com.ait.lienzo.client.core.event.NodeMouseExitEvent) Test(org.junit.Test)

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