Search in sources :

Example 1 with FragmentProps

use of org.eclipse.sirius.components.representations.FragmentProps in project sirius-components by eclipse-sirius.

the class PageComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    PageDescription pageDescription = this.props.getPageDescription();
    List<?> semanticElements = pageDescription.getSemanticElementsProvider().apply(variableManager);
    List<Element> children = new ArrayList<>(semanticElements.size());
    for (Object semanticElement : semanticElements) {
        VariableManager pageVariableManager = variableManager.createChild();
        pageVariableManager.put(VariableManager.SELF, semanticElement);
        String id = pageDescription.getIdProvider().apply(pageVariableManager);
        String label = pageDescription.getLabelProvider().apply(pageVariableManager);
        // @formatter:off
        List<Element> groupComponents = pageDescription.getGroupDescriptions().stream().map(groupDescription -> {
            GroupComponentProps groupComponentProps = new GroupComponentProps(pageVariableManager, groupDescription);
            return new Element(GroupComponent.class, groupComponentProps);
        }).collect(Collectors.toList());
        PageElementProps pageElementProps = PageElementProps.newPageElementProps(id).label(label).children(groupComponents).build();
        Element pageElement = new Element(PageElementProps.TYPE, pageElementProps);
        // @formatter:on
        children.add(pageElement);
    }
    FragmentProps fragmentProps = new FragmentProps(children);
    return new Fragment(fragmentProps);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Objects(java.util.Objects) List(java.util.List) Fragment(org.eclipse.sirius.components.representations.Fragment) PageDescription(org.eclipse.sirius.components.forms.description.PageDescription) PageElementProps(org.eclipse.sirius.components.forms.elements.PageElementProps) FragmentProps(org.eclipse.sirius.components.representations.FragmentProps) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Collectors(java.util.stream.Collectors) Element(org.eclipse.sirius.components.representations.Element) IComponent(org.eclipse.sirius.components.representations.IComponent) ArrayList(java.util.ArrayList) Element(org.eclipse.sirius.components.representations.Element) ArrayList(java.util.ArrayList) PageDescription(org.eclipse.sirius.components.forms.description.PageDescription) Fragment(org.eclipse.sirius.components.representations.Fragment) PageElementProps(org.eclipse.sirius.components.forms.elements.PageElementProps) FragmentProps(org.eclipse.sirius.components.representations.FragmentProps)

Example 2 with FragmentProps

use of org.eclipse.sirius.components.representations.FragmentProps 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)

Example 3 with FragmentProps

use of org.eclipse.sirius.components.representations.FragmentProps in project sirius-components by eclipse-sirius.

the class NodeComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    NodeDescription nodeDescription = this.props.getNodeDescription();
    INodesRequestor nodesRequestor = this.props.getNodesRequestor();
    DiagramRenderingCache cache = this.props.getCache();
    List<Element> children = new ArrayList<>();
    List<?> semanticElements = nodeDescription.getSemanticElementsProvider().apply(variableManager);
    for (Object semanticElement : semanticElements) {
        VariableManager nodeVariableManager = variableManager.createChild();
        nodeVariableManager.put(VariableManager.SELF, semanticElement);
        String targetObjectId = nodeDescription.getTargetObjectIdProvider().apply(nodeVariableManager);
        var optionalPreviousNode = nodesRequestor.getByTargetObjectId(targetObjectId);
        if (this.shouldRender(targetObjectId, optionalPreviousNode)) {
            Element nodeElement = this.doRender(nodeVariableManager, targetObjectId, optionalPreviousNode);
            children.add(nodeElement);
            cache.put(nodeDescription.getId(), nodeElement);
            cache.put(semanticElement, nodeElement);
        }
    }
    FragmentProps fragmentProps = new FragmentProps(children);
    return new Fragment(fragmentProps);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Element(org.eclipse.sirius.components.representations.Element) ArrayList(java.util.ArrayList) Fragment(org.eclipse.sirius.components.representations.Fragment) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) DiagramRenderingCache(org.eclipse.sirius.components.diagrams.renderer.DiagramRenderingCache) FragmentProps(org.eclipse.sirius.components.representations.FragmentProps)

Example 4 with FragmentProps

use of org.eclipse.sirius.components.representations.FragmentProps in project sirius-components by eclipse-sirius.

