Search in sources :

Example 1 with SetConnectionTargetNodeCommand

use of org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionTargetNodeCommand 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)

Example 2 with SetConnectionTargetNodeCommand

use of org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionTargetNodeCommand in project kie-wb-common by kiegroup.

the class ConnectionAcceptorControlImplTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(canvasHandler.getCanvas()).thenReturn(canvas);
    when(canvasHandler.getAbstractCanvas()).thenReturn(canvas);
    when(canvas.getView()).thenReturn(canvasView);
    when(edge.getContent()).thenReturn(edgeContent);
    when(edgeContent.getSourceConnection()).thenReturn(Optional.empty());
    when(edgeContent.getTargetConnection()).thenReturn(Optional.empty());
    doAnswer(invocationOnMock -> {
        final Node node = (Node) invocationOnMock.getArguments()[0];
        final Edge edge = (Edge) invocationOnMock.getArguments()[1];
        final Connection connection = (Connection) invocationOnMock.getArguments()[2];
        setConnectionSourceNodeCommand = new SetConnectionSourceNodeCommand(node, edge, connection);
        return setConnectionSourceNodeCommand;
    }).when(canvasCommandFactory).setSourceNode(any(Node.class), any(Edge.class), any(Connection.class));
    doAnswer(invocationOnMock -> {
        final Node node = (Node) invocationOnMock.getArguments()[0];
        final Edge edge = (Edge) invocationOnMock.getArguments()[1];
        final Connection connection = (Connection) invocationOnMock.getArguments()[2];
        setConnectionTargetNodeCommand = new SetConnectionTargetNodeCommand(node, edge, connection);
        return setConnectionTargetNodeCommand;
    }).when(canvasCommandFactory).setTargetNode(any(Node.class), any(Edge.class), any(Connection.class));
    when(commandManager.allow(eq(canvasHandler), eq(setConnectionSourceNodeCommand))).thenReturn(result);
    when(commandManager.execute(eq(canvasHandler), eq(setConnectionSourceNodeCommand))).thenReturn(result);
    when(commandManager.allow(eq(canvasHandler), eq(setConnectionTargetNodeCommand))).thenReturn(result);
    when(commandManager.execute(eq(canvasHandler), eq(setConnectionTargetNodeCommand))).thenReturn(result);
    this.tested = new ConnectionAcceptorControlImpl(canvasCommandFactory, cancelCanvasActionEvent);
    this.tested.setCommandManagerProvider(() -> commandManager);
}
Also used : SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionTargetNodeCommand) Node(org.kie.workbench.common.stunner.core.graph.Node) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) WiresConnection(com.ait.lienzo.client.core.shape.wires.WiresConnection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) SetConnectionSourceNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionSourceNodeCommand) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Before(org.junit.Before)

Aggregations

SetConnectionTargetNodeCommand (org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionTargetNodeCommand)2 WiresConnection (com.ait.lienzo.client.core.shape.wires.WiresConnection)1 Before (org.junit.Before)1 Test (org.junit.Test)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)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 SetConnectionSourceNodeCommand (org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionSourceNodeCommand)1 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)1 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)1 MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)1 Command (org.kie.workbench.common.stunner.core.command.Command)1 DeferredCommand (org.kie.workbench.common.stunner.core.command.impl.DeferredCommand)1 DeferredCompositeCommand (org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 Connection (org.kie.workbench.common.stunner.core.graph.content.view.Connection)1 MagnetConnection (org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection)1 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)1