use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider 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));
}
use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider 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);
}
use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider in project sirius-components by eclipse-sirius.
the class NodePositionProviderTests method testSEResizeNodeEvent.
@Test
public void testSEResizeNodeEvent() {
Position nodePosition1 = Position.at(100, 100);
Position nodePosition2 = Position.at(200, 300);
Position nodePosition21 = Position.at(40, 40);
Size nodeSize = Size.of(200, 100);
Size nodeSize21 = Size.of(50, 50);
List<NodeLayoutData> nodes = new ArrayList<>();
// Create diagram with two children
DiagramLayoutData diagramLayoutData = this.createDiagramLayoutData();
NodeLayoutData nodeLayoutData = this.createNodeLayoutData(nodePosition1, nodeSize, diagramLayoutData, NodeType.NODE_RECTANGLE);
NodeLayoutData nodeLayoutData2 = this.createNodeLayoutData(nodePosition2, nodeSize, diagramLayoutData, NodeType.NODE_RECTANGLE);
diagramLayoutData.setChildrenNodes(nodes);
nodes.add(nodeLayoutData);
nodes.add(nodeLayoutData2);
// Add one child within the node 2
NodeLayoutData nodeLayoutData21 = this.createNodeLayoutData(nodePosition21, nodeSize21, nodeLayoutData2, NodeType.NODE_RECTANGLE);
nodeLayoutData2.setChildrenNodes(List.of(nodeLayoutData21));
Size newNode2Size = Size.of(190, 80);
// Since the resize is performed from the SE, the position should not change.
NodePositionProvider nodePositionProvider = new NodePositionProvider();
Optional<IDiagramEvent> optionalEvent = Optional.of(new ResizeEvent(nodeLayoutData2.getId(), Position.at(0, 0), newNode2Size));
Position newPosition1 = nodePositionProvider.getPosition(optionalEvent, nodeLayoutData);
Position newPosition2 = nodePositionProvider.getPosition(optionalEvent, nodeLayoutData2);
Position newPosition21 = nodePositionProvider.getPosition(optionalEvent, nodeLayoutData21);
assertThat(newPosition2).isEqualTo(nodePosition2);
assertThat(newPosition1).isEqualTo(nodePosition1);
assertThat(newPosition21).isEqualTo(nodePosition21);
}
use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider in project sirius-components by eclipse-sirius.
the class NodePositionProviderTests method testDiagramSeveralNewNodesAtOnce.
@Test
public void testDiagramSeveralNewNodesAtOnce() {
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);
// we pin the node so the next one gets positioned after
// this is what happens in the incremental layout
nodeLayoutData.setPinned(true);
assertThat(nextPosition).isEqualTo(ZERO_POSITION);
NodeLayoutData nodeLayoutData2 = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, diagramLayoutData, NodeType.NODE_RECTANGLE);
nodes.add(nodeLayoutData2);
nextPosition = nodePositionProvider.getPosition(optionalDiagramElementEvent, nodeLayoutData2);
assertThat(nextPosition).isEqualTo(Position.at(Double.valueOf(0), Double.valueOf(DEFAULT_NODE_SIZE.getHeight() + 30)));
}
use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider in project sirius-components by eclipse-sirius.
the class NodePositionProviderTests method testNodeNewNodesOneByOne.
@Test
public void testNodeNewNodesOneByOne() {
NodePositionProvider nodePositionProvider = new NodePositionProvider();
DiagramLayoutData diagramLayoutData = this.createDiagramLayoutData();
NodeLayoutData parentNodeLayoutData = this.createNodeLayoutData(ZERO_POSITION, DEFAULT_NODE_SIZE, diagramLayoutData, NodeType.NODE_RECTANGLE);
diagramLayoutData.setChildrenNodes(List.of(parentNodeLayoutData));
List<NodeLayoutData> nodes = new ArrayList<>();
parentNodeLayoutData.setChildrenNodes(nodes);
Optional<IDiagramEvent> optionalEvent = Optional.of(new SinglePositionEvent(ZERO_POSITION));
NodeLayoutData firstChild = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, parentNodeLayoutData, NodeType.NODE_RECTANGLE);
nodes.add(firstChild);
Position nextPosition = nodePositionProvider.getPosition(optionalEvent, firstChild);
firstChild.setPosition(nextPosition);
assertThat(nextPosition).isEqualTo(ZERO_POSITION);
NodeLayoutData secondChild = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, parentNodeLayoutData, NodeType.NODE_RECTANGLE);
nodes.add(secondChild);
nextPosition = nodePositionProvider.getPosition(optionalEvent, secondChild);
secondChild.setPosition(nextPosition);
assertThat(nextPosition).isEqualTo(ZERO_POSITION);
// Test creation of a new node at a given position within parent (creation tool)
nodePositionProvider = new NodePositionProvider();
NodeLayoutData thirdChild = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, parentNodeLayoutData, NodeType.NODE_RECTANGLE);
Position startingPosition = Position.at(START_X_WITHIN_PARENT, START_Y_WITHIN_PARENT);
nodes.add(thirdChild);
nextPosition = nodePositionProvider.getPosition(Optional.of(new SinglePositionEvent(startingPosition)), thirdChild);
assertThat(nextPosition).isEqualTo(Position.at(START_X_WITHIN_PARENT, START_Y_WITHIN_PARENT));
// Test creation of a new node at a given position outside parent (creation tool)
NodeLayoutData fourthChild = this.createNodeLayoutData(Position.UNDEFINED, DEFAULT_NODE_SIZE, parentNodeLayoutData, NodeType.NODE_RECTANGLE);
Position startingPositionOutside = Position.at(START_X_OUTSIDE_PARENT, START_Y_OUTSIDE_PARENT);
nodes.add(fourthChild);
nodePositionProvider = new NodePositionProvider();
nextPosition = nodePositionProvider.getPosition(Optional.of(new SinglePositionEvent(startingPositionOutside)), fourthChild);
assertThat(nextPosition).isEqualTo(nodePositionProvider.getDefaultPosition(fourthChild));
}
Aggregations