Search in sources :

Example 1 with GroupElementProps

use of org.eclipse.sirius.components.forms.elements.GroupElementProps 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)

Aggregations

ArrayList (java.util.ArrayList)1 AbstractControlDescription (org.eclipse.sirius.components.forms.description.AbstractControlDescription)1 AbstractWidgetDescription (org.eclipse.sirius.components.forms.description.AbstractWidgetDescription)1 ForDescription (org.eclipse.sirius.components.forms.description.ForDescription)1 GroupDescription (org.eclipse.sirius.components.forms.description.GroupDescription)1 GroupElementProps (org.eclipse.sirius.components.forms.elements.GroupElementProps)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