Search in sources :

Example 1 with ViewConnector

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

the class SingleConnectorPerTypeGraphRuleTest method checkHasExistingConnection.

@Test
@SuppressWarnings("unchecked")
public void checkHasExistingConnection() {
    final Node node1 = new NodeImpl<>("node1");
    final Node node2 = new NodeImpl<>("node2");
    final Edge existingConnector = new EdgeImpl<>("edge1");
    final ViewConnector existingConnectorView = mock(ViewConnector.class);
    existingConnector.setContent(existingConnectorView);
    when(existingConnectorView.getDefinition()).thenReturn(new Definition());
    node1.getOutEdges().add(existingConnector);
    node2.getInEdges().add(existingConnector);
    existingConnector.setSourceNode(node1);
    existingConnector.setTargetNode(node2);
    graph.addNode(node1);
    graph.addNode(node2);
    when(context.getSource()).thenReturn(Optional.of(node1));
    when(context.getTarget()).thenReturn(Optional.of(node2));
    when(context.getConnector()).thenReturn(connector);
    final RuleViolations result = check.evaluate(rule, context);
    assertNotNull(result);
    assertTrue(result.violations().iterator().hasNext());
    final RuleViolation violation = result.violations().iterator().next();
    assertNotNull(violation);
    assertTrue(violation.getArguments().isPresent());
    assertEquals(1, violation.getArguments().get().length);
    assertEquals(SingleConnectorPerTypeGraphRule.ERROR_MESSAGE, violation.getArguments().get()[0]);
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 2 with ViewConnector

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

the class DMNMarshaller method setConnectionMagnets.

@SuppressWarnings("unchecked")
private void setConnectionMagnets(final Edge edge) {
    final ViewConnector connectionContent = (ViewConnector) edge.getContent();
    // Set the source connection, if any.
    final Node sourceNode = edge.getSourceNode();
    if (null != sourceNode) {
        connectionContent.setSourceConnection(MagnetConnection.Builder.forElement(sourceNode));
    }
    // Set the target connection, if any.
    final Node targetNode = edge.getTargetNode();
    if (null != targetNode) {
        connectionContent.setTargetConnection(MagnetConnection.Builder.forElement(targetNode));
    }
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node)

Example 3 with ViewConnector

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

the class SequenceFlowConverter method toFlowElement.

public SequenceFlowPropertyWriter toFlowElement(Edge<?, ?> edge, ElementContainer process) {
    ViewConnector<SequenceFlow> content = (ViewConnector<SequenceFlow>) edge.getContent();
    SequenceFlow definition = content.getDefinition();
    org.eclipse.bpmn2.SequenceFlow seq = bpmn2.createSequenceFlow();
    SequenceFlowPropertyWriter p = propertyWriterFactory.of(seq);
    seq.setId(edge.getUUID());
    BasePropertyWriter pSrc = process.getChildElement(edge.getSourceNode().getUUID());
    BasePropertyWriter pTgt = process.getChildElement(edge.getTargetNode().getUUID());
    p.setSource(pSrc);
    p.setTarget(pTgt);
    seq.setId(edge.getUUID());
    seq.setName(definition.getGeneral().getName().getValue());
    p.setConnection(content);
    SequenceFlowExecutionSet executionSet = definition.getExecutionSet();
    ScriptTypeValue scriptTypeValue = executionSet.getConditionExpression().getValue();
    String language = scriptTypeValue.getLanguage();
    String script = scriptTypeValue.getScript();
    if (script != null) {
        FormalExpression formalExpression = bpmn2.createFormalExpression();
        String uri = Scripts.scriptLanguageToUri(language);
        formalExpression.setLanguage(uri);
        formalExpression.setBody(asCData(script));
        seq.setConditionExpression(formalExpression);
    }
    process.addChildElement(p);
    process.addChildEdge(p.getEdge());
    return p;
}
Also used : BasePropertyWriter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.BasePropertyWriter) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) SequenceFlow(org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow) Factories.bpmn2(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpmn2) SequenceFlowPropertyWriter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.SequenceFlowPropertyWriter) SequenceFlowExecutionSet(org.kie.workbench.common.stunner.bpmn.definition.property.connectors.SequenceFlowExecutionSet) FormalExpression(org.eclipse.bpmn2.FormalExpression) ScriptTypeValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue)

