Search in sources :

Example 1 with IDiagramEvent

use of org.eclipse.sirius.components.diagrams.events.IDiagramEvent in project sirius-components by eclipse-sirius.

the class NodeCreationTests method createNewNode.

private Diagram createNewNode(Diagram diagram, IEditingContext editingContext, Position eventCreationPosition) {
    TestDiagramCreationService diagramCreationService = this.createDiagramCreationService(diagram);
    Optional<Diagram> optionalRefreshedDiagram = diagramCreationService.performRefresh(editingContext, diagram);
    assertThat(optionalRefreshedDiagram).isNotEmpty();
    Diagram refreshedDiagram = optionalRefreshedDiagram.get();
    IDiagramEvent diagramEvent = new SinglePositionEvent(eventCreationPosition);
    return diagramCreationService.performLayout(editingContext, refreshedDiagram, diagramEvent);
}
Also used : TestDiagramCreationService(org.eclipse.sirius.components.diagrams.layout.services.TestDiagramCreationService) SinglePositionEvent(org.eclipse.sirius.components.diagrams.events.SinglePositionEvent) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) Diagram(org.eclipse.sirius.components.diagrams.Diagram)

Example 2 with IDiagramEvent

use of org.eclipse.sirius.components.diagrams.events.IDiagramEvent in project sirius-components by eclipse-sirius.

the class NodePositionProviderTests method testDiagramNewNodesOneByOne.

@Test
public void testDiagramNewNodesOneByOne() {
    List<NodeLayoutData> nodes = new ArrayList<>();
    NodePositionProvider nodePositionProvider = new NodePositionProvider();
    DiagramLayoutData diagramLayoutData = this.createDiagramLayoutData();
    NodeLayoutData nodeLayoutData = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, diagramLayoutData, NodeType.NODE_RECTANGLE);
    diagramLayoutData.setChildrenNodes(nodes);
    nodes.add(nodeLayoutData);
    Optional<IDiagramEvent> optionalDiagramElementEvent = Optional.of(new SinglePositionEvent(ZERO_POSITION));
    Position nextPosition = nodePositionProvider.getPosition(optionalDiagramElementEvent, nodeLayoutData);
    nodeLayoutData.setPosition(nextPosition);
    assertThat(nextPosition).isEqualTo(Position.at(0, 0));
    List<NodeLayoutData> childNodes = new ArrayList<>();
    nodeLayoutData.setChildrenNodes(childNodes);
    // Test creation of a new node at a given position within parent (creation tool)
    Position startingPosition = Position.at(START_X_WITHIN_PARENT, START_Y_WITHIN_PARENT);
    nodePositionProvider = new NodePositionProvider();
    NodeLayoutData childLayoutData = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, nodeLayoutData, NodeType.NODE_RECTANGLE);
    childNodes.add(childLayoutData);
    Optional<IDiagramEvent> optionalEventInside = Optional.of(new SinglePositionEvent(startingPosition));
    nextPosition = nodePositionProvider.getPosition(optionalEventInside, childLayoutData);
    assertThat(nextPosition).isEqualTo(startingPosition);
    // Test creation of a new node at a given position outside parent (creation tool)
    Position startingPositionOutside = Position.at(START_X_OUTSIDE_PARENT, START_Y_OUTSIDE_PARENT);
    nodePositionProvider = new NodePositionProvider();
    childLayoutData = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, nodeLayoutData, NodeType.NODE_RECTANGLE);
    childNodes.add(nodeLayoutData);
    Optional<IDiagramEvent> optionalEventOutside = Optional.of(new SinglePositionEvent(startingPositionOutside));
    nextPosition = nodePositionProvider.getPosition(optionalEventOutside, childLayoutData);
    assertThat(nextPosition).isEqualTo(nodePositionProvider.getDefaultPosition(childLayoutData));
}
Also used : DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) Position(org.eclipse.sirius.components.diagrams.Position) ArrayList(java.util.ArrayList) SinglePositionEvent(org.eclipse.sirius.components.diagrams.events.SinglePositionEvent) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) NodePositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Test(org.junit.jupiter.api.Test)

Example 3 with IDiagramEvent

use of org.eclipse.sirius.components.diagrams.events.IDiagramEvent in project sirius-components by eclipse-sirius.

the class NodePositionProviderTests method testMoveNodeEvent.

@Test
public void testMoveNodeEvent() {
    Position nodePosition1 = Position.at(100, 100);
    Position nodePosition2 = Position.at(200, 300);
    List<NodeLayoutData> nodes = new ArrayList<>();
    DiagramLayoutData diagramLayoutData = this.createDiagramLayoutData();
    NodeLayoutData nodeLayoutData = this.createNodeLayoutData(nodePosition1, Size.of(200, 100), diagramLayoutData, NodeType.NODE_RECTANGLE);
    NodeLayoutData nodeLayoutData2 = this.createNodeLayoutData(nodePosition2, Size.of(200, 100), diagramLayoutData, NodeType.NODE_RECTANGLE);
    diagramLayoutData.setChildrenNodes(nodes);
    nodes.add(nodeLayoutData);
    nodes.add(nodeLayoutData2);
    Position newNodePosition = Position.at(300, 300);
    NodePositionProvider nodePositionProvider = new NodePositionProvider();
    Optional<IDiagramEvent> optionalEvent = Optional.of(new MoveEvent(nodeLayoutData.getId(), newNodePosition));
    Position newPosition = nodePositionProvider.getPosition(optionalEvent, nodeLayoutData);
    Position newPosition2 = nodePositionProvider.getPosition(optionalEvent, nodeLayoutData2);
    assertThat(newPosition).isEqualTo(newNodePosition);
    assertThat(newPosition2).isEqualTo(nodePosition2);
}
Also used : Position(org.eclipse.sirius.components.diagrams.Position) DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) ArrayList(java.util.ArrayList) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) MoveEvent(org.eclipse.sirius.components.diagrams.events.MoveEvent) NodePositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Test(org.junit.jupiter.api.Test)

