use of org.eclipse.sirius.components.diagrams.elements.EdgeElementProps in project sirius-components by eclipse-sirius.
the class EdgeComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
EdgeDescription edgeDescription = this.props.getEdgeDescription();
IEdgesRequestor edgesRequestor = this.props.getEdgesRequestor();
DiagramRenderingCache cache = this.props.getCache();
List<Element> children = new ArrayList<>();
// @formatter:off
boolean hasCandidates = this.hasNodeCandidates(edgeDescription.getSourceNodeDescriptions(), cache) && this.hasNodeCandidates(edgeDescription.getTargetNodeDescriptions(), cache);
if (hasCandidates) {
VariableManager semanticElementsVariableManager = new VariableManager();
variableManager.getVariables().forEach(semanticElementsVariableManager::put);
semanticElementsVariableManager.put(DiagramDescription.CACHE, cache);
List<?> semanticElements = edgeDescription.getSemanticElementsProvider().apply(semanticElementsVariableManager);
int count = 0;
for (Object semanticElement : semanticElements) {
VariableManager edgeVariableManager = variableManager.createChild();
edgeVariableManager.put(VariableManager.SELF, semanticElement);
edgeVariableManager.put(DiagramDescription.CACHE, cache);
String targetObjectId = edgeDescription.getTargetObjectIdProvider().apply(edgeVariableManager);
String targetObjectKind = edgeDescription.getTargetObjectKindProvider().apply(edgeVariableManager);
String targetObjectLabel = edgeDescription.getTargetObjectLabelProvider().apply(edgeVariableManager);
List<Element> sourceNodes = edgeDescription.getSourceNodesProvider().apply(edgeVariableManager);
if (!sourceNodes.isEmpty()) {
List<Element> targetNodes = edgeDescription.getTargetNodesProvider().apply(edgeVariableManager);
for (Element sourceNode : sourceNodes) {
for (Element targetNode : targetNodes) {
String id = this.computeEdgeId(edgeDescription, sourceNode, targetNode, count);
var optionalPreviousEdge = edgesRequestor.getById(id);
var edgeInstanceVariableManager = edgeVariableManager.createChild();
edgeInstanceVariableManager.put(EdgeDescription.SEMANTIC_EDGE_SOURCE, cache.getNodeToObject().get(sourceNode));
edgeInstanceVariableManager.put(EdgeDescription.SEMANTIC_EDGE_TARGET, cache.getNodeToObject().get(targetNode));
SynchronizationPolicy synchronizationPolicy = edgeDescription.getSynchronizationPolicy();
boolean shouldRender = synchronizationPolicy == SynchronizationPolicy.SYNCHRONIZED || (synchronizationPolicy == SynchronizationPolicy.UNSYNCHRONIZED && optionalPreviousEdge.isPresent());
if (shouldRender) {
EdgeStyle style = edgeDescription.getStyleProvider().apply(edgeInstanceVariableManager);
String sourceId = this.getId(sourceNode);
String targetId = this.getId(targetNode);
// @formatter:off
String edgeType = optionalPreviousEdge.map(Edge::getType).orElse(// $NON-NLS-1$
"edge:straight");
List<Position> routingPoints = optionalPreviousEdge.map(Edge::getRoutingPoints).orElse(List.of());
Ratio sourceAnchorRelativePosition = optionalPreviousEdge.map(Edge::getSourceAnchorRelativePosition).orElse(Ratio.UNDEFINED);
Ratio targetAnchorRelativePosition = optionalPreviousEdge.map(Edge::getTargetAnchorRelativePosition).orElse(Ratio.UNDEFINED);
List<Element> labelChildren = this.getLabelsChildren(edgeDescription, edgeInstanceVariableManager, optionalPreviousEdge, id, routingPoints);
EdgeElementProps edgeElementProps = EdgeElementProps.newEdgeElementProps(id).type(edgeType).descriptionId(edgeDescription.getId()).targetObjectId(targetObjectId).targetObjectKind(targetObjectKind).targetObjectLabel(targetObjectLabel).sourceId(sourceId).targetId(targetId).style(style).routingPoints(routingPoints).sourceAnchorRelativePosition(sourceAnchorRelativePosition).targetAnchorRelativePosition(targetAnchorRelativePosition).children(labelChildren).build();
// @formatter:on
Element edgeElement = new Element(EdgeElementProps.TYPE, edgeElementProps);
children.add(edgeElement);
count++;
}
}
}
}
}
}
FragmentProps fragmentProps = new FragmentProps(children);
return new Fragment(fragmentProps);
}
Aggregations