Search in sources :

Example 6 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 setConnectionMagnets.

void setConnectionMagnets(final Edge edge, final ViewConnector connectionContent, final JSIDMNEdge jsidmnEdge) {
    final JSIDMNEdge e = Js.uncheckedCast(jsidmnEdge);
    final JSIPoint source = Js.uncheckedCast(e.getWaypoint().get(0));
    final Node<View<?>, Edge> sourceNode = edge.getSourceNode();
    if (null != sourceNode) {
        setConnectionMagnet(sourceNode, source, connectionContent::setSourceConnection, isSourceAutoConnectionEdge(jsidmnEdge));
    }
    final JSIPoint target = Js.uncheckedCast(e.getWaypoint().get(e.getWaypoint().size() - 1));
    final Node<View<?>, Edge> targetNode = edge.getTargetNode();
    if (null != targetNode) {
        setConnectionMagnet(targetNode, target, connectionContent::setTargetConnection, isTargetAutoConnectionEdge(jsidmnEdge));
    }
    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));
    }
}
Also used : JSIPoint(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)

Example 7 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 NodeEntriesFactory method getEdges.

private List<JSIDMNEdge> getEdges(final JSIDMNDiagram dmnDiagram) {
    final List<JSIDMNEdge> edges = new ArrayList<>();
    final List<JSIDiagramElement> dmnDiagramElements = dmnDiagram.getDMNDiagramElement();
    forEach(dmnDiagramElements, dmnDiagramElement -> {
        if (JSIDMNEdge.instanceOf(dmnDiagramElement)) {
            final JSIDMNEdge jsiEdge = Js.uncheckedCast(dmnDiagramElement);
            edges.add(jsiEdge);
        }
    });
    return edges;
}
Also used : JSIDiagramElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement) ArrayList(java.util.ArrayList) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)

Example 8 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 DMNMarshallerTest method testConnect.

@Test
public void testConnect() {
    final DMNMarshaller dmnMarshaller = new DMNMarshaller();
    final JSIDMNDiagram diagram = mock(JSIDMNDiagram.class);
    final List<String> dmnDiagramElementIds = mock(List.class);
    final Definitions definitionsStunnerPojo = mock(Definitions.class);
    final List<JSIDMNEdge> dmnEdges = new ArrayList<>();
    final Node<?, ?> node = mock(Node.class);
    final List inEdges = new ArrayList<>();
    final Edge edge = mock(Edge.class);
    final Node sourceNode = mock(Node.class);
    final View sourceView = mock(View.class);
    final ViewConnector viewConnector = mock(ViewConnector.class);
    final DiscreteConnection sourceConnection = mock(DiscreteConnection.class);
    final DiscreteConnection targetConnection = mock(DiscreteConnection.class);
    final View<?> view = mock(View.class);
    inEdges.add(edge);
    when(edge.getSourceNode()).thenReturn(sourceNode);
    when(sourceNode.getContent()).thenReturn(sourceView);
    when(node.getInEdges()).thenReturn(inEdges);
    when(edge.getContent()).thenReturn(viewConnector);
    when(viewConnector.getControlPoints()).thenReturn(new ControlPoint[] {});
    when(sourceConnection.isAuto()).thenReturn(true);
    when(targetConnection.isAuto()).thenReturn(true);
    when(diagram.getName()).thenReturn("dmnEdge");
    when(definitionsStunnerPojo.getDefaultNamespace()).thenReturn("org.edge");
    when(viewConnector.getSourceConnection()).thenReturn(Optional.of(sourceConnection));
    when(viewConnector.getTargetConnection()).thenReturn(Optional.of(targetConnection));
    dmnMarshaller.connect(diagram, dmnDiagramElementIds, definitionsStunnerPojo, dmnEdges, node, view);
    when(viewConnector.getSourceConnection()).thenReturn(Optional.empty());
    when(viewConnector.getTargetConnection()).thenReturn(Optional.empty());
    dmnMarshaller.connect(diagram, dmnDiagramElementIds, definitionsStunnerPojo, dmnEdges, node, view);
    when(viewConnector.getSourceConnection()).thenReturn(Optional.of(sourceConnection));
    when(viewConnector.getTargetConnection()).thenReturn(Optional.empty());
    dmnMarshaller.connect(diagram, dmnDiagramElementIds, definitionsStunnerPojo, dmnEdges, node, view);
    verify(sourceConnection).isAuto();
    verify(targetConnection).isAuto();
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) DiscreteConnection(org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) View(org.kie.workbench.common.stunner.core.graph.content.view.View) JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Edge(org.kie.workbench.common.stunner.core.graph.Edge) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Test(org.junit.Test)

Example 9 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 NodeConnectorTest method testConnectWbEdge.

@Test
public void testConnectWbEdge() {
    final JSIDMNEdge edge = mock(JSIDMNEdge.class);
    final Element element = mock(Element.class);
    final String id = "123";
    final Edge wbEdge = mock(Edge.class);
    final ViewConnector viewConnector = mock(ViewConnector.class);
    when(factoryManager.newElement("diagramId#123", connectorTypeId)).thenReturn(element);
    when(element.asEdge()).thenReturn(wbEdge);
    when(wbEdge.getContent()).thenReturn(viewConnector);
    doNothing().when(nodeConnector).connectEdge(any(), any(), any());
    doNothing().when(nodeConnector).setConnectionMagnets(any(), any(), any());
    nodeConnector.connectWbEdge(connectorTypeId, diagramId, currentNode, requiredNode, edge, id);
    verify(nodeConnector).connectEdge(wbEdge, requiredNode, currentNode);
    verify(nodeConnector).setConnectionMagnets(wbEdge, viewConnector, edge);
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) JSITDMNElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElement) Element(org.kie.workbench.common.stunner.core.graph.Element) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Edge(org.kie.workbench.common.stunner.core.graph.Edge) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Test(org.junit.Test)

Example 10 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 NodeConnectorTest method testGetTargetNode.

@Test
public void testGetTargetNode() {
    final JSIDMNEdge jsiDMNEdge = mock(JSIDMNEdge.class);
    final double targetX = 7.0;
    final double targetY = 8.0;
    final JSIPoint sourcePoint = createPoint(1, 2);
    final JSIPoint targetPoint = createPoint(targetX, targetY);
    final List<JSIPoint> waypoints = Arrays.asList(sourcePoint, targetPoint);
    final List nodeEntries = mock(List.class);
    final Point2D targetPoint2D = new Point2D(targetX, targetY);
    when(jsiDMNEdge.getWaypoint()).thenReturn(waypoints);
    doReturn(Optional.of(mock(Node.class))).when(nodeConnector).getNodeFromPoint(targetPoint2D, nodeEntries);
    nodeConnector.getTargetNode(jsiDMNEdge, nodeEntries);
    verify(nodeConnector).getNodeFromPoint(targetPoint2D, nodeEntries);
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) JSIPoint(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Test(org.junit.Test)

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