use of org.eclipse.sirius.components.diagrams.Edge 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();
}
use of org.eclipse.sirius.components.diagrams.Edge in project sirius-components by eclipse-sirius.
the class LayoutedDiagramProviderTests method testLayoutedDiagramProvider.
@Test
public void testLayoutedDiagramProvider() {
// @formatter:off
TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
Node node = Node.newNode(diagramBuilder.getNode(FIRST_NODE_ID)).build();
Edge edge = Edge.newEdge(diagramBuilder.getEdge(FIRST_EDGE_ID, node.getId(), node.getId())).build();
Diagram originalDiagram = Diagram.newDiagram(diagramBuilder.getDiagram(DIAGRAM_ID)).nodes(List.of(node)).edges(List.of(edge)).build();
// @formatter:on
ELKConvertedDiagram convertedDiagram = this.getConvertedDiagram(originalDiagram);
Diagram layoutedDiagram = new ELKLayoutedDiagramProvider().getLayoutedDiagram(originalDiagram, convertedDiagram.getElkDiagram(), convertedDiagram.getId2ElkGraphElements());
assertThat(layoutedDiagram).hasBounds(0, 0, 0, 0);
assertThat(layoutedDiagram.getNodes()).hasSizeGreaterThan(0);
assertThat(layoutedDiagram.getNodes().get(0)).hasBounds(NODE_X, NODE_Y, NODE_WIDTH, NODE_HEIGHT);
assertThat(layoutedDiagram).matchesRecursively(originalDiagram, IdPolicy.WITH_ID, LayoutPolicy.WITHOUT_LAYOUT);
}
use of org.eclipse.sirius.components.diagrams.Edge in project sirius-components by eclipse-sirius.
the class DiagramAssert method matchesRecursively.
/**
* Asserts that the actual diagram has the same properties as the given diagram (without taking into account the
* position and size of any elements.
*
* @param diagram
* The given diagram
* @param idPolicy
* Indicates if the identifiers of the diagram elements should match too
* @param layoutPolicy
* Indicates that the size, position and routing points of the diagram and its elements should match too
* @return The current diagram assert
*/
public DiagramAssert matchesRecursively(Diagram diagram, IdPolicy idPolicy, LayoutPolicy layoutPolicy) {
this.matches(diagram, idPolicy, layoutPolicy);
if (this.actual != null && diagram != null) {
assertThat(this.actual.getNodes()).hasSize(diagram.getNodes().size());
assertThat(this.actual.getEdges()).hasSize(diagram.getEdges().size());
if (this.actual.getNodes().size() == diagram.getNodes().size()) {
int size = this.actual.getNodes().size();
for (int i = 0; i < size; i++) {
Node actualNode = this.actual.getNodes().get(i);
Node node = diagram.getNodes().get(i);
assertThat(actualNode).matchesRecursively(node, idPolicy, layoutPolicy);
}
}
if (this.actual.getEdges().size() == diagram.getEdges().size()) {
int size = this.actual.getEdges().size();
for (int i = 0; i < size; i++) {
Edge actualEdge = this.actual.getEdges().get(i);
Edge edge = diagram.getEdges().get(i);
assertThat(actualEdge).matches(edge, idPolicy, layoutPolicy);
}
}
}
return this;
}
use of org.eclipse.sirius.components.diagrams.Edge in project sirius-components by eclipse-sirius.
the class ToolInterpreter method deleteView.
public void deleteView(Object element) {
if (this.diagramContext != null) {
String elementId = null;
if (element instanceof Node) {
elementId = ((Node) element).getId();
} else if (element instanceof Edge) {
elementId = ((Edge) element).getId();
}
if (elementId != null) {
ViewDeletionRequest viewDeletionRequest = ViewDeletionRequest.newViewDeletionRequest().elementId(elementId).build();
this.diagramContext.getViewDeletionRequests().add(viewDeletionRequest);
}
}
}
use of org.eclipse.sirius.components.diagrams.Edge in project sirius-components by eclipse-sirius.
the class DeleteFromDiagramEventHandler method invokeDeleteEdgeTool.
private IStatus invokeDeleteEdgeTool(Edge edge, IEditingContext editingContext, IDiagramContext diagramContext, DeletionPolicy deletionPolicy) {
// $NON-NLS-1$
IStatus result = new Failure("");
var optionalEdgeDescription = this.findEdgeDescription(edge, diagramContext.getDiagram(), editingContext);
if (optionalEdgeDescription.isPresent()) {
var optionalSelf = this.objectService.getObject(editingContext, edge.getTargetObjectId());
if (optionalSelf.isPresent()) {
VariableManager variableManager = new VariableManager();
variableManager.put(VariableManager.SELF, optionalSelf.get());
variableManager.put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
variableManager.put(Edge.SELECTED_EDGE, edge);
variableManager.put(DELETION_POLICY, deletionPolicy);
variableManager.put(Environment.ENVIRONMENT, new Environment(Environment.SIRIUS_COMPONENTS));
// @formatter:off
this.diagramQueryService.findNodeById(diagramContext.getDiagram(), edge.getSourceId()).flatMap(node -> this.objectService.getObject(editingContext, node.getTargetObjectId())).ifPresent(semanticElement -> variableManager.put(EdgeDescription.SEMANTIC_EDGE_SOURCE, semanticElement));
this.diagramQueryService.findNodeById(diagramContext.getDiagram(), edge.getTargetId()).flatMap(node -> this.objectService.getObject(editingContext, node.getTargetObjectId())).ifPresent(semanticElement -> variableManager.put(EdgeDescription.SEMANTIC_EDGE_TARGET, semanticElement));
// @formatter:on
EdgeDescription edgeDescription = optionalEdgeDescription.get();
// $NON-NLS-1$
this.logger.debug("Deleted diagram edge {}", edge.getId());
result = edgeDescription.getDeleteHandler().apply(variableManager);
} else {
String message = this.messageService.semanticObjectNotFound(edge.getTargetObjectId());
this.logger.debug(message);
result = new Failure(message);
}
} else {
String message = this.messageService.edgeDescriptionNotFound(edge.getId().toString());
this.logger.debug(message);
result = new Failure(message);
}
return result;
}
Aggregations