Search in sources :

Example 1 with DoublePositionEvent

use of org.eclipse.sirius.components.diagrams.events.DoublePositionEvent in project sirius-components by eclipse-sirius.

the class IncrementalLayoutEngine method layoutEdge.

private void layoutEdge(Optional<IDiagramEvent> optionalDiagramElementEvent, EdgeLayoutData edge) {
    // @formatter:off
    optionalDiagramElementEvent.filter(DoublePositionEvent.class::isInstance).map(DoublePositionEvent.class::cast).ifPresent(doublePositionEvent -> {
        Ratio edgeSourceAnchorRelativePosition = this.getPositionProportionOfEdgeEndAbsolutePosition(edge.getSource(), doublePositionEvent.getSourcePosition());
        Ratio edgeTargetAnchorRelativePosition = this.getPositionProportionOfEdgeEndAbsolutePosition(edge.getTarget(), doublePositionEvent.getTargetPosition());
        edge.setSourceAnchorRelativePosition(edgeSourceAnchorRelativePosition);
        edge.setTargetAnchorRelativePosition(edgeTargetAnchorRelativePosition);
    });
    // @formatter:on
    // recompute the edge routing points
    edge.setRoutingPoints(this.edgeRoutingPointsProvider.getRoutingPoints(edge));
    // recompute edge labels
    if (edge.getCenterLabel() != null) {
        edge.getCenterLabel().setPosition(this.edgeLabelPositionProvider.getCenterPosition(edge, edge.getCenterLabel()));
    }
}
Also used : Ratio(org.eclipse.sirius.components.diagrams.Ratio) DoublePositionEvent(org.eclipse.sirius.components.diagrams.events.DoublePositionEvent)

Example 2 with DoublePositionEvent

use of org.eclipse.sirius.components.diagrams.events.DoublePositionEvent in project sirius-components by eclipse-sirius.

the class InvokeSingleClickOnTwoDiagramElementsToolEventHandler method executeTool.

private IStatus executeTool(IEditingContext editingContext, IDiagramContext diagramContext, String sourceNodeId, String targetNodeId, SingleClickOnTwoDiagramElementsTool tool, Position sourcePosition, Position targetPosition) {
    // $NON-NLS-1$
    IStatus result = new Failure("");
    Diagram diagram = diagramContext.getDiagram();
    Optional<Node> sourceNode = this.diagramQueryService.findNodeById(diagram, sourceNodeId);
    Optional<Node> targetNode = this.diagramQueryService.findNodeById(diagram, targetNodeId);
    Optional<Object> source = Optional.empty();
    Optional<Object> target = Optional.empty();
    if (sourceNode.isPresent() && targetNode.isPresent()) {
        source = this.objectService.getObject(editingContext, sourceNode.get().getTargetObjectId());
        target = this.objectService.getObject(editingContext, targetNode.get().getTargetObjectId());
    }
    if (source.isPresent() && target.isPresent()) {
        VariableManager variableManager = new VariableManager();
        variableManager.put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
        variableManager.put(IEditingContext.EDITING_CONTEXT, editingContext);
        variableManager.put(Environment.ENVIRONMENT, new Environment(Environment.SIRIUS_COMPONENTS));
        variableManager.put(EdgeDescription.SEMANTIC_EDGE_SOURCE, source.get());
        variableManager.put(EdgeDescription.SEMANTIC_EDGE_TARGET, target.get());
        result = tool.getHandler().apply(variableManager);
        diagramContext.setDiagramEvent(new DoublePositionEvent(sourcePosition, targetPosition));
    }
    return result;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) IStatus(org.eclipse.sirius.components.representations.IStatus) Node(org.eclipse.sirius.components.diagrams.Node) Environment(org.eclipse.sirius.components.core.api.Environment) DoublePositionEvent(org.eclipse.sirius.components.diagrams.events.DoublePositionEvent) Failure(org.eclipse.sirius.components.representations.Failure) Diagram(org.eclipse.sirius.components.diagrams.Diagram)

Aggregations

DoublePositionEvent (org.eclipse.sirius.components.diagrams.events.DoublePositionEvent)2 Environment (org.eclipse.sirius.components.core.api.Environment)1 Diagram (org.eclipse.sirius.components.diagrams.Diagram)1 Node (org.eclipse.sirius.components.diagrams.Node)1 Ratio (org.eclipse.sirius.components.diagrams.Ratio)1 Failure (org.eclipse.sirius.components.representations.Failure)1 IStatus (org.eclipse.sirius.components.representations.IStatus)1 VariableManager (org.eclipse.sirius.components.representations.VariableManager)1