Search in sources :

Example 6 with CanvasSelectionEvent

use of org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent in project kie-wb-common by kiegroup.

the class MapSelectionControlTest method testLayerClickAndSelectRootElement.

@Test
public void testLayerClickAndSelectRootElement() {
    tested.enable(canvasHandler);
    final ArgumentCaptor<MouseClickHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(MouseClickHandler.class);
    verify(layer, 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 7 with CanvasSelectionEvent

use of org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent in project kie-wb-common by kiegroup.

the class MapSelectionControlTest method testOnSelectEvent.

@Test
public void testOnSelectEvent() {
    tested.enable(canvasHandler);
    tested.register(element);
    CanvasSelectionEvent event = new CanvasSelectionEvent(canvasHandler, ELEMENT_UUID);
    tested.onCanvasElementSelected(event);
    assertEquals(1, tested.getSelectedItems().size());
    assertEquals(ELEMENT_UUID, tested.getSelectedItems().iterator().next());
    verify(shape, times(1)).applyState(eq(ShapeState.SELECTED));
    verify(shape, times(1)).applyState(eq(ShapeState.NONE));
    verify(shape, never()).applyState(eq(ShapeState.INVALID));
    verify(shape, never()).applyState(eq(ShapeState.HIGHLIGHT));
    final ArgumentCaptor<CanvasSelectionEvent> elementSelectedEventArgumentCaptor = ArgumentCaptor.forClass(CanvasSelectionEvent.class);
    verify(elementSelectedEvent, times(1)).fire(elementSelectedEventArgumentCaptor.capture());
    final CanvasSelectionEvent selectionEvent = elementSelectedEventArgumentCaptor.getValue();
    assertEquals(1, selectionEvent.getIdentifiers().size());
    assertEquals(ELEMENT_UUID, selectionEvent.getIdentifiers().iterator().next());
}
Also used : CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) Test(org.junit.Test)

Example 8 with CanvasSelectionEvent

use of org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent in project kie-wb-common by kiegroup.

the class MapSelectionControlTest method testSelect.

@Test
public void testSelect() {
    tested.enable(canvasHandler);
    tested.register(element);
    tested.select(element);
    assertEquals(1, tested.getSelectedItems().size());
    assertEquals(ELEMENT_UUID, tested.getSelectedItems().iterator().next());
    verify(shape, times(1)).applyState(eq(ShapeState.SELECTED));
    verify(shape, never()).applyState(eq(ShapeState.NONE));
    verify(shape, never()).applyState(eq(ShapeState.INVALID));
    verify(shape, never()).applyState(eq(ShapeState.HIGHLIGHT));
    final ArgumentCaptor<CanvasSelectionEvent> elementSelectedEventArgumentCaptor = ArgumentCaptor.forClass(CanvasSelectionEvent.class);
    verify(elementSelectedEvent, times(1)).fire(elementSelectedEventArgumentCaptor.capture());
    final CanvasSelectionEvent event = elementSelectedEventArgumentCaptor.getValue();
    assertEquals(1, event.getIdentifiers().size());
    assertEquals(ELEMENT_UUID, event.getIdentifiers().iterator().next());
}
Also used : CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) Test(org.junit.Test)

Example 9 with CanvasSelectionEvent

use of org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent in project kie-wb-common by kiegroup.

the class ToolboxControlTest method testElementSelectedEvent.

@Test
public void testElementSelectedEvent() {
    final String uuid = "uuid1";
    when(element.getUUID()).thenReturn(uuid);
    final CanvasSelectionEvent event = new CanvasSelectionEvent(canvasHandler, element.getUUID());
    tested.onCanvasSelectionEvent(event);
    verify(delegated, times(1)).show(eq(uuid));
    verify(delegated, never()).destroy();
}
Also used : CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 10 with CanvasSelectionEvent

use of org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent in project kie-wb-common by kiegroup.

the class CreateNodeActionTest method testAction.

@Test
@SuppressWarnings("unchecked")
public void testAction() {
    when(canvasLayoutUtils.getNext(eq(canvasHandler), eq(element), eq(targetNode))).thenReturn(new Point2D(100d, 500d));
    final MouseClickEvent event = mock(MouseClickEvent.class);
    when(event.getX()).thenReturn(100d);
    when(event.getY()).thenReturn(500d);
    ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, NODE_UUID, event);
    assertEquals(tested, cascade);
    ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
    verify(sessionCommandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
    DeferredCompositeCommand command = (DeferredCompositeCommand) commandArgumentCaptor.getValue();
    DeferredCommand c0 = (DeferredCommand) command.getCommands().get(0);
    DeferredCommand c1 = (DeferredCommand) command.getCommands().get(1);
    DeferredCommand c2 = (DeferredCommand) command.getCommands().get(2);
    DeferredCommand c3 = (DeferredCommand) command.getCommands().get(3);
    AddNodeCommand addNodeCommand = (AddNodeCommand) c0.getCommand();
    UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) c1.getCommand();
    AddConnectorCommand addConnectorCommand = (AddConnectorCommand) c2.getCommand();
    SetConnectionTargetNodeCommand setTargetNodeCommand = (SetConnectionTargetNodeCommand) c3.getCommand();
    assertEquals(targetNode, addNodeCommand.getCandidate());
    assertEquals("ss1", addNodeCommand.getShapeSetId());
    assertEquals(edge, addConnectorCommand.getCandidate());
    assertEquals(element, addConnectorCommand.getSource());
    assertEquals("ss1", addConnectorCommand.getShapeSetId());
    assertEquals(edge, setTargetNodeCommand.getEdge());
    assertEquals(targetNode, setTargetNodeCommand.getNode());
    assertEquals(targetNode, updateElementPositionCommand.getElement());
    assertEquals(new Point2D(100d, 500d), updateElementPositionCommand.getLocation());
    final ArgumentCaptor<CanvasSelectionEvent> eventArgumentCaptor = ArgumentCaptor.forClass(CanvasSelectionEvent.class);
    verify(canvasElementSelectedEvent, times(1)).fire(eventArgumentCaptor.capture());
    final CanvasSelectionEvent eCaptured = eventArgumentCaptor.getValue();
    assertEquals(TARGET_NODE_UUID, eCaptured.getIdentifiers().iterator().next());
}
Also used : DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionTargetNodeCommand) AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) AddConnectorCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddConnectorCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionTargetNodeCommand) Command(org.kie.workbench.common.stunner.core.command.Command) DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) DeferredCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) AddConnectorCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddConnectorCommand) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) DeferredCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCommand) Test(org.junit.Test)

Aggregations

CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)15 Test (org.junit.Test)10 MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)5 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)4 MouseClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler)3 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 Layer (org.kie.workbench.common.stunner.core.client.canvas.Layer)2 CanvasClearSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent)2 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)2 Timer (com.google.gwt.user.client.Timer)1 Collections (java.util.Collections)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 RunWith (org.junit.runner.RunWith)1 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)1 CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)1 AddConnectorCommand (org.kie.workbench.common.stunner.core.client.canvas.command.AddConnectorCommand)1 AddNodeCommand (org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand)1