use of org.eclipse.sirius.components.diagrams.events.ResizeEvent in project sirius-components by eclipse-sirius.
the class UpdateNodeBoundsEventHandler method handleUpdateNodeBounds.
private void handleUpdateNodeBounds(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IDiagramContext diagramContext, UpdateNodeBoundsInput diagramInput) {
// @formatter:off
Position newPosition = Position.newPosition().x(diagramInput.getNewPositionX()).y(diagramInput.getNewPositionY()).build();
Size newSize = Size.newSize().width(diagramInput.getNewWidth()).height(diagramInput.getNewHeight()).build();
// @formatter:on
Optional<Node> optionalNode = this.diagramQueryService.findNodeById(diagramContext.getDiagram(), diagramInput.getDiagramElementId());
if (optionalNode.isPresent()) {
Position oldPosition = optionalNode.get().getPosition();
// @formatter:off
Position delta = Position.newPosition().x(oldPosition.getX() - newPosition.getX()).y(oldPosition.getY() - newPosition.getY()).build();
// @formatter:on
diagramContext.setDiagramEvent(new ResizeEvent(diagramInput.getDiagramElementId(), delta, newSize));
payloadSink.tryEmitValue(new UpdateNodeBoundsSuccessPayload(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.ResizeEvent in project sirius-components by eclipse-sirius.
the class IncrementalLayoutEngine method updateBorderNodeAccordingParentResize.
/**
* Move the border node along the side according to the parent Size changes.
*/
private void updateBorderNodeAccordingParentResize(Optional<IDiagramEvent> optionalDiagramElementEvent, Bounds initialNodeBounds, Bounds newNodeBounds, List<BorderNodesOnSide> borderNodesPerSideList, String parentId) {
// @formatter:off
boolean isParentRectangleResized = optionalDiagramElementEvent.filter(ResizeEvent.class::isInstance).map(ResizeEvent.class::cast).map(ResizeEvent::getNodeId).filter(parentId::equals).isPresent();
if (isParentRectangleResized && !initialNodeBounds.equals(newNodeBounds)) {
EnumMap<RectangleSide, Double> sideHomotheticRatio = this.getHomotheticRatio(initialNodeBounds.getSize(), newNodeBounds.getSize());
Size initialSize = initialNodeBounds.getSize();
Size newSize = newNodeBounds.getSize();
for (BorderNodesOnSide borderNodesOnSide : borderNodesPerSideList) {
RectangleSide side = borderNodesOnSide.getSide();
List<NodeLayoutData> borderNodes = borderNodesOnSide.getBorderNodes();
double homotheticRatio = sideHomotheticRatio.get(side);
for (NodeLayoutData borderNodeLayoutData : borderNodes) {
// The border node position is done in the parent node coordinate system
Position position = borderNodeLayoutData.getPosition();
Size size = borderNodeLayoutData.getSize();
if (RectangleSide.NORTH.equals(side)) {
borderNodeLayoutData.setPosition(Position.at((position.getX() + size.getWidth() / 2) * homotheticRatio - size.getWidth() / 2, position.getY()));
} else if (RectangleSide.SOUTH.equals(side)) {
double dySouthShift = newSize.getHeight() - initialSize.getHeight();
borderNodeLayoutData.setPosition(Position.at((position.getX() + size.getWidth() / 2) * homotheticRatio - size.getWidth() / 2, position.getY() + dySouthShift));
} else if (RectangleSide.WEST.equals(side)) {
borderNodeLayoutData.setPosition(Position.at(position.getX(), (position.getY() + size.getHeight() / 2) * homotheticRatio - size.getHeight() / 2));
} else if (RectangleSide.EAST.equals(side)) {
double dxEastShift = newSize.getWidth() - initialSize.getWidth();
borderNodeLayoutData.setPosition(Position.at(position.getX() + dxEastShift, (position.getY() + size.getHeight() / 2) * homotheticRatio - size.getHeight() / 2));
}
}
}
}
}
use of org.eclipse.sirius.components.diagrams.events.ResizeEvent 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.ResizeEvent 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);
}
use of org.eclipse.sirius.components.diagrams.events.ResizeEvent in project sirius-components by eclipse-sirius.
the class NodeSizeProvider method getSize.
/**
* Provides the new {@link Size} of the given node. If the node size is no need to be updated, the current size is
* returned. If the provided {@link NodeLayoutData} is resized by the {@link ResizeEvent}, we mark it as
* resizedByUser.
*
* @param optionalDiagramElementEvent
* The event which is currently taken into account
* @param node
* the {@link NodeLayoutData} for which we want to retrieve the new size.
* @return the new {@link Size} if updated or the current one.
*/
public Size getSize(Optional<IDiagramEvent> optionalDiagramElementEvent, NodeLayoutData node, ISiriusWebLayoutConfigurator layoutConfigurator) {
Size size;
if (this.isRelevantResizeEvent(optionalDiagramElementEvent, node)) {
node.setResizedByUser(true);
// @formatter:off
size = optionalDiagramElementEvent.filter(ResizeEvent.class::isInstance).map(ResizeEvent.class::cast).map(ResizeEvent::getNewSize).orElse(Size.UNDEFINED);
// @formatter:on
} else if (this.isAlreadySized(node)) {
size = node.getSize();
} else {
size = this.getInitialSize(node, layoutConfigurator);
}
return size;
}
Aggregations