Example 4 with ViewConnector

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

the class NodeDragProxyImpl method show.

@Override
@SuppressWarnings("unchecked")
public DragProxy<AbstractCanvasHandler, Item, NodeDragProxyCallback> show(final Item item, final int x, final int y, final NodeDragProxyCallback callback) {
    final AbstractCanvas canvas = canvasHandler.getAbstractCanvas();
    final Node<View<?>, Edge> node = item.getNode();
    final ShapeFactory<Object, ?> nodeShapeFactory = item.getNodeShapeFactory();
    final Edge<View<?>, Node> inEdge = item.getInEdge();
    final Node<View<?>, Edge> inEdgeSourceNode = item.getInEdgeSourceNode();
    final ShapeFactory<Object, ?> edgeShapeFactory = item.getInEdgeShapeFactory();
    final Shape nodeShape = nodeShapeFactory.newShape(node.getContent().getDefinition());
    if (nodeShape instanceof ElementShape) {
        ((ElementShape) nodeShape).applyProperties(node, MutationContext.STATIC);
    }
    this.transientEdgeShape = (EdgeShape) edgeShapeFactory.newShape(inEdge.getContent().getDefinition());
    canvas.addTransientShape(this.transientEdgeShape);
    this.transientEdgeShape.applyProperties(inEdge, MutationContext.STATIC);
    final Shape<?> edgeSourceNodeShape = canvasHandler.getCanvas().getShape(inEdgeSourceNode.getUUID());
    shapeDragProxyFactory.show(nodeShape, x, y, new DragProxyCallback() {

        @Override
        public void onStart(final int x, final int y) {
            callback.onStart(x, y);
            drawEdge();
        }

        @Override
        public void onMove(final int x, final int y) {
            callback.onMove(x, y);
            drawEdge();
        }

        @Override
        public void onComplete(final int x, final int y) {
            final MagnetConnection[] connections = createShapeConnections();
            callback.onComplete(x, y);
            callback.onComplete(x, y, connections[0], connections[1]);
            deleteTransientEdgeShape();
            canvas.draw();
        }

        private void drawEdge() {
            if (inEdge.getContent() instanceof ViewConnector) {
                final ViewConnector viewConnector = (ViewConnector) inEdge.getContent();
                final MagnetConnection[] connections = createShapeConnections();
                viewConnector.setSourceConnection(connections[0]);
                viewConnector.setTargetConnection(connections[1]);
            }
            NodeDragProxyImpl.this.transientEdgeShape.applyConnections(inEdge, edgeSourceNodeShape.getShapeView(), nodeShape.getShapeView(), MutationContext.STATIC);
            canvas.draw();
        }

        private MagnetConnection[] createShapeConnections() {
            return new MagnetConnection[] { MagnetConnection.Builder.forElement(inEdgeSourceNode), MagnetConnection.Builder.forElement(node) };
        }
    });
    return this;
}
Also used : ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) EdgeShape(org.kie.workbench.common.stunner.core.client.shape.EdgeShape) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 5 with ViewConnector

use of org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector 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)

Aggregations

ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)30 Node (org.kie.workbench.common.stunner.core.graph.Node)20 Edge (org.kie.workbench.common.stunner.core.graph.Edge)17 Graph (org.kie.workbench.common.stunner.core.graph.Graph)10 Test (org.junit.Test)8 View (org.kie.workbench.common.stunner.core.graph.content.view.View)8 List (java.util.List)7 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)6 ArrayList (java.util.ArrayList)5 SequenceFlow (org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow)5 Connection (org.kie.workbench.common.stunner.core.graph.content.view.Connection)5 DiscreteConnection (org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)5 ScriptTask (org.kie.workbench.common.stunner.bpmn.definition.ScriptTask)4 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)4 Element (org.kie.workbench.common.stunner.core.graph.Element)3 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)3 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)3 LinkedList (java.util.LinkedList)2 InclusiveGateway (org.kie.workbench.common.stunner.bpmn.definition.InclusiveGateway)2 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)2