the class GroupComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    GroupDescription groupDescription = this.props.getGroupDescription();
    WidgetIdCounter widgetIdCounter = new WidgetIdCounter();
    List<?> semanticElements = groupDescription.getSemanticElementsProvider().apply(variableManager);
    List<Element> children = new ArrayList<>(semanticElements.size());
    for (Object semanticElement : semanticElements) {
        VariableManager groupVariableManager = variableManager.createChild();
        groupVariableManager.put(VariableManager.SELF, semanticElement);
        groupVariableManager.put(WIDGET_ID_PROVIDER_COUNTER, widgetIdCounter);
        String id = groupDescription.getIdProvider().apply(groupVariableManager);
        String label = groupDescription.getLabelProvider().apply(groupVariableManager);
        // @formatter:off
        List<Element> groupChildren = new ArrayList<>();
        List<AbstractControlDescription> controlDescriptions = groupDescription.getControlDescriptions();
        for (AbstractControlDescription controlDescription : controlDescriptions) {
            if (controlDescription instanceof AbstractWidgetDescription) {
                AbstractWidgetDescription widgetDescription = (AbstractWidgetDescription) controlDescription;
                WidgetComponentProps widgetComponentProps = new WidgetComponentProps(groupVariableManager, widgetDescription);
                groupChildren.add(new Element(WidgetComponent.class, widgetComponentProps));
            } else if (controlDescription instanceof ForDescription) {
                ForDescription forDescription = (ForDescription) controlDescription;
                ForComponentProps forComponentProps = new ForComponentProps(groupVariableManager, forDescription);
                groupChildren.add(new Element(ForComponent.class, forComponentProps));
            }
        }
        GroupElementProps groupElementProps = GroupElementProps.newGroupElementProps(id).label(label).children(groupChildren).build();
        Element groupElement = new Element(GroupElementProps.TYPE, groupElementProps);
        // @formatter:on
        children.add(groupElement);
    }
    FragmentProps fragmentProps = new FragmentProps(children);
    return new Fragment(fragmentProps);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) GroupElementProps(org.eclipse.sirius.components.forms.elements.GroupElementProps) Element(org.eclipse.sirius.components.representations.Element) ArrayList(java.util.ArrayList) AbstractWidgetDescription(org.eclipse.sirius.components.forms.description.AbstractWidgetDescription) Fragment(org.eclipse.sirius.components.representations.Fragment) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) AbstractControlDescription(org.eclipse.sirius.components.forms.description.AbstractControlDescription) FragmentProps(org.eclipse.sirius.components.representations.FragmentProps) ForDescription(org.eclipse.sirius.components.forms.description.ForDescription)

Example 5 with FragmentProps

use of org.eclipse.sirius.components.representations.FragmentProps in project sirius-components by eclipse-sirius.

the class ForComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    ForDescription forDescription = this.props.getForDescription();
    // @formatter:off
    List<?> objects = forDescription.getIterableProvider().apply(variableManager);
    List<Element> children = new ArrayList<>(objects.size());
    for (Object object : objects) {
        VariableManager childVariableManager = variableManager.createChild();
        childVariableManager.put(forDescription.getIterator(), object);
        List<Element> forChildren = new ArrayList<>();
        List<IfDescription> ifDescriptions = forDescription.getIfDescriptions();
        for (IfDescription ifDescription : ifDescriptions) {
            IfComponentProps ifComponentProps = new IfComponentProps(childVariableManager, ifDescription);
            forChildren.add(new Element(IfComponent.class, ifComponentProps));
        }
        FragmentProps fragmentProps = new FragmentProps(forChildren);
        children.add(new Fragment(fragmentProps));
    }
    // @formatter:on
    FragmentProps fragmentProps = new FragmentProps(children);
    return new Fragment(fragmentProps);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Element(org.eclipse.sirius.components.representations.Element) ArrayList(java.util.ArrayList) Fragment(org.eclipse.sirius.components.representations.Fragment) FragmentProps(org.eclipse.sirius.components.representations.FragmentProps) ForDescription(org.eclipse.sirius.components.forms.description.ForDescription) IfDescription(org.eclipse.sirius.components.forms.description.IfDescription)

Aggregations

ArrayList (java.util.ArrayList)6 Element (org.eclipse.sirius.components.representations.Element)6 Fragment (org.eclipse.sirius.components.representations.Fragment)6 FragmentProps (org.eclipse.sirius.components.representations.FragmentProps)6 VariableManager (org.eclipse.sirius.components.representations.VariableManager)6 DiagramRenderingCache (org.eclipse.sirius.components.diagrams.renderer.DiagramRenderingCache)2 AbstractWidgetDescription (org.eclipse.sirius.components.forms.description.AbstractWidgetDescription)2 ForDescription (org.eclipse.sirius.components.forms.description.ForDescription)2 List (java.util.List)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)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 NodeDescription (org.eclipse.sirius.components.diagrams.description.NodeDescription)1 SynchronizationPolicy (org.eclipse.sirius.components.diagrams.description.SynchronizationPolicy)1 EdgeElementProps (org.eclipse.sirius.components.diagrams.elements.EdgeElementProps)1 AbstractControlDescription (org.eclipse.sirius.components.forms.description.AbstractControlDescription)1