Search in sources :

Example 1 with MoveEvent

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
}
Also used : Position(org.eclipse.sirius.components.diagrams.Position) MoveEvent(org.eclipse.sirius.components.diagrams.events.MoveEvent)

Example 2 with MoveEvent

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()));
            }
        }
    }
}
Also used : LabelLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData) MoveEvent(org.eclipse.sirius.components.diagrams.events.MoveEvent) ResizeEvent(org.eclipse.sirius.components.diagrams.events.ResizeEvent)

Example 3 with MoveEvent

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

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));
    }
}
Also used : UpdateNodePositionSuccessPayload(org.eclipse.sirius.components.collaborative.diagrams.dto.UpdateNodePositionSuccessPayload) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Position(org.eclipse.sirius.components.diagrams.Position) Node(org.eclipse.sirius.components.diagrams.Node) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) MoveEvent(org.eclipse.sirius.components.diagrams.events.MoveEvent)

Example 5 with MoveEvent

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);
}
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) MoveEvent(org.eclipse.sirius.components.diagrams.events.MoveEvent) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Test(org.junit.jupiter.api.Test)

Aggregations

MoveEvent (org.eclipse.sirius.components.diagrams.events.MoveEvent)6 Position (org.eclipse.sirius.components.diagrams.Position)3 IDiagramEvent (org.eclipse.sirius.components.diagrams.events.IDiagramEvent)3 DiagramLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData)3 NodeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)3 Test (org.junit.jupiter.api.Test)3 LayoutConfiguratorRegistry (org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry)2 ImageSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider)2 NodeSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider)2 ArrayList (java.util.ArrayList)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 UpdateNodePositionSuccessPayload (org.eclipse.sirius.components.collaborative.diagrams.dto.UpdateNodePositionSuccessPayload)1 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)1 Node (org.eclipse.sirius.components.diagrams.Node)1 ResizeEvent (org.eclipse.sirius.components.diagrams.events.ResizeEvent)1 LabelLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.LabelLayoutData)1 NodePositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider)1