Search in sources :

Example 21 with MouseClickEvent

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

the class DMNDeleteNodeToolboxActionTest method testOnMouseClickWhenNodeRequiresDeletionConfirmation.

@Test
public void testOnMouseClickWhenNodeRequiresDeletionConfirmation() {
    final String nodeUuid = "node uuid";
    final Element element = mock(Element.class);
    final Node node = mock(Node.class);
    final MouseClickEvent event = new MouseClickEvent(0, 0, 0, 0);
    when(element.asNode()).thenReturn(node);
    when(graphIndex.get(nodeUuid)).thenReturn(element);
    when(deleteNodeConfirmation.requiresDeletionConfirmation(Collections.singleton(node))).thenReturn(true);
    toolboxAction.onMouseClick(canvasHandler, nodeUuid, event);
    verify(deleteNodeConfirmation).confirmDeletion(any(), any(), any());
    verify(toolboxAction, never()).superOnMouseClick(canvasHandler, nodeUuid, event);
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Test(org.junit.Test)

Example 22 with MouseClickEvent

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

the class DMNEditDecisionToolboxActionTest method testActionWhenIsReadOnlyDiagram.

@Test
public void testActionWhenIsReadOnlyDiagram() {
    when(readOnlyProvider.isReadOnlyDiagram()).thenReturn(true);
    final MouseClickEvent event = mock(MouseClickEvent.class);
    final ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, event);
    assertEquals(tested, cascade);
    final ArgumentCaptor<EditExpressionEvent> eventCaptor = ArgumentCaptor.forClass(EditExpressionEvent.class);
    verify(editExpressionEvent, times(1)).fire(eventCaptor.capture());
    final EditExpressionEvent editExprEvent = eventCaptor.getValue();
    assertEquals(E_UUID, editExprEvent.getNodeUUID());
    assertEquals(decision, editExprEvent.getHasExpression());
    assertEquals(decision, editExprEvent.getHasName().get());
    assertEquals(session, editExprEvent.getSession());
    assertTrue(editExprEvent.isOnlyVisualChangeAllowed());
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Test(org.junit.Test)

Example 23 with MouseClickEvent

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

the class MapSelectionControlTest method testLayerClickAndClear.

@Test
public void testLayerClickAndClear() {
    when(metadata.getCanvasRootUUID()).thenReturn(null);
    tested.init(canvasHandler);
    final ArgumentCaptor<MouseClickHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(MouseClickHandler.class);
    verify(canvas, times(1)).addHandler(eq(ViewEventType.MOUSE_CLICK), clickHandlerArgumentCaptor.capture());
    final MouseClickHandler clickHandler = clickHandlerArgumentCaptor.getValue();
    final MouseClickEvent event = new MouseClickEvent(12, 20, 30, 40);
    event.setButtonLeft(true);
    event.setShiftKeyDown(false);
    clickHandler.handle(event);
    verify(clearSelectionEvent, times(1)).fire(any(CanvasClearSelectionEvent.class));
    verify(elementSelectedEvent, never()).fire(any(CanvasSelectionEvent.class));
}
Also used : CanvasClearSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent) MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Test(org.junit.Test)

Example 24 with MouseClickEvent

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

the class MapSelectionControlTest method testLayerClickAndSelectRootElement.

@Test
public void testLayerClickAndSelectRootElement() {
    tested.init(canvasHandler);
    final ArgumentCaptor<MouseClickHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(MouseClickHandler.class);
    verify(canvas, times(1)).addHandler(eq(ViewEventType.MOUSE_CLICK), clickHandlerArgumentCaptor.capture());
    final MouseClickHandler clickHandler = clickHandlerArgumentCaptor.getValue();
    final MouseClickEvent event = new MouseClickEvent(12, 20, 30, 40);
    event.setButtonLeft(true);
    event.setShiftKeyDown(false);
    clickHandler.handle(event);
    final ArgumentCaptor<CanvasSelectionEvent> elementSelectedEventArgumentCaptor = ArgumentCaptor.forClass(CanvasSelectionEvent.class);
    verify(elementSelectedEvent, times(1)).fire(elementSelectedEventArgumentCaptor.capture());
    verify(clearSelectionEvent, times(1)).fire(any(CanvasClearSelectionEvent.class));
    final CanvasSelectionEvent ese = elementSelectedEventArgumentCaptor.getValue();
    assertEquals(ROOT_UUID, ese.getIdentifiers().iterator().next());
}
Also used : CanvasClearSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent) MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Test(org.junit.Test)

Example 25 with MouseClickEvent

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

the class ToolboxControlImpl method register.

@Override
@SuppressWarnings("unchecked")
public void register(final Element element) {
    if (checkNotRegistered(element) && supportsToolbox(element)) {
        final Shape shape = canvasHandler.getCanvas().getShape(element.getUUID());
        final HasEventHandlers hasEventHandlers = (HasEventHandlers) shape.getShapeView();
        if (hasEventHandlers.supports(ViewEventType.MOUSE_CLICK)) {
            final MouseClickHandler clickHandler = new MouseClickHandler() {

                @Override
                public void handle(final MouseClickEvent event) {
                    if (event.isButtonLeft()) {
                        show(element);
                    }
                }
            };
            hasEventHandlers.addHandler(ViewEventType.MOUSE_CLICK, clickHandler);
            registerHandler(element.getUUID(), clickHandler);
        }
    }
}
Also used : Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) 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