Search in sources :

Example 1 with AddNodeCommand

use of org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand in project kie-wb-common by kiegroup.

the class AbstractEdgeBuilder method buildTargetNode.

private Node buildTargetNode(BuilderContext context, String outgoingNodeId, GraphCommandFactory commandFactory) {
    GraphObjectBuilder<?, ?> outgoingNodeBuilder = getBuilder(context, outgoingNodeId);
    if (outgoingNodeBuilder == null) {
        throw new RuntimeException("No edge for " + outgoingNodeId);
    }
    Node node = (Node) outgoingNodeBuilder.build(context);
    AddNodeCommand addNodeCommand = commandFactory.addNode(node);
    CommandResult<RuleViolation> addEdgeResult = context.execute(addNodeCommand);
    if (hasErrors(addEdgeResult)) {
        throw new RuntimeException("Error building BPMN graph. Command 'addNodeCommand' execution failed.");
    }
    return node;
}
Also used : AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 2 with AddNodeCommand

use of org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand 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 3 with AddNodeCommand

use of org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand in project kie-wb-common by kiegroup.

the class NodeProxyTest method testCreateTargetNodeInSomeParent.

@Test
@SuppressWarnings("all")
public void testCreateTargetNodeInSomeParent() {
    Node<View<?>, Edge> parentNode = new NodeImpl<>(PARENT_NODE_ID);
    parentNode.setContent(new ViewImpl<>(mock(Object.class), Bounds.create()));
    DirectGraphCommandExecutionContext context = new DirectGraphCommandExecutionContext(definitionManager, factoryManager, new MapIndexBuilder().build(graph));
    new AddNodeCommand(parentNode).execute(context);
    new SetChildrenCommand(parentNode, sourceNode).execute(context);
    CanvasCommand<AbstractCanvasHandler> addConnector = mock(CanvasCommand.class);
    CanvasCommand<AbstractCanvasHandler> addNode = mock(CanvasCommand.class);
    CanvasCommand<AbstractCanvasHandler> setTargetNode = mock(CanvasCommand.class);
    doReturn(addConnector).when(commandFactory).addConnector(eq(sourceNode), eq(edge), Mockito.<MagnetConnection>any(), eq(SHAPE_SET_ID));
    doReturn(addNode).when(commandFactory).addChildNode(eq(parentNode), eq(targetNode), eq(SHAPE_SET_ID));
    doReturn(setTargetNode).when(commandFactory).setTargetNode(eq(targetNode), eq(edge), any());
    verifyCreateTargetNode(addConnector, addNode, setTargetNode);
}
Also used : AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand) SetChildrenCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SetChildrenCommand) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) MapIndexBuilder(org.kie.workbench.common.stunner.core.graph.processing.index.map.MapIndexBuilder) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) DirectGraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.DirectGraphCommandExecutionContext) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 4 with AddNodeCommand

use of org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand in project kie-wb-common by kiegroup.

the class AbstractNodeBuilder method doBuild.

@Override
@SuppressWarnings("unchecked")
protected T doBuild(final BuilderContext context) {
    if (context.getIndex().getNode(this.nodeId) == null) {
        FactoryManager factoryManager = context.getFactoryManager();
        // Build the graph node for the definition.
        String definitionId = getDefinitionToBuild(context);
        T result = (T) factoryManager.newElement(this.nodeId, definitionId);
        // Set the def properties.
        setProperties(context, (BPMNDefinition) result.getContent().getDefinition());
        // View Bounds.
        setBounds(context, result);
        AddNodeCommand addNodeCommand = context.getCommandFactory().addNode(result);
        if (doExecuteCommand(context, addNodeCommand)) {
            // Post processing.
            afterNodeBuild(context, result);
        } else {
        // TODO: throw an exception and handle the error.
        }
        return result;
    } else {
        return (T) context.getIndex().getNode(this.nodeId);
    }
}
Also used : AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager)

Example 5 with AddNodeCommand

use of org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand in project kie-wb-common by kiegroup.

the class GraphBuilder method addNode.

private void addNode(Node node) {
    AddNodeCommand addNodeCommand = commandFactory.addNode(node);
    execute(addNodeCommand);
}
Also used : AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand)

Aggregations

AddNodeCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand)6 Test (org.junit.Test)2 Command (org.kie.workbench.common.stunner.core.command.Command)2 SetChildrenCommand (org.kie.workbench.common.stunner.core.graph.command.impl.SetChildrenCommand)2 List (java.util.List)1 FactoryManager (org.kie.workbench.common.stunner.core.api.FactoryManager)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 CanvasCommand (org.kie.workbench.common.stunner.core.client.command.CanvasCommand)1 NodeShape (org.kie.workbench.common.stunner.core.client.shape.NodeShape)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 DirectGraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.DirectGraphCommandExecutionContext)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)1 MapIndexBuilder (org.kie.workbench.common.stunner.core.graph.processing.index.map.MapIndexBuilder)1 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)1