Search in sources :

Example 6 with MouseClickEvent

use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent 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 7 with MouseClickEvent

use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent in project kie-wb-common by kiegroup.

the class LienzoSelectionControlTest method testRegisterAndClick.

@Test
public void testRegisterAndClick() {
    tested.init(canvasHandler);
    tested.register(element);
    verify(selectionControl, times(1)).register(eq(element));
    ArgumentCaptor<MouseClickHandler> clickHandlerCaptor = ArgumentCaptor.forClass(MouseClickHandler.class);
    verify(shapeViewHandlers, times(1)).supports(eq(ViewEventType.MOUSE_CLICK));
    verify(shapeViewHandlers, times(1)).addHandler(eq(ViewEventType.MOUSE_CLICK), clickHandlerCaptor.capture());
    final MouseClickHandler clickHandler = clickHandlerCaptor.getValue();
    assertEquals(clickHandler, tested.getHandlers().get(ELEMENT_UUID));
    MouseClickEvent event = mock(MouseClickEvent.class);
    when(event.isButtonLeft()).thenReturn(true);
    clickHandler.handle(event);
    verify(selectionControl, times(1)).select(eq(element.getUUID()));
}
Also used : MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Test(org.junit.Test)

Example 8 with MouseClickEvent

use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent in project kie-wb-common by kiegroup.

the class FormGenerationToolboxActionTest method testOnClick.

@Test
@SuppressWarnings("unchecked")
public void testOnClick() {
    final MouseClickEvent event = mock(MouseClickEvent.class);
    tested.onMouseClick(canvasHandler, "uuid", event);
    verify(formGenerationManager, times(1)).call(any(Consumer.class));
    verify(formGenerationService, times(1)).generateSelectedForms(eq(diagram), eq(new String[] { "uuid" }));
}
Also used : Consumer(java.util.function.Consumer) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Test(org.junit.Test)

Example 9 with MouseClickEvent

use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent in project kie-wb-common by kiegroup.

the class LienzoSelectionControl method onRegister.

@Override
protected void onRegister(final Element element) {
    super.onRegister(element);
    final Shape<?> shape = getSelectionControl().getCanvas().getShape(element.getUUID());
    if (null != shape) {
        final ShapeView shapeView = shape.getShapeView();
        if (shapeView instanceof HasEventHandlers) {
            final HasEventHandlers hasEventHandlers = (HasEventHandlers) shapeView;
            if (hasEventHandlers.supports(ViewEventType.MOUSE_CLICK)) {
                final MouseClickHandler clickHandler = new MouseClickHandler() {

                    @Override
                    public void handle(final MouseClickEvent event) {
                        if (event.isButtonLeft() || event.isButtonRight()) {
                            singleSelect(element);
                        }
                    }
                };
                hasEventHandlers.addHandler(ViewEventType.MOUSE_CLICK, clickHandler);
                registerHandler(shape.getUUID(), clickHandler);
            }
        }
    }
}
Also used : MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)

Example 10 with MouseClickEvent

use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent in project kie-wb-common by kiegroup.

the class ViewEventHandlerManager method onMouseClick.

private void onMouseClick(final ViewHandler<ViewEvent> eventHandler, final int x, final int y, final int clientX, final int clientY, final boolean isShiftKeyDown, final boolean isAltKeyDown, final boolean isMetaKeyDown, final boolean isButtonLeft, final boolean isButtonMiddle, final boolean isButtonRight) {
    final MouseClickEvent event = new MouseClickEvent(x, y, clientX, clientY);
    event.setShiftKeyDown(isShiftKeyDown);
    event.setAltKeyDown(isAltKeyDown);
    event.setMetaKeyDown(isMetaKeyDown);
    event.setButtonLeft(isButtonLeft);
    event.setButtonMiddle(isButtonMiddle);
    event.setButtonRight(isButtonRight);
    eventHandler.handle(event);
}
Also used : MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)

Aggregations

MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)25 Test (org.junit.Test)17 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)11 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)7 MouseClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler)7 CanvasClearSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent)4 Node (org.kie.workbench.common.stunner.core.graph.Node)4 NodeMouseClickEvent (com.ait.lienzo.client.core.event.NodeMouseClickEvent)2 NodeMouseClickHandler (com.ait.lienzo.client.core.event.NodeMouseClickHandler)2 MouseEvent (com.google.gwt.event.dom.client.MouseEvent)2 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)2 Consumer (java.util.function.Consumer)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Before (org.junit.Before)2 RunWith (org.junit.runner.RunWith)2 EditExpressionEvent (org.kie.workbench.common.dmn.client.events.EditExpressionEvent)2 CanvasCommand (org.kie.workbench.common.stunner.core.client.command.CanvasCommand)2 SessionCommandManager (org.kie.workbench.common.stunner.core.client.command.SessionCommandManager)2 ClientTranslationService (org.kie.workbench.common.stunner.core.client.i18n.ClientTranslationService)2 HasEventHandlers (org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)2