Search in sources :

Example 21 with DMNDiagram

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);
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Test(org.junit.Test)

Example 22 with DMNDiagram

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);
    });
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 23 with DMNDiagram

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);
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child)

Example 24 with DMNDiagram

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

Example 25 with DMNDiagram

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);
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child)

Aggregations

DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)33 Node (org.kie.workbench.common.stunner.core.graph.Node)25 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)19 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)17 Test (org.junit.Test)16 View (org.kie.workbench.common.stunner.core.graph.content.view.View)16 Edge (org.kie.workbench.common.stunner.core.graph.Edge)13 Graph (org.kie.workbench.common.stunner.core.graph.Graph)12 DMNModelInstrumentedBase (org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase)10 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)10 ArrayList (java.util.ArrayList)9 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)8 HashMap (java.util.HashMap)7 Optional (java.util.Optional)7 DMNDefinitionSet (org.kie.workbench.common.dmn.api.DMNDefinitionSet)7 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)7 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)7 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)7 EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)7