Example 4 with IDiagramEvent

use of org.eclipse.sirius.components.diagrams.events.IDiagramEvent in project sirius-components by eclipse-sirius.

the class BorderNodePositionTests method testBorderNodeCreationEvent.

@Test
public void testBorderNodeCreationEvent() {
    DiagramLayoutData initializeDiagram = this.initializeDiagram();
    List<NodeLayoutData> borderNodes = initializeDiagram.getChildrenNodes().get(0).getBorderNodes();
    // add a border node with an non positioned label
    // $NON-NLS-1$
    LabelLayoutData labelLayoutData = this.createLabelLayoutData(Position.at(-1, -1), "any", BORDER_NODE_LABEL_TEXT_BOUNDS);
    borderNodes.add(this.createBorderNodeLayoutData(BORDER_NODE_LABEL_TEXT_POSITION, DEFAULT_BORDER_NODE_SIZE, initializeDiagram, NodeType.NODE_RECTANGLE, labelLayoutData));
    NodeSizeProvider nodeSizeProvider = new NodeSizeProvider(new ImageSizeProvider());
    IncrementalLayoutEngine incrementalLayoutEngine = new IncrementalLayoutEngine(nodeSizeProvider);
    Optional<IDiagramEvent> creationEvent = Optional.of(new SinglePositionEvent(Position.at(10, 10)));
    incrementalLayoutEngine.layout(creationEvent, initializeDiagram, new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator());
    this.checkBorderNodeLabel(borderNodes.get(0).getLabel(), BORDER_NODE_LABEL_TEXT_POSITION, BORDER_NODE_LABEL_TEXT_BOUNDS);
}
Also used : DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) LabelLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData) NodeSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider) SinglePositionEvent(org.eclipse.sirius.components.diagrams.events.SinglePositionEvent) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) LayoutConfiguratorRegistry(org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Test(org.junit.jupiter.api.Test)

Example 5 with IDiagramEvent

use of org.eclipse.sirius.components.diagrams.events.IDiagramEvent in project sirius-components by eclipse-sirius.

the class BorderNodePositionTests method testResizeParentNodeNorthWestEvent.

@Test
public void testResizeParentNodeNorthWestEvent() {
    DiagramLayoutData initializeDiagram = this.initializeDiagram();
    String nodeId = initializeDiagram.getChildrenNodes().get(0).getId();
    List<NodeLayoutData> borderNodes = initializeDiagram.getChildrenNodes().get(0).getBorderNodes();
    NodeSizeProvider nodeSizeProvider = new NodeSizeProvider(new ImageSizeProvider());
    IncrementalLayoutEngine incrementalLayoutEngine = new IncrementalLayoutEngine(nodeSizeProvider);
    // Decrease the parent node size
    Optional<IDiagramEvent> resizeEvent = Optional.of(new ResizeEvent(nodeId, Position.at(100, 50), Size.of(100, 50)));
    incrementalLayoutEngine.layout(resizeEvent, initializeDiagram, new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator());
    this.checkBorderNodesAfterResize(borderNodes);
    // Increase the parent node size to get the initial size
    resizeEvent = Optional.of(new ResizeEvent(nodeId, ZERO_POSITION, DEFAULT_NODE_SIZE));
    incrementalLayoutEngine.layout(resizeEvent, initializeDiagram, new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator());
    this.checkBorderNodesAtInitialPosition(borderNodes);
    this.checkBorderNodeLabel(borderNodes.get(0).getLabel(), BORDER_NODE_LABEL_TEXT_POSITION, BORDER_NODE_LABEL_TEXT_BOUNDS);
}
Also used : DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) NodeSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) LayoutConfiguratorRegistry(org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) ResizeEvent(org.eclipse.sirius.components.diagrams.events.ResizeEvent) Test(org.junit.jupiter.api.Test)

Aggregations

IDiagramEvent (org.eclipse.sirius.components.diagrams.events.IDiagramEvent)18 Test (org.junit.jupiter.api.Test)15 NodeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)14 DiagramLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData)13 ArrayList (java.util.ArrayList)7 Position (org.eclipse.sirius.components.diagrams.Position)7 ResizeEvent (org.eclipse.sirius.components.diagrams.events.ResizeEvent)7 SinglePositionEvent (org.eclipse.sirius.components.diagrams.events.SinglePositionEvent)7 LayoutConfiguratorRegistry (org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry)7 ImageSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider)7 NodePositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider)7 NodeSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider)7 Diagram (org.eclipse.sirius.components.diagrams.Diagram)4 Size (org.eclipse.sirius.components.diagrams.Size)3 MoveEvent (org.eclipse.sirius.components.diagrams.events.MoveEvent)3 TestDiagramCreationService (org.eclipse.sirius.components.diagrams.layout.services.TestDiagramCreationService)3 Path (java.nio.file.Path)2 Node (org.eclipse.sirius.components.diagrams.Node)2 JsonBasedEditingContext (org.eclipse.sirius.components.diagrams.tests.builder.JsonBasedEditingContext)2 IDiagramContext (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext)1