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