Search in sources :

Example 1 with JsonBasedEditingContext

use of org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext in project sirius-components by eclipse-sirius.

the class DiagramELKLayoutTest method testNodeLayoutWithMultilineLabel.

@Test
public void testNodeLayoutWithMultilineLabel() throws IOException {
    // $NON-NLS-1$
    String nodeLabelWithMultiple = "First LineAAAAAAAA\nSecond LineBBBBBBBBB";
    // $NON-NLS-1$
    String firstChildTargetObjectId = "First child";
    // @formatter:off
    Diagram diagram = // $NON-NLS-1$
    TestLayoutDiagramBuilder.diagram("Root").nodes().rectangleNode(nodeLabelWithMultiple).at(10, 10).of(10, 10).childNodes().rectangleNode(firstChildTargetObjectId).at(10, 10).of(50, 50).and().and().and().and().build();
    // @formatter:on
    // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$
    Path path = Paths.get("src", "test", "resources", "editing-contexts", "testNodeLayoutWithMultilineLabel");
    JsonBasedEditingContext editingContext = new JsonBasedEditingContext(path);
    TestDiagramCreationService diagramCreationService = this.createDiagramCreationService(diagram);
    Diagram layoutedDiagram = diagramCreationService.performElKLayout(editingContext, diagram);
    Node firstParent = layoutedDiagram.getNodes().get(0);
    // Check that the parent node and the label have the right size
    assertThat(firstParent.getSize()).isEqualTo(Size.of(195.8818359375, 131.197265625));
    assertThat(firstParent.getLabel().getSize()).isEqualTo(Size.of(161.8818359375, 32.197265625));
    // Check that the inner node is under the multi line label area
    assertThat(firstParent.getChildNodes().get(0).getPosition()).isEqualTo(Position.at(12, 49.197265625));
}
Also used : Path(java.nio.file.Path) Node(org.eclipse.sirius.components.diagrams.Node) JsonBasedEditingContext(org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 2 with JsonBasedEditingContext

use of org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext in project sirius-components by eclipse-sirius.

the class NodeCreationTests method testNodeCreationOutsideItsParent.

@Test
public void testNodeCreationOutsideItsParent() {
    // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$
    Path path = Paths.get("src", "test", "resources", "editing-contexts", "testNodeCreationOutsideItsParent");
    JsonBasedEditingContext editingContext = new JsonBasedEditingContext(path);
    Position eventCreationPosition = Position.at(100, 100);
    // @formatter:off
    Diagram diagram = // $NON-NLS-1$
    TestLayoutDiagramBuilder.diagram("Root").nodes().rectangleNode("A").at(10, 10).of(200, 300).and().rectangleNode("B").at(500, 500).of(200, 300).and().and().build();
    // @formatter:on
    // we create a child of B by clicking inside of A
    Diagram layoutedDiagram = this.createNewNode(diagram, editingContext, eventCreationPosition);
    // $NON-NLS-1$
    Optional<Node> optionalA = this.getNode(layoutedDiagram.getNodes(), "A");
    assertThat(optionalA).isPresent();
    // $NON-NLS-1$
    Optional<Node> optionalB = this.getNode(layoutedDiagram.getNodes(), "B");
    assertThat(optionalB).isPresent();
    // $NON-NLS-1$
    Optional<Node> optionalChild = this.getNode(layoutedDiagram.getNodes(), "Child");
    assertThat(optionalChild).isPresent();
    // A should not have been resized
    Node aNode = optionalA.get();
    assertThat(aNode.getPosition()).isEqualTo(Position.at(10, 10));
    assertThat(aNode.getSize()).isEqualTo(Size.of(200, 300));
    Node bNode = optionalB.get();
    // Child should be within B
    assertThat(bNode).hasEveryChildWithinItsBounds();
    // B should not haven been resized
    assertThat(bNode.getPosition()).isEqualTo(Position.at(500, 500));
    assertThat(bNode.getSize()).isEqualTo(Size.of(200, 300));
}
Also used : Path(java.nio.file.Path) Position(org.eclipse.sirius.components.diagrams.Position) Node(org.eclipse.sirius.components.diagrams.Node) JsonBasedEditingContext(org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 3 with JsonBasedEditingContext

use of org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext in project sirius-components by eclipse-sirius.

the class NodeCreationTests method testMultiNodeCreation.

@Test
public void testMultiNodeCreation() {
    // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$
    Path path = Paths.get("src", "test", "resources", "editing-contexts", "testNodeCreation");
    JsonBasedEditingContext editingContext = new JsonBasedEditingContext(path);
    Position eventCreationPosition = Position.at(100, 100);
    // $NON-NLS-1$
    Diagram diagram = TestLayoutDiagramBuilder.diagram("Root").nodes().and().build();
    Diagram layoutedDiagram = this.createNewNode(diagram, editingContext, eventCreationPosition);
    // parent node should still be positioned at the eventCreationPosition
    // $NON-NLS-1$
    Optional<Node> optionalParent = this.getNode(layoutedDiagram.getNodes(), "Parent");
    assertThat(optionalParent).isPresent();
    Node parent = optionalParent.get();
    Position parentPosition = parent.getPosition();
    assertThat(parentPosition).isEqualTo(Position.at(100, 100));
    // since the parent was not positioned yet, its children should be at a default position
    // $NON-NLS-1$
    Optional<Node> optionalChild = this.getNode(layoutedDiagram.getNodes(), "Child");
    assertThat(optionalChild).isPresent();
    Node child = optionalChild.get();
    assertThat(child.getPosition()).isEqualTo(this.getDefaultPosition(parent, child));
}
Also used : Path(java.nio.file.Path) Position(org.eclipse.sirius.components.diagrams.Position) Node(org.eclipse.sirius.components.diagrams.Node) JsonBasedEditingContext(org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 4 with JsonBasedEditingContext

use of org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext in project sirius-components by eclipse-sirius.

the class NodeResizeTests method resizeNode.

private Optional<Node> resizeNode(String objectId, Diagram diagram, Position positionDelta, Size newSize) {
    // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$
    Path path = Paths.get("src", "test", "resources", "editing-contexts", "testResizeWithNoPositionDelta");
    JsonBasedEditingContext editingContext = new JsonBasedEditingContext(path);
    TestDiagramCreationService diagramCreationService = this.createDiagramCreationService(diagram);
    Optional<Node> optionalFirstParent = this.getNode(diagram.getNodes(), objectId);
    assertThat(optionalFirstParent).isPresent();
    Node firstParent = optionalFirstParent.get();
    IDiagramEvent resizeEvent = new ResizeEvent(firstParent.getId(), positionDelta, newSize);
    Diagram layoutedDiagram = diagramCreationService.performLayout(editingContext, diagram, resizeEvent);
    Optional<Node> optionalResizedFirstParent = this.getNode(layoutedDiagram.getNodes(), objectId);
    assertThat(optionalResizedFirstParent).isPresent();
    return optionalResizedFirstParent;
}
Also used : Path(java.nio.file.Path) TestDiagramCreationService(org.eclipse.sirius.components.diagrams.layout.services.TestDiagramCreationService) Node(org.eclipse.sirius.components.diagrams.Node) JsonBasedEditingContext(org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) ResizeEvent(org.eclipse.sirius.components.diagrams.events.ResizeEvent) Diagram(org.eclipse.sirius.components.diagrams.Diagram)

Example 5 with JsonBasedEditingContext

use of org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext in project sirius-components by eclipse-sirius.

the class DiagramLayoutTest method testSimpleDiagramLayout.

@Test
public void testSimpleDiagramLayout() throws IOException {
    // $NON-NLS-1$
    String firstParentTargetObjectId = "First Parent";
    // $NON-NLS-1$
    String secondParentTargetObjectId = "Second Parent";
    // $NON-NLS-1$
    String firstChildTargetObjectId = "First child";
    // $NON-NLS-1$
    String secondChildTargetObjectId = "Second child";
    // @formatter:off
    Diagram diagram = // $NON-NLS-1$
    TestLayoutDiagramBuilder.diagram("Root").nodes().rectangleNode(firstParentTargetObjectId).at(10, 10).of(200, 300).childNodes().rectangleNode(firstChildTargetObjectId).at(10, 10).of(50, 50).and().rectangleNode(secondChildTargetObjectId).at(70, 70).of(50, 50).and().and().and().rectangleNode(secondParentTargetObjectId).at(300, 400).of(100, 100).and().and().edge(// $NON-NLS-1$
    "Link").from(firstParentTargetObjectId).at(0.5, 0.5).to(secondParentTargetObjectId).at(0.8, 0.8).and().edge(// $NON-NLS-1$
    "Opposite Link").from(secondParentTargetObjectId).at(0.2, 0.7).to(firstParentTargetObjectId).at(0.1, 0.9).and().build();
    // @formatter:on
    // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$
    Path path = Paths.get("src", "test", "resources", "editing-contexts", "testSimpleDiagramLayout");
    JsonBasedEditingContext editingContext = new JsonBasedEditingContext(path);
    TestDiagramCreationService diagramCreationService = this.createDiagramCreationService(diagram);
    Optional<Diagram> optionalRefreshedDiagram = diagramCreationService.performRefresh(editingContext, diagram);
    assertThat(optionalRefreshedDiagram).isNotEmpty();
    Diagram refreshedDiagram = optionalRefreshedDiagram.get();
    Optional<Node> optionalFirstParent = this.getNode(refreshedDiagram.getNodes(), firstParentTargetObjectId);
    assertThat(optionalFirstParent).isPresent();
    Node firstParent = optionalFirstParent.get();
    assertThat(firstParent.getPosition()).isEqualTo(Position.at(10, 10));
    assertThat(firstParent.getSize()).isEqualTo(Size.of(200, 300));
    Optional<Node> optionalFirstChild = this.getNode(refreshedDiagram.getNodes(), firstChildTargetObjectId);
    assertThat(optionalFirstChild).isPresent();
    Node firstChild = optionalFirstChild.get();
    assertThat(firstChild.getPosition()).isEqualTo(Position.at(10, 10));
    assertThat(firstChild.getSize()).isEqualTo(Size.of(50, 50));
    // $NON-NLS-1$
    Optional<Node> optionalThirdParent = this.getNode(refreshedDiagram.getNodes(), "Third Parent");
    assertThat(optionalThirdParent).isPresent();
    Node thirdParent = optionalThirdParent.get();
    assertThat(thirdParent.getPosition()).isEqualTo(Position.UNDEFINED);
    IDiagramEvent diagramEvent = new SinglePositionEvent(Position.at(300, 100));
    Diagram layoutedDiagram = diagramCreationService.performLayout(editingContext, refreshedDiagram, diagramEvent);
    // $NON-NLS-1$
    Optional<Node> optionalLayoutedThirdParent = this.getNode(layoutedDiagram.getNodes(), "Third Parent");
    assertThat(optionalLayoutedThirdParent).isPresent();
    Node layoutedThirdParent = optionalLayoutedThirdParent.get();
    assertThat(layoutedThirdParent.getPosition()).isEqualTo(Position.at(300, 100));
}
Also used : Path(java.nio.file.Path) TestDiagramCreationService(org.eclipse.sirius.components.diagrams.layout.services.TestDiagramCreationService) Node(org.eclipse.sirius.components.diagrams.Node) SinglePositionEvent(org.eclipse.sirius.components.diagrams.events.SinglePositionEvent) JsonBasedEditingContext(org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Aggregations

Path (java.nio.file.Path)10 Diagram (org.eclipse.sirius.components.diagrams.Diagram)10 JsonBasedEditingContext (org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext)10 Test (org.junit.jupiter.api.Test)9 Position (org.eclipse.sirius.components.diagrams.Position)7 Node (org.eclipse.sirius.components.diagrams.Node)6 IDiagramEvent (org.eclipse.sirius.components.diagrams.events.IDiagramEvent)2 TestDiagramCreationService (org.eclipse.sirius.components.diagrams.layout.services.TestDiagramCreationService)2 ResizeEvent (org.eclipse.sirius.components.diagrams.events.ResizeEvent)1 SinglePositionEvent (org.eclipse.sirius.components.diagrams.events.SinglePositionEvent)1