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));
}
}
}
Aggregations