Search in sources :

Example 1 with Edge

use of org.eclipse.sirius.components.diagrams.Edge in project sirius-components by eclipse-sirius.

the class GetToolSectionsEventHandler method findDiagramElement.

private Optional<Object> findDiagramElement(Diagram diagram, String diagramElementId) {
    Object diagramElement = null;
    if (diagram.getId().equals(diagramElementId)) {
        diagramElement = diagram;
    } else {
        var findNodeById = this.diagramQueryService.findNodeById(diagram, diagramElementId);
        if (findNodeById.isPresent()) {
            Node node = findNodeById.get();
            diagramElement = node;
        } else {
            var findEdgeById = this.diagramQueryService.findEdgeById(diagram, diagramElementId);
            if (findEdgeById.isPresent()) {
                Edge edge = findEdgeById.get();
                diagramElement = edge;
            }
        }
    }
    return Optional.ofNullable(diagramElement);
}
Also used : Node(org.eclipse.sirius.components.diagrams.Node) Edge(org.eclipse.sirius.components.diagrams.Edge)

Example 2 with Edge

use of org.eclipse.sirius.components.diagrams.Edge in project sirius-components by eclipse-sirius.

the class GetToolSectionsEventHandler method findTargetElement.

private Optional<Object> findTargetElement(Diagram diagram, String diagramElementId, IEditingContext editingContext) {
    String targetObjectId = null;
    boolean appliesToRootDiagram = diagram.getId().equals(diagramElementId);
    if (appliesToRootDiagram) {
        targetObjectId = diagram.getTargetObjectId();
    } else {
        var findNodeById = this.diagramQueryService.findNodeById(diagram, diagramElementId);
        if (findNodeById.isPresent()) {
            Node node = findNodeById.get();
            targetObjectId = node.getTargetObjectId();
        } else {
            var findEdgeById = this.diagramQueryService.findEdgeById(diagram, diagramElementId);
            if (findEdgeById.isPresent()) {
                Edge edge = findEdgeById.get();
                targetObjectId = edge.getTargetObjectId();
            }
        }
    }
    if (targetObjectId != null) {
        return this.objectService.getObject(editingContext, targetObjectId);
    }
    return Optional.empty();
}
Also used : Node(org.eclipse.sirius.components.diagrams.Node) Edge(org.eclipse.sirius.components.diagrams.Edge)

Example 3 with Edge

use of org.eclipse.sirius.components.diagrams.Edge in project sirius-components by eclipse-sirius.

the class DiagramRendererEdgeTests method testSimpleEdgeRendering.

/**
 * Creates a diagram with two nodes "First" and "Second" and with an edge between the two nodes.
 */
@Test
public void testSimpleEdgeRendering() {
    NodeDescription nodeDescription = this.getNodeDescription(NODE_DESCRIPTION_ID1);
    EdgeDescription edgeDescription = this.getEdgeDescription(nodeDescription, EDGE_DESCRIPTION_ID);
    Diagram diagram = this.renderDiagram(List.of(nodeDescription), List.of(edgeDescription));
    assertThat(diagram).isNotNull();
    assertThat(diagram.getId()).asString().isNotBlank();
    assertThat(diagram.getLabel()).isNotBlank();
    assertThat(diagram.getTargetObjectId()).isNotBlank();
    assertThat(diagram.getNodes()).hasSize(2);
    Node firstNode = diagram.getNodes().get(0);
    Node secondNode = diagram.getNodes().get(1);
    assertThat(diagram.getEdges()).hasSize(1);
    Edge edge = diagram.getEdges().get(0);
    assertThat(edge).extracting(Edge::getSourceId).isEqualTo(firstNode.getId());
    assertThat(edge).extracting(Edge::getTargetId).isEqualTo(secondNode.getId());
}
Also used : NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) Node(org.eclipse.sirius.components.diagrams.Node) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) Edge(org.eclipse.sirius.components.diagrams.Edge) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 4 with Edge

use of org.eclipse.sirius.components.diagrams.Edge in project sirius-components by eclipse-sirius.

the class DiagramRendererEdgeTests method testEdgeRendering.

/**
 * Check edge between nodes (of a first mapping) that represents objects that are represented by another mapping. To
 * do so, this test creates a diagram with
 * <li>two nodes "First" and "Second" from a nodeDescriptionId1</li>
 * <li>two other nodes "First" and "Second" from a nodeDescriptionId2</li>
 * <li>an edge between nodes of a type nodeDescriptionId1</li>
 */
