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);
}
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));
}
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);
}
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);
}
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);
}
Aggregations