Search in sources :

Example 6 with Connection

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

the class EdgeParser method parseExtendedProperties.

@Override
protected void parseExtendedProperties(final ObjectParser propertiesParser) {
    super.parseExtendedProperties(propertiesParser);
    ViewConnector viewConnector = (ViewConnector) element.getContent();
    viewConnector.getTargetConnection().ifPresent(connection -> appendConnAuto((Connection) connection, Bpmn2OryxManager.TARGET, propertiesParser));
    viewConnector.getSourceConnection().ifPresent(connection -> appendConnAuto((Connection) connection, Bpmn2OryxManager.SOURCE, propertiesParser));
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) DiscreteConnection(org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)

Example 7 with Connection

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

the class BPMNDiagramMarshallerTest 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 8 with Connection

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

the class ConnectorShapeTest method testApplyConnections.

@Test
@SuppressWarnings("unchecked")
public void testApplyConnections() {
    final Object def = mock(Object.class);
    final Edge<ViewConnector<Object>, Node> edge = new EdgeImpl<>("uuid1");
    final ViewConnectorImpl<Object> content = new ViewConnectorImpl<>(def, new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(15d, 40d)));
    Connection sourceConnection = mock(Connection.class);
    Connection targetConnection = mock(Connection.class);
    content.setSourceConnection(sourceConnection);
    content.setTargetConnection(targetConnection);
    edge.setContent(content);
    final ShapeView<?> source = mock(ShapeView.class);
    final ShapeView<?> target = mock(ShapeView.class);
    tested.applyConnections(edge, source, target, MutationContext.STATIC);
    verify(((IsConnector) shapeView), times(1)).connect(eq(source), eq(sourceConnection), eq(target), eq(targetConnection));
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) ViewConnectorImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnectorImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Test(org.junit.Test)

Example 9 with Connection

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

the class NodeBuilderControlImpl method build.

@Override
@SuppressWarnings("unchecked")
public void build(final NodeBuildRequest request, final BuildCallback buildCallback) {
    final double x = request.getX();
    final double y = request.getY();
    final Node<? extends View<?>, Edge> node = request.getNode();
    final Edge<? extends ViewConnector<?>, Node> inEdge = request.getInEdge();
    final Connection sourceConnection = request.getSourceConnection();
    final Connection targetConnection = request.getTargetConnection();
    if (null != node) {
        final Object nodeDef = node.getContent().getDefinition();
        final String nodeId = clientDefinitionManager.adapters().forDefinition().getId(nodeDef);
        final ElementBuilderControlImpl ebc = getElementBuilderControl();
        final Node<View<?>, Edge> parent = ebc.getParent(x, y);
        final Point2D childCoordinates = ebc.getChildCoordinates(parent, x, y);
        final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
        ebc.getElementCommands(node, parent, childCoordinates.getX(), childCoordinates.getY(), new AbstractElementBuilderControl.CommandsCallback() {

            @Override
            public void onComplete(final String uuid, final List<Command<AbstractCanvasHandler, CanvasViolation>> commands) {
                final CompositeCommand.Builder commandBuilder = new CompositeCommand.Builder().addCommands(commands);
                if (inEdge != null) {
                    final Object edgeDef = inEdge.getContent().getDefinition();
                    final String edgeId = clientDefinitionManager.adapters().forDefinition().getId(edgeDef);
                    // The commands to batch for the edge that connects both nodes.
                    commandBuilder.addCommand(commandFactory.addConnector(inEdge.getSourceNode(), inEdge, sourceConnection, ssid));
                    commandBuilder.addCommand(commandFactory.setTargetNode(node, inEdge, targetConnection));
                }
                final CommandResult<CanvasViolation> results = elementBuilderControl.getCommandManager().execute(canvasHandler, commandBuilder.build());
                if (!CommandUtils.isError(results)) {
                    updateConnectorShape(inEdge, node, sourceConnection, targetConnection);
                }
                buildCallback.onSuccess(uuid);
            }

            @Override
            public void onError(final ClientRuntimeError error) {
                buildCallback.onError(error);
            }
        });
    }
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) View(org.kie.workbench.common.stunner.core.graph.content.view.View) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Command(org.kie.workbench.common.stunner.core.command.Command) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 10 with Connection

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

the class SetConnectionSourceNodeCommandTest method testExecuteOnlyConnectionsHasBeenChanged.

@Test
@SuppressWarnings("unchecked")
public void testExecuteOnlyConnectionsHasBeenChanged() {
    when(edge.getSourceNode()).thenReturn(node);
    MagnetConnection connection = MagnetConnection.Builder.at(MAGNETX, MAGNETY);
    tested = new SetConnectionSourceNodeCommand(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)).setSourceConnection(eq(connection));
    verify(edgeContent, never()).setTargetConnection(any(Connection.class));
    assertEquals(sourceMagnet.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)

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