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