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