@Test
public void testEdgeRendering() {
    NodeDescription nodeDescription1 = this.getNodeDescription(NODE_DESCRIPTION_ID1);
    NodeDescription nodeDescription2 = this.getNodeDescription(NODE_DESCRIPTION_ID2);
    EdgeDescription edgeDescription = this.getEdgeDescription(nodeDescription1, EDGE_DESCRIPTION_ID);
    Diagram diagram = this.renderDiagram(List.of(nodeDescription1, nodeDescription2), List.of(edgeDescription));
    assertThat(diagram.getNodes()).hasSize(4);
    Node node1 = diagram.getNodes().get(0);
    Node node2 = diagram.getNodes().get(1);
    assertThat(diagram.getEdges()).hasSize(1);
    Edge edge = diagram.getEdges().get(0);
    assertThat(edge).extracting(Edge::getSourceId).isEqualTo(node1.getId());
    assertThat(edge).extracting(Edge::getTargetId).isEqualTo(node2.getId());
}
Also used : NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) Node(org.eclipse.sirius.components.diagrams.Node) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) Edge(org.eclipse.sirius.components.diagrams.Edge) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 5 with Edge

use of org.eclipse.sirius.components.diagrams.Edge in project sirius-components by eclipse-sirius.

the class DiagramConverterTests method testDiagramOneEdgeBetweenTwoBorderNodes.

@Test
public void testDiagramOneEdgeBetweenTwoBorderNodes() {
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    ELKDiagramConverter diagramConverter = new ELKDiagramConverter(this.textBoundsService, imageSizeProvider);
    // @formatter:off
    TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
    Node firstBorderNode = Node.newNode(diagramBuilder.getNode(FIRST_NODE_ID)).style(diagramBuilder.getRectangularNodeStyle()).build();
    Node secondBorderNode = Node.newNode(diagramBuilder.getNode(SECOND_NODE_ID)).style(diagramBuilder.getRectangularNodeStyle()).build();
    Node node = Node.newNode(diagramBuilder.getNode(THIRD_NODE_ID)).style(diagramBuilder.getImageNodeStyle()).borderNodes(List.of(firstBorderNode, secondBorderNode)).build();
    Edge edge = Edge.newEdge(diagramBuilder.getEdge(FIRST_EDGE_ID, firstBorderNode.getId(), secondBorderNode.getId())).build();
    Diagram diagram = Diagram.newDiagram(diagramBuilder.getDiagram(DIAGRAM_ID)).nodes(List.of(node)).edges(List.of(edge)).build();
    // @formatter:on
    ELKConvertedDiagram convertedDiagram = diagramConverter.convert(diagram);
    ElkNode elkDiagram = convertedDiagram.getElkDiagram();
    assertThat(elkDiagram.getChildren().size()).isEqualTo(1);
    assertThat(elkDiagram.getChildren().get(0)).isInstanceOf(ElkNode.class);
    assertThat(elkDiagram.getContainedEdges().size()).isEqualTo(1);
    assertThat(elkDiagram.getContainedEdges().get(0)).isInstanceOf(ElkEdge.class);
    ElkEdge elkEdge = elkDiagram.getContainedEdges().get(0);
    assertThat(elkEdge.getSources().size()).isEqualTo(1);
    assertThat(elkEdge.getSources().get(0).getIdentifier()).isEqualTo(firstBorderNode.getId().toString());
    assertThat(elkEdge.getTargets().size()).isEqualTo(1);
    assertThat(elkEdge.getTargets().get(0).getIdentifier()).isEqualTo(secondBorderNode.getId().toString());
    imageSizeProvider.dispose();
}
Also used : ELKDiagramConverter(org.eclipse.sirius.components.diagrams.layout.ELKDiagramConverter) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) ElkNode(org.eclipse.elk.graph.ElkNode) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) Edge(org.eclipse.sirius.components.diagrams.Edge) ElkEdge(org.eclipse.elk.graph.ElkEdge) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) Diagram(org.eclipse.sirius.components.diagrams.Diagram) ElkEdge(org.eclipse.elk.graph.ElkEdge) Test(org.junit.jupiter.api.Test)

Aggregations

Edge (org.eclipse.sirius.components.diagrams.Edge)15 Node (org.eclipse.sirius.components.diagrams.Node)14 Diagram (org.eclipse.sirius.components.diagrams.Diagram)6 Test (org.junit.jupiter.api.Test)5 ElkEdge (org.eclipse.elk.graph.ElkEdge)4 ElkNode (org.eclipse.elk.graph.ElkNode)4 EdgeDescription (org.eclipse.sirius.components.diagrams.description.EdgeDescription)4 NodeDescription (org.eclipse.sirius.components.diagrams.description.NodeDescription)4 ArrayList (java.util.ArrayList)3 ELKConvertedDiagram (org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram)3 TestDiagramBuilder (org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder)3 VariableManager (org.eclipse.sirius.components.representations.VariableManager)3 List (java.util.List)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 Position (org.eclipse.sirius.components.diagrams.Position)2 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)2 ELKDiagramConverter (org.eclipse.sirius.components.diagrams.layout.ELKDiagramConverter)2 ImageSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider)2