Search in sources :

Example 11 with DMNEdge

use of org.kie.dmn.model.api.dmndi.DMNEdge in project kie-wb-common by kiegroup.

the class DMNMarshallerStandalone method setConnectionMagnets.

@SuppressWarnings("unchecked")
private void setConnectionMagnets(final Edge edge, final String dmnEdgeElementRef, final org.kie.dmn.model.api.Definitions dmnXml) {
    final ViewConnector connectionContent = (ViewConnector) edge.getContent();
    final Optional<org.kie.dmn.model.api.dmndi.DMNDiagram> dmnDiagram = findDMNDiagram(dmnXml);
    Optional<DMNEdge> dmnEdge = Optional.empty();
    if (dmnDiagram.isPresent()) {
        dmnEdge = dmnDiagram.get().getDMNDiagramElement().stream().filter(DMNEdge.class::isInstance).map(DMNEdge.class::cast).filter(e -> e.getDmnElementRef().getLocalPart().equals(dmnEdgeElementRef)).findFirst();
    }
    if (dmnEdge.isPresent()) {
        DMNEdge e = dmnEdge.get();
        final Point source = e.getWaypoint().get(0);
        final Node<View<?>, Edge> sourceNode = edge.getSourceNode();
        if (null != sourceNode) {
            setConnectionMagnet(sourceNode, source, connectionContent::setSourceConnection, isSourceAutoConnectionEdge(e));
        }
        final Point target = e.getWaypoint().get(e.getWaypoint().size() - 1);
        final Node<View<?>, Edge> targetNode = edge.getTargetNode();
        if (null != targetNode) {
            setConnectionMagnet(targetNode, target, connectionContent::setTargetConnection, isTargetAutoConnectionEdge(e));
        }
        if (e.getWaypoint().size() > 2) {
            connectionContent.setControlPoints(e.getWaypoint().subList(1, e.getWaypoint().size() - 1).stream().map(p -> ControlPoint.build(PointUtils.dmndiPointToPoint2D(p))).toArray(ControlPoint[]::new));
        }
    } else {
        // Set the source connection, if any.
        final Node sourceNode = edge.getSourceNode();
        if (null != sourceNode) {
            connectionContent.setSourceConnection(MagnetConnection.Builder.atCenter(sourceNode));
        }
        // Set the target connection, if any.
        final Node targetNode = edge.getTargetNode();
        if (null != targetNode) {
            connectionContent.setTargetConnection(MagnetConnection.Builder.atCenter(targetNode));
        }
    }
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) Point(org.kie.dmn.model.api.dmndi.Point) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) View(org.kie.workbench.common.stunner.core.graph.content.view.View) DMNEdge(org.kie.dmn.model.api.dmndi.DMNEdge) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DMNEdge(org.kie.dmn.model.api.dmndi.DMNEdge)

Aggregations

DMNEdge (org.kie.dmn.model.api.dmndi.DMNEdge)11 Point (org.kie.dmn.model.api.dmndi.Point)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 ArrayList (java.util.ArrayList)3 Collections.emptyList (java.util.Collections.emptyList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 BiConsumer (java.util.function.BiConsumer)3 Consumer (java.util.function.Consumer)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 StreamSupport (java.util.stream.StreamSupport)3 QName (javax.xml.namespace.QName)3 Test (org.junit.Test)3 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)3 Edge (org.kie.workbench.common.stunner.core.graph.Edge)3