Search in sources :

Example 1 with EdgeElementProps

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);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Position(org.eclipse.sirius.components.diagrams.Position) Element(org.eclipse.sirius.components.representations.Element) ArrayList(java.util.ArrayList) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) Fragment(org.eclipse.sirius.components.representations.Fragment) EdgeElementProps(org.eclipse.sirius.components.diagrams.elements.EdgeElementProps) DiagramRenderingCache(org.eclipse.sirius.components.diagrams.renderer.DiagramRenderingCache) SynchronizationPolicy(org.eclipse.sirius.components.diagrams.description.SynchronizationPolicy) Ratio(org.eclipse.sirius.components.diagrams.Ratio) FragmentProps(org.eclipse.sirius.components.representations.FragmentProps) EdgeStyle(org.eclipse.sirius.components.diagrams.EdgeStyle)

Aggregations

ArrayList (java.util.ArrayList)1 EdgeStyle (org.eclipse.sirius.components.diagrams.EdgeStyle)1 Position (org.eclipse.sirius.components.diagrams.Position)1 Ratio (org.eclipse.sirius.components.diagrams.Ratio)1 EdgeDescription (org.eclipse.sirius.components.diagrams.description.EdgeDescription)1 SynchronizationPolicy (org.eclipse.sirius.components.diagrams.description.SynchronizationPolicy)1 EdgeElementProps (org.eclipse.sirius.components.diagrams.elements.EdgeElementProps)1 DiagramRenderingCache (org.eclipse.sirius.components.diagrams.renderer.DiagramRenderingCache)1 Element (org.eclipse.sirius.components.representations.Element)1 Fragment (org.eclipse.sirius.components.representations.Fragment)1 FragmentProps (org.eclipse.sirius.components.representations.FragmentProps)1 VariableManager (org.eclipse.sirius.components.representations.VariableManager)1