Search in sources :

Example 21 with Diagram

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

the class UnsynchronizedDiagramTests method testUnsynchronizedRenderingOnNodeContainerAfterDeletion.

/**
 * This very simple test will validate that we can add and remove an unsynchronized node thanks to a
 * ViewCreationRequest/ViewDeletionRequest on a node container. We will test the following sequence of events:
 *
 * <ul>
 * <li>render the diagram with two nodes (the first is unsynchronized, the second is synchronized)</li>
 * <li>create a new node thanks to a ViewCreationRequest during a refresh diagram</li>
 * <li>delete the node thanks to a ViewDeletionRequest during a refresh diagram: no child nodes should be visible on
 * the first unsynchronized node children</li>
 * </ul>
 */
@Test
public void testUnsynchronizedRenderingOnNodeContainerAfterDeletion() {
    DiagramDescription diagramDescription = this.getDiagramDescription();
    Diagram initialDiagram = this.render(diagramDescription, List.of(), List.of(), Optional.empty());
    // @formatter:off
    ViewCreationRequest viewCreationRequest = ViewCreationRequest.newViewCreationRequest().descriptionId(diagramDescription.getNodeDescriptions().get(0).getId()).parentElementId(initialDiagram.getId()).targetObjectId(TARGET_OBJECT_ID).build();
    // @formatter:on
    Diagram diagramAfterFirstNodeCreation = this.render(diagramDescription, List.of(viewCreationRequest), List.of(), Optional.of(initialDiagram));
    UUID descriptionId = diagramDescription.getNodeDescriptions().get(0).getChildNodeDescriptions().get(0).getId();
    String parentNodeId = diagramAfterFirstNodeCreation.getNodes().get(0).getId();
    // @formatter:off
    ViewCreationRequest childViewCreationRequest = ViewCreationRequest.newViewCreationRequest().descriptionId(descriptionId).parentElementId(parentNodeId).targetObjectId(TARGET_OBJECT_ID).build();
    // @formatter:on
    Diagram diagramAfterSecondNodeCreation = this.render(diagramDescription, List.of(childViewCreationRequest), List.of(), Optional.of(diagramAfterFirstNodeCreation));
    String nodeIdToDelete = diagramAfterSecondNodeCreation.getNodes().get(0).getChildNodes().get(0).getId();
    // @formatter:off
    ViewDeletionRequest viewDeletionRequest = ViewDeletionRequest.newViewDeletionRequest().elementId(nodeIdToDelete).build();
    // @formatter:on
    Diagram diagramAfterSecondNodeDeletion = this.render(diagramDescription, List.of(), List.of(viewDeletionRequest), Optional.of(diagramAfterFirstNodeCreation));
    assertThat(diagramAfterSecondNodeDeletion.getNodes()).hasSize(2);
    Node firstRootNode = diagramAfterSecondNodeDeletion.getNodes().get(0);
    assertThat(firstRootNode.getBorderNodes()).isEmpty();
    assertThat(firstRootNode.getChildNodes()).isEmpty();
    Node secondRootNode = diagramAfterSecondNodeCreation.getNodes().get(1);
    assertThat(secondRootNode.getBorderNodes()).isEmpty();
    assertThat(secondRootNode.getChildNodes()).isEmpty();
}
Also used : ViewCreationRequest(org.eclipse.sirius.components.diagrams.ViewCreationRequest) Node(org.eclipse.sirius.components.diagrams.Node) UUID(java.util.UUID) ViewDeletionRequest(org.eclipse.sirius.components.diagrams.ViewDeletionRequest) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 22 with Diagram

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

