Search in sources :

Example 1 with NodeShape

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

the class NodeProxyTest method verifyCreateTargetNode.

@SuppressWarnings("all")
private void verifyCreateTargetNode(CanvasCommand<AbstractCanvasHandler> addConnectorCommand, CanvasCommand<AbstractCanvasHandler> addNodeCommand, CanvasCommand<AbstractCanvasHandler> setTargetNodeCommand) {
    tested.init();
    tested.start(1d, 2d);
    verify(proxy, times(1)).start(eq(1d), eq(2d));
    NodeShape targetNodeShape = view.getShapeBuilder().get();
    assertEquals(targetShape, targetNodeShape);
    ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
    verify(proxy, times(1)).execute(commandCaptor.capture());
    DeferredCompositeCommand command = (DeferredCompositeCommand) commandCaptor.getValue();
    List commands = command.getCommands();
    assertEquals(3, command.size());
    DeferredCommand c0 = (DeferredCommand) commands.get(0);
    assertEquals(addNodeCommand, c0.getCommand());
    DeferredCommand c1 = (DeferredCommand) commands.get(1);
    assertEquals(addConnectorCommand, c1.getCommand());
    DeferredCommand c2 = (DeferredCommand) commands.get(2);
    assertEquals(setTargetNodeCommand, c2.getCommand());
}
Also used : DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) DeferredCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCommand) Command(org.kie.workbench.common.stunner.core.command.Command) AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand) SetChildrenCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SetChildrenCommand) NodeShape(org.kie.workbench.common.stunner.core.client.shape.NodeShape) List(java.util.List) DeferredCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCommand)

Example 2 with NodeShape

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

the class NodeProxy method onCreateProxy.

private NodeShape onCreateProxy() {
    final CanvasCommandFactory<AbstractCanvasHandler> commandFactory = proxy.lookupCanvasFactory();
    final Node<View<?>, Edge> parent = getParent();
    proxy.execute(new DeferredCompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().deferCommand(() -> null != parent ? commandFactory.addChildNode(parent, targetNode, getShapeSetId()) : commandFactory.addNode(targetNode, getShapeSetId())).deferCommand(() -> commandFactory.addConnector(sourceNode, edge, MagnetConnection.Builder.atCenter(sourceNode), getShapeSetId())).deferCommand(() -> commandFactory.setTargetNode(targetNode, edge, MagnetConnection.Builder.forTarget(sourceNode, targetNode))).build());
    final Canvas canvas = proxy.getCanvas();
    final NodeShape targetShape = getTargetShape();
    final Shape<?> edgeShape = canvas.getShape(edge.getUUID());
    edgeShape.applyState(ShapeState.SELECTED);
    return targetShape;
}
Also used : DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Canvas(org.kie.workbench.common.stunner.core.client.canvas.Canvas) NodeShape(org.kie.workbench.common.stunner.core.client.shape.NodeShape) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Aggregations

NodeShape (org.kie.workbench.common.stunner.core.client.shape.NodeShape)2 DeferredCompositeCommand (org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand)2 List (java.util.List)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 Canvas (org.kie.workbench.common.stunner.core.client.canvas.Canvas)1 CanvasCommand (org.kie.workbench.common.stunner.core.client.command.CanvasCommand)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 Command (org.kie.workbench.common.stunner.core.command.Command)1 DeferredCommand (org.kie.workbench.common.stunner.core.command.impl.DeferredCommand)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 AddNodeCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand)1 SetChildrenCommand (org.kie.workbench.common.stunner.core.graph.command.impl.SetChildrenCommand)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1