Search in sources :

Example 1 with Connection

use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.

the class ConnectorShape method applyConnections.

@Override
public void applyConnections(final Edge<ViewConnector<W>, Node> element, final ShapeView<?> source, final ShapeView<?> target, final MutationContext mutationContext) {
    final ViewConnector connectionContent = element.getContent();
    final Connection sourceConnection = (Connection) connectionContent.getSourceConnection().orElse(null);
    final Connection targetConnection = (Connection) connectionContent.getTargetConnection().orElse(null);
    if (null != source && null != target) {
        IsConnector shapeView = (IsConnector) getShapeView();
        shapeView.connect(source, sourceConnection, target, targetConnection);
    }
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) IsConnector(org.kie.workbench.common.stunner.core.client.shape.view.IsConnector) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection)

Example 2 with Connection

use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.

the class SetConnectionTargetNodeCommandTest method testExecuteOnlyConnectionsHasBeenChanged.

@Test
@SuppressWarnings("unchecked")
public void testExecuteOnlyConnectionsHasBeenChanged() {
    when(edge.getTargetNode()).thenReturn(node);
    MagnetConnection connection = MagnetConnection.Builder.at(MAGNETX, MAGNETY);
    tested = new SetConnectionTargetNodeCommand(node, edge, connection);
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    assertEquals(CommandResult.Type.INFO, result.getType());
    verify(ruleManager, never()).evaluate(eq(ruleSet), any(RuleEvaluationContext.class));
    verify(edgeContent, times(1)).setTargetConnection(eq(connection));
    verify(edgeContent, never()).setSourceConnection(any(Connection.class));
    assertEquals(targetMagnet.get(), tested.lastConnection);
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) TestingGraphUtils.verifyConnection(org.kie.workbench.common.stunner.core.TestingGraphUtils.verifyConnection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 3 with Connection

use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshallerTest method testMagnetsInLane.

private void testMagnetsInLane(Diagram<Graph, Metadata> diagram) throws Exception {
    Node userTaskNode = (Node) findElementByContentType(diagram, UserTask.class);
    Node scriptTaskNode = (Node) findElementByContentType(diagram, ScriptTask.class);
    assertNotNull(userTaskNode);
    assertNotNull(scriptTaskNode);
    ViewConnector userTaskInEdgeConnector = getInEdgeViewConnector(userTaskNode);
    ViewConnector scriptTaskInEdgeConnector = getInEdgeViewConnector(scriptTaskNode);
    assertNotNull(userTaskInEdgeConnector);
    assertNotNull(scriptTaskInEdgeConnector);
    ViewConnector userTaskOutEdgeConnector = getOutEdgeViewConnector(userTaskNode);
    ViewConnector scriptTaskOutEdgeConnector = getOutEdgeViewConnector(scriptTaskNode);
    assertNotNull(userTaskOutEdgeConnector);
    assertNotNull(scriptTaskOutEdgeConnector);
    // userTaskInEdgeConnector is from magnet right-middle to middle-top
    assertTrue(userTaskInEdgeConnector.getSourceConnection().isPresent());
    assertTrue(userTaskInEdgeConnector.getTargetConnection().isPresent());
    Connection sourceConnection = (Connection) userTaskInEdgeConnector.getSourceConnection().get();
    Connection targetConnection = (Connection) userTaskInEdgeConnector.getTargetConnection().get();
    assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(24d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(68d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
    // scriptTaskInEdgeConnector is from magnet right-bottom to left-top
    assertTrue(scriptTaskInEdgeConnector.getSourceConnection().isPresent());
    assertTrue(scriptTaskInEdgeConnector.getTargetConnection().isPresent());
    sourceConnection = (Connection) scriptTaskInEdgeConnector.getSourceConnection().get();
    targetConnection = (Connection) scriptTaskInEdgeConnector.getTargetConnection().get();
    assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(48d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
    // userTaskOutEdgeConnector is from magnet right-bottom to left-top
    assertTrue(userTaskOutEdgeConnector.getSourceConnection().isPresent());
    assertTrue(userTaskOutEdgeConnector.getTargetConnection().isPresent());
    sourceConnection = (Connection) userTaskOutEdgeConnector.getSourceConnection().get();
    targetConnection = (Connection) userTaskOutEdgeConnector.getTargetConnection().get();
    assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(48d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getY(), 0.1d);
    // scriptTaskOutEdgeConnector is from magnet right-top to left-middle
    assertTrue(scriptTaskOutEdgeConnector.getSourceConnection().isPresent());
    assertTrue(scriptTaskOutEdgeConnector.getTargetConnection().isPresent());
    sourceConnection = (Connection) scriptTaskOutEdgeConnector.getSourceConnection().get();
    targetConnection = (Connection) scriptTaskOutEdgeConnector.getTargetConnection().get();
    assertEquals(136d, sourceConnection.getLocation().getX(), 0.1d);
    assertEquals(0d, sourceConnection.getLocation().getY(), 0.1d);
    assertEquals(0d, targetConnection.getLocation().getX(), 0.1d);
    assertEquals(14d, targetConnection.getLocation().getY(), 0.1d);
}
Also used : ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) DiscreteConnection(org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)

Example 4 with Connection

use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.

the class AbstractEdgeBuilder method buildTargetConnection.

private void buildTargetConnection(BuilderContext context, T edge, Node node, GraphCommandFactory commandFactory) {
    Double[] targetDocker = null;
    if (dockers != null && dockers.size() > 1) {
        targetDocker = dockers.get(dockers.size() - 1);
    }
    Connection targetConnection = null;
    if (null != targetDocker) {
        targetConnection = MagnetConnection.Builder.at(targetDocker[0], targetDocker[1]).setAuto(isTargetAutoConnection());
    }
    SetConnectionTargetNodeCommand setTargetNodeCommand = commandFactory.setTargetNode(node, edge, targetConnection);
    CommandResult<RuleViolation> setTargetResult = context.execute(setTargetNodeCommand);
    if (hasErrors(setTargetResult)) {
        throw new RuntimeException("Error building BPMN graph. Command 'SetConnectionTargetNodeCommand' execution failed.");
    }
}
Also used : SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.SetConnectionTargetNodeCommand) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 5 with Connection

use of org.kie.workbench.common.stunner.core.graph.content.view.Connection in project kie-wb-common by kiegroup.

the class AbstractNodeBuilder method afterNodeBuild.

@SuppressWarnings("unchecked")
protected void afterNodeBuild(final BuilderContext context, final T node) {
    // Outgoing connections.
    if (outgoingResourceIds != null && !outgoingResourceIds.isEmpty()) {
        for (String outgoingNodeId : outgoingResourceIds) {
            GraphObjectBuilder<?, ?> outgoingBuilder = getBuilder(context, outgoingNodeId);
            if (outgoingBuilder == null) {
                throw new RuntimeException("No outgoing edge builder for " + outgoingNodeId);
            }
            final List<Command<GraphCommandExecutionContext, RuleViolation>> commands = new LinkedList<>();
            // If outgoing element it's a node means that it's docked.
            if (outgoingBuilder instanceof AbstractNodeBuilder) {
                // Command - Create the docked node.
                Node docked = (Node) outgoingBuilder.build(context);
                commands.add(context.getCommandFactory().addDockedNode(node, docked));
                // Obtain docked position and use those for the docked node.
                final List<Double[]> dockers = ((AbstractNodeBuilder) outgoingBuilder).dockers;
                if (!dockers.isEmpty()) {
                    // TODO: Use not only first docker coordinates?
                    Double[] dCoords = dockers.get(0);
                    double x = dCoords[0];
                    double y = dCoords[1];
                    commands.add(context.getCommandFactory().updatePosition(docked, new Point2D(x, y)));
                }
            } else {
                // Create the outgoing edge.
                AbstractEdgeBuilder edgeBuilder = (AbstractEdgeBuilder) outgoingBuilder;
                Edge edge = (Edge) edgeBuilder.build(context);
                if (edge != null) {
                    // Command - Execute the graph command to set the node as the edge connection's source..
                    Double[] sourceDocker = null;
                    final List<Double[]> dockers = ((AbstractEdgeBuilder) outgoingBuilder).dockers;
                    if (dockers != null && dockers.size() > 1) {
                        sourceDocker = dockers.get(0);
                    }
                    Connection sourceConnection = null;
                    if (null != sourceDocker) {
                        sourceConnection = MagnetConnection.Builder.at(sourceDocker[0], sourceDocker[1]).setAuto(edgeBuilder.isSourceAutoConnection());
                    }
                    commands.add(context.getCommandFactory().setSourceNode(node, edge, sourceConnection));
                }
            }
            if (!commands.isEmpty()) {
                for (Command<GraphCommandExecutionContext, RuleViolation> command : commands) {
                    doExecuteCommand(context, command);
                }
            }
        }
    }
    // Children connections.
    if (childNodeIds != null && !childNodeIds.isEmpty()) {
        for (String childNodeId : childNodeIds) {
            GraphObjectBuilder<?, ?> childNodeBuilder = getBuilder(context, childNodeId);
            if (childNodeBuilder == null) {
                throw new RuntimeException("No child node builder for " + childNodeId);
            }
            Command<GraphCommandExecutionContext, RuleViolation> command = null;
            if (childNodeBuilder instanceof NodeObjectBuilder) {
                // Command - Create the child node and the parent-child relationship.
                Node childNode = (Node) childNodeBuilder.build(context);
                command = context.getCommandFactory().addChildNode(node, childNode);
            }
            if (null != command) {
                doExecuteCommand(context, command);
            }
        }
    }
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) LinkedList(java.util.LinkedList) Command(org.kie.workbench.common.stunner.core.command.Command) AddNodeCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AddNodeCommand) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Aggregations

Connection (org.kie.workbench.common.stunner.core.graph.content.view.Connection)11 Node (org.kie.workbench.common.stunner.core.graph.Node)6 MagnetConnection (org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection)5 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)5 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)4 Test (org.junit.Test)3 Edge (org.kie.workbench.common.stunner.core.graph.Edge)3 DiscreteConnection (org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)3 ScriptTask (org.kie.workbench.common.stunner.bpmn.definition.ScriptTask)2 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)2 TestingGraphUtils.verifyConnection (org.kie.workbench.common.stunner.core.TestingGraphUtils.verifyConnection)2 Command (org.kie.workbench.common.stunner.core.command.Command)2 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)2 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)2 WiresConnection (com.ait.lienzo.client.core.shape.wires.WiresConnection)1 LinkedList (java.util.LinkedList)1 Before (org.junit.Before)1 SetConnectionSourceNodeCommand (org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionSourceNodeCommand)1 SetConnectionTargetNodeCommand (org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionTargetNodeCommand)1 ClientRuntimeError (org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError)1