the class DiagramComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    DiagramDescription diagramDescription = this.props.getDiagramDescription();
    var optionalPreviousDiagram = this.props.getPreviousDiagram();
    String label = diagramDescription.getLabelProvider().apply(variableManager);
    String diagramId = optionalPreviousDiagram.map(Diagram::getId).orElseGet(() -> UUID.randomUUID().toString());
    String targetObjectId = diagramDescription.getTargetObjectIdProvider().apply(variableManager);
    DiagramRenderingCache cache = new DiagramRenderingCache();
    IDiagramElementRequestor diagramElementRequestor = new DiagramElementRequestor();
    // @formatter:off
    var nodes = diagramDescription.getNodeDescriptions().stream().map(nodeDescription -> {
        var previousNodes = optionalPreviousDiagram.map(previousDiagram -> diagramElementRequestor.getRootNodes(previousDiagram, nodeDescription)).orElse(List.of());
        INodesRequestor nodesRequestor = new NodesRequestor(previousNodes);
        var nodeComponentProps = NodeComponentProps.newNodeComponentProps().variableManager(variableManager).nodeDescription(nodeDescription).nodesRequestor(nodesRequestor).containmentKind(NodeContainmentKind.CHILD_NODE).cache(cache).viewCreationRequests(this.props.getViewCreationRequests()).viewDeletionRequests(this.props.getViewDeletionRequests()).parentElementId(diagramId).build();
        return new Element(NodeComponent.class, nodeComponentProps);
    }).collect(Collectors.toList());
    var edges = diagramDescription.getEdgeDescriptions().stream().map(edgeDescription -> {
        var previousEdges = optionalPreviousDiagram.map(previousDiagram -> diagramElementRequestor.getEdges(previousDiagram, edgeDescription)).orElse(List.of());
        IEdgesRequestor edgesRequestor = new EdgesRequestor(previousEdges);
        var edgeComponentProps = new EdgeComponentProps(variableManager, edgeDescription, edgesRequestor, cache);
        return new Element(EdgeComponent.class, edgeComponentProps);
    }).collect(Collectors.toList());
    // @formatter:on
    List<Element> children = new ArrayList<>();
    children.addAll(nodes);
    children.addAll(edges);
    // @formatter:off
    Position position = optionalPreviousDiagram.map(Diagram::getPosition).orElse(Position.UNDEFINED);
    Size size = optionalPreviousDiagram.map(Diagram::getSize).orElse(Size.UNDEFINED);
    DiagramElementProps diagramElementProps = DiagramElementProps.newDiagramElementProps(diagramId).targetObjectId(targetObjectId).descriptionId(diagramDescription.getId()).label(label).position(position).size(size).children(children).build();
    // @formatter:on
    return new Element(DiagramElementProps.TYPE, diagramElementProps);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Size(org.eclipse.sirius.components.diagrams.Size) Position(org.eclipse.sirius.components.diagrams.Position) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Element(org.eclipse.sirius.components.representations.Element) IComponent(org.eclipse.sirius.components.representations.IComponent) ArrayList(java.util.ArrayList) List(java.util.List) Diagram(org.eclipse.sirius.components.diagrams.Diagram) DiagramElementProps(org.eclipse.sirius.components.diagrams.elements.DiagramElementProps) VariableManager(org.eclipse.sirius.components.representations.VariableManager) DiagramRenderingCache(org.eclipse.sirius.components.diagrams.renderer.DiagramRenderingCache) Position(org.eclipse.sirius.components.diagrams.Position) Size(org.eclipse.sirius.components.diagrams.Size) Element(org.eclipse.sirius.components.representations.Element) ArrayList(java.util.ArrayList) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) DiagramRenderingCache(org.eclipse.sirius.components.diagrams.renderer.DiagramRenderingCache) DiagramElementProps(org.eclipse.sirius.components.diagrams.elements.DiagramElementProps)

Example 23 with Diagram

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

the class DiagramConverterTests method testDiagramOneNodeAndOneBorderNode.

@Test
public void testDiagramOneNodeAndOneBorderNode() {
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    ELKDiagramConverter diagramConverter = new ELKDiagramConverter(this.textBoundsService, imageSizeProvider);
    // @formatter:off
    TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
    Node borderNode = Node.newNode(diagramBuilder.getNode(FIRST_NODE_ID)).style(diagramBuilder.getRectangularNodeStyle()).build();
    Node node = Node.newNode(diagramBuilder.getNode(SECOND_NODE_ID)).style(diagramBuilder.getImageNodeStyle()).borderNodes(List.of(borderNode)).build();
    Diagram diagram = Diagram.newDiagram(diagramBuilder.getDiagram(DIAGRAM_ID)).nodes(List.of(node)).build();
    // @formatter:on
    ELKConvertedDiagram convertedDiagram = diagramConverter.convert(diagram);
    ElkNode elkDiagram = convertedDiagram.getElkDiagram();
    assertThat(elkDiagram.getChildren().size()).isEqualTo(1);
    ElkNode elkNode = elkDiagram.getChildren().get(0);
    assertThat(elkNode.getPorts().size()).isEqualTo(1);
    ElkPort elkPort = elkNode.getPorts().get(0);
    assertThat(elkPort.getIdentifier()).isEqualTo(borderNode.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) ElkPort(org.eclipse.elk.graph.ElkPort) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 24 with Diagram

use of org.eclipse.sirius.components.diagrams.Diagram 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)

Example 25 with Diagram

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

the class DiagramConverterTests method testDiagramOneNodeAndOneEdge.

@Test
public void testDiagramOneNodeAndOneEdge() {
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    ELKDiagramConverter diagramConverter = new ELKDiagramConverter(this.textBoundsService, imageSizeProvider);
    // @formatter:off
    TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
    Node node = Node.newNode(diagramBuilder.getNode(FIRST_NODE_ID)).style(diagramBuilder.getImageNodeStyle()).build();
    Edge edge = Edge.newEdge(diagramBuilder.getEdge(FIRST_EDGE_ID, node.getId(), node.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.getContainedEdges().size()).isEqualTo(1);
    ElkEdge elkEdge = elkDiagram.getContainedEdges().get(0);
    assertThat(elkEdge.getIdentifier()).isEqualTo(edge.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

Diagram (org.eclipse.sirius.components.diagrams.Diagram)66 Test (org.junit.jupiter.api.Test)37 Node (org.eclipse.sirius.components.diagrams.Node)34 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)28 UUID (java.util.UUID)20 Failure (org.eclipse.sirius.components.representations.Failure)20 VariableManager (org.eclipse.sirius.components.representations.VariableManager)19 ArrayList (java.util.ArrayList)18 List (java.util.List)18 NodeDescription (org.eclipse.sirius.components.diagrams.description.NodeDescription)17 Success (org.eclipse.sirius.components.representations.Success)16 Position (org.eclipse.sirius.components.diagrams.Position)14 Optional (java.util.Optional)13 Function (java.util.function.Function)12 Size (org.eclipse.sirius.components.diagrams.Size)12 IStatus (org.eclipse.sirius.components.representations.IStatus)12 Path (java.nio.file.Path)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)10 IPayload (org.eclipse.sirius.components.core.api.IPayload)10