use of org.eclipse.sirius.components.diagrams.events.MoveEvent in project sirius-components by eclipse-sirius.
the class IncrementalLayoutEngine method updateBorderNodePosition.
private void updateBorderNodePosition(Optional<IDiagramEvent> optionalDiagramElementEvent, NodeLayoutData nodeLayoutData) {
// @formatter:off
optionalDiagramElementEvent.filter(MoveEvent.class::isInstance).map(MoveEvent.class::cast).map(MoveEvent::getNodeId).filter(nodeLayoutData.getId()::equals).ifPresent(nodeId -> {
Position position = this.nodePositionProvider.getPosition(optionalDiagramElementEvent, nodeLayoutData);
if (!position.equals(nodeLayoutData.getPosition())) {
nodeLayoutData.setPosition(position);
nodeLayoutData.setChanged(true);
nodeLayoutData.setPinned(true);
}
});
// @formatter:on
}
use of org.eclipse.sirius.components.diagrams.events.MoveEvent in project sirius-components by eclipse-sirius.
the class BorderNodeLabelPositionProvider method updateLabelPosition.
public void updateLabelPosition(Optional<IDiagramEvent> optionalDiagramElementEvent, RectangleSide side, NodeLayoutData borderNodeLayoutData) {
LabelLayoutData label = borderNodeLayoutData.getLabel();
if (label != null) {
// @formatter:off
boolean isBorderNodeMoved = optionalDiagramElementEvent.filter(MoveEvent.class::isInstance).map(MoveEvent.class::cast).map(MoveEvent::getNodeId).filter(borderNodeLayoutData.getId()::equals).isPresent();
boolean isBorderNodeResized = optionalDiagramElementEvent.filter(ResizeEvent.class::isInstance).map(ResizeEvent.class::cast).map(ResizeEvent::getNodeId).filter(borderNodeLayoutData.getId()::equals).isPresent();
if (borderNodeLayoutData.getLabel().getPosition().getX() == -1 || isBorderNodeMoved || isBorderNodeResized) {
if (RectangleSide.NORTH.equals(side)) {
label.setPosition(Position.at(-label.getTextBounds().getSize().getWidth(), -label.getTextBounds().getSize().getHeight()));
} else if (RectangleSide.EAST.equals(side)) {
label.setPosition(Position.at(borderNodeLayoutData.getSize().getWidth(), borderNodeLayoutData.getSize().getHeight()));
} else {
label.setPosition(Position.at(-label.getTextBounds().getSize().getWidth(), borderNodeLayoutData.getSize().getHeight()));
}
}
}
}
use of org.eclipse.sirius.components.diagrams.events.MoveEvent 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.MoveEvent in project sirius-components by eclipse-sirius.
the class UpdateNodePositionEventHandler method handleUpdateNodePosition.
private void handleUpdateNodePosition(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IDiagramContext diagramContext, UpdateNodePositionInput diagramInput) {
Position newPosition = Position.at(diagramInput.getNewPositionX(), diagramInput.getNewPositionY());
Optional<Node> optionalNode = this.diagramQueryService.findNodeById(diagramContext.getDiagram(), diagramInput.getDiagramElementId());
if (optionalNode.isPresent()) {
diagramContext.setDiagramEvent(new MoveEvent(diagramInput.getDiagramElementId(), newPosition));
payloadSink.tryEmitValue(new UpdateNodePositionSuccessPayload(diagramInput.getId(), diagramContext.getDiagram()));
changeDescriptionSink.tryEmitNext(new ChangeDescription(DiagramChangeKind.DIAGRAM_LAYOUT_CHANGE, diagramInput.getRepresentationId(), diagramInput));
} else {
String message = this.messageService.nodeNotFound(String.valueOf(diagramInput.getDiagramElementId()));
payloadSink.tryEmitValue(new ErrorPayload(diagramInput.getId(), message));
changeDescriptionSink.tryEmitNext(new ChangeDescription(ChangeKind.NOTHING, diagramInput.getRepresentationId(), diagramInput));
}
}
use of org.eclipse.sirius.components.diagrams.events.MoveEvent in project sirius-components by eclipse-sirius.
the class BorderNodePositionTests method testMoveBorderNodeEvent.
@Test
public void testMoveBorderNodeEvent() {
DiagramLayoutData initializeDiagram = this.initializeDiagram();
NodeLayoutData northBorderNode = initializeDiagram.getChildrenNodes().get(0).getBorderNodes().get(0);
NodeLayoutData eastBorderNode = initializeDiagram.getChildrenNodes().get(0).getBorderNodes().get(3);
NodeSizeProvider nodeSizeProvider = new NodeSizeProvider(new ImageSizeProvider());
IncrementalLayoutEngine incrementalLayoutEngine = new IncrementalLayoutEngine(nodeSizeProvider);
// move slightly the north border node so that the incremental layout updates the label position
Optional<IDiagramEvent> resizeEvent = Optional.of(new MoveEvent(northBorderNode.getId(), Position.at(northBorderNode.getPosition().getX() + 1, northBorderNode.getPosition().getY())));
incrementalLayoutEngine.layout(resizeEvent, initializeDiagram, new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator());
this.checkBorderNodeLabel(northBorderNode.getLabel(), Position.at(-100, -BORDER_NODE_LABEL_TEXT_BOUNDS.getSize().getHeight()), BORDER_NODE_LABEL_TEXT_BOUNDS);
// move slightly the east border node so that the incremental layout updates the label position
resizeEvent = Optional.of(new MoveEvent(eastBorderNode.getId(), Position.at(eastBorderNode.getPosition().getX() + 1, eastBorderNode.getPosition().getY())));
incrementalLayoutEngine.layout(resizeEvent, initializeDiagram, new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator());
this.checkBorderNodeLabel(eastBorderNode.getLabel(), Position.at(DEFAULT_BORDER_NODE_SIZE.getWidth(), DEFAULT_BORDER_NODE_SIZE.getHeight()), BORDER_NODE_LABEL_TEXT_BOUNDS);
}
Aggregations