use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.
the class DMNDiagramUtilsTest method testGetDefinitionsWithMultipleRootNodes.
@Test
public void testGetDefinitionsWithMultipleRootNodes() {
final Decision definition1 = new Decision();
final DMNDiagram definition2 = new DMNDiagram();
graph.addNode(newNode(definition1));
graph.addNode(newNode(definition2));
final Definitions definitions = utils.getDefinitions(diagram);
assertNotNull(definitions);
assertEquals(definition2.getDefinitions(), definitions);
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.
the class DecisionNavigatorItemFactory method removeFromModel.
private void removeFromModel(final DMNDiagramElement dmnDiagramElement) {
final Graph graph = dmnDiagramsSession.getDRGDiagram().getGraph();
final Node<View<DMNDiagram>, ?> dmnDiagramRoot = (Node<View<DMNDiagram>, ?>) DMNGraphUtils.findDMNDiagramRoot(graph);
final Definitions definitions = ((DMNDiagram) DefinitionUtils.getElementDefinition(dmnDiagramRoot)).getDefinitions();
definitions.getDiagramElements().removeIf(e -> {
final String diagramId = e.getId().getValue();
final String removedDiagramId = dmnDiagramElement.getId().getValue();
return Objects.equals(diagramId, removedDiagramId);
});
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.
the class DRDContextMenuService method connectRootWithChild.
private void connectRootWithChild(final Node dmnDiagramRoot, final Node child) {
final String uuid = UUID.uuid();
final Edge<Child, Node> edge = new EdgeImpl<>(uuid);
edge.setContent(new Child());
connectEdge(edge, dmnDiagramRoot, child);
final Definitions definitions = ((DMNDiagram) ((View) dmnDiagramRoot.getContent()).getDefinition()).getDefinitions();
final DMNModelInstrumentedBase childDRG = (DMNModelInstrumentedBase) ((View) child.getContent()).getDefinition();
childDRG.setParent(definitions);
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram 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));
}
}
}
use of org.kie.workbench.common.dmn.api.definition.model.DMNDiagram in project kie-wb-common by kiegroup.
the class DMNMarshallerStandalone method connectRootWithChild.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void connectRootWithChild(final Node dmnDiagramRoot, final Node child) {
final String uuid = org.kie.workbench.common.stunner.core.util.UUID.uuid();
final Edge<Child, Node> edge = new EdgeImpl<>(uuid);
edge.setContent(new Child());
connectEdge(edge, dmnDiagramRoot, child);
final Definitions definitions = ((DMNDiagram) ((View) dmnDiagramRoot.getContent()).getDefinition()).getDefinitions();
final DMNModelInstrumentedBase childDRG = (DMNModelInstrumentedBase) ((View) child.getContent()).getDefinition();
childDRG.setParent(definitions);
}
Aggregations