Search in sources :

Example 26 with JSIDMNEdge

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge in project kie-wb-common by kiegroup.

the class NodeConnector method connectEdgeToNodes.

void connectEdgeToNodes(final String connectorTypeId, final JSITDMNElement jsiDMNElement, final JSITDMNElementReference jsiDMNElementReference, final Map<String, List<NodeEntry>> entriesById, final String diagramId, final List<JSIDMNEdge> edges, final boolean isDMNDIPresent, final Node currentNode) {
    final String reqInputID = getId(jsiDMNElementReference);
    final List<NodeEntry> nodeEntries = entriesById.get(reqInputID);
    if (nodeEntries == null || nodeEntries.isEmpty()) {
        return;
    }
    final Optional<JSIDMNEdge> existingEdge = findExistingEdge(jsiDMNElement, edges);
    if (!isDMNDIPresent) {
        // Generate new a edge and connect it
        final NodeEntry nodeEntry = nodeEntries.get(0);
        final Node requiredNode = nodeEntry.getNode();
        final View<?> view = (View<?>) requiredNode.getContent();
        final double viewWidth = view.getBounds().getWidth();
        final double viewHeight = view.getBounds().getHeight();
        connectWbEdge(connectorTypeId, diagramId, currentNode, requiredNode, newEdge(viewWidth / 2, viewHeight / 2), uuid());
    } else if (existingEdge.isPresent()) {
        // Connect existing edge
        final JSIDMNEdge edge = Js.uncheckedCast(existingEdge.get());
        final Optional<Node> requiredNode = getSourceNode(edge, nodeEntries);
        final String id = edge.getDmnElementRef().getLocalPart();
        final String currentNodeId = ((DRGElement) ((Definition) currentNode.getContent()).getDefinition()).getContentDefinitionId();
        // The edge can be connected with another instance of the same Node and not the currentNode
        if (isEdgeConnectedWithNode(edge, currentNode, entriesById.get(currentNodeId))) {
            connectWbEdge(connectorTypeId, diagramId, currentNode, requiredNode.get(), edge, id);
        }
    }
}
Also used : Optional(java.util.Optional) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Aggregations

JSIDMNEdge (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)26 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)13 List (java.util.List)11 Node (org.kie.workbench.common.stunner.core.graph.Node)10 Collections.singletonList (java.util.Collections.singletonList)8 Edge (org.kie.workbench.common.stunner.core.graph.Edge)8 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)7 JSIPoint (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint)6 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 QName (javax.xml.namespace.QName)4 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)4 ControlPoint (org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)4 JSIBounds (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds)3 JSIDiagramElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement)3 JSITDMNElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElement)3 JSIDMNDiagram (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram)3 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)3 DiscreteConnection (org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)3 Point2D (com.ait.lienzo.client.core.types.Point2D)2