Search in sources :

Example 6 with Edge

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

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);
}
Also used : ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ELKLayoutedDiagramProvider(org.eclipse.sirius.components.diagrams.layout.ELKLayoutedDiagramProvider) 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) Test(org.junit.jupiter.api.Test)

Example 8 with Edge

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;
}
Also used : Node(org.eclipse.sirius.components.diagrams.Node) Edge(org.eclipse.sirius.components.diagrams.Edge)

Example 9 with Edge

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);
        }
    }
}
Also used : Node(org.eclipse.sirius.components.diagrams.Node) ViewDeletionRequest(org.eclipse.sirius.components.diagrams.ViewDeletionRequest) Edge(org.eclipse.sirius.components.diagrams.Edge)

Example 10 with Edge

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;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Edge(org.eclipse.sirius.components.diagrams.Edge) Node(org.eclipse.sirius.components.diagrams.Node) Environment(org.eclipse.sirius.components.core.api.Environment) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInput) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) LoggerFactory(org.slf4j.LoggerFactory) One(reactor.core.publisher.Sinks.One) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ArrayList(java.util.ArrayList) IDiagramDescriptionService(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramDescriptionService) Diagram(org.eclipse.sirius.components.diagrams.Diagram) IStatus(org.eclipse.sirius.components.representations.IStatus) Monitoring(org.eclipse.sirius.components.collaborative.api.Monitoring) Service(org.springframework.stereotype.Service) ICollaborativeDiagramMessageService(org.eclipse.sirius.components.collaborative.diagrams.messages.ICollaborativeDiagramMessageService) DeleteFromDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.DeleteFromDiagramInput) IDiagramQueryService(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramQueryService) Counter(io.micrometer.core.instrument.Counter) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) Logger(org.slf4j.Logger) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) DeleteFromDiagramSuccessPayload(org.eclipse.sirius.components.collaborative.diagrams.dto.DeleteFromDiagramSuccessPayload) IRepresentationDescriptionSearchService(org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService) DeletionPolicy(org.eclipse.sirius.components.collaborative.diagrams.dto.DeletionPolicy) Objects(java.util.Objects) List(java.util.List) IPayload(org.eclipse.sirius.components.core.api.IPayload) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) IDiagramEventHandler(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventHandler) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IStatus(org.eclipse.sirius.components.representations.IStatus) Environment(org.eclipse.sirius.components.core.api.Environment) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) Failure(org.eclipse.sirius.components.representations.Failure)

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