Search in sources :

Example 1 with ListElementProps

use of org.eclipse.sirius.components.forms.elements.ListElementProps in project sirius-components by eclipse-sirius.

the class ListComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    ListDescription listDescription = this.props.getListDescription();
    String id = listDescription.getIdProvider().apply(variableManager);
    String label = listDescription.getLabelProvider().apply(variableManager);
    List<?> itemCandidates = listDescription.getItemsProvider().apply(variableManager);
    List<Element> children = List.of(new Element(DiagnosticComponent.class, new DiagnosticComponentProps(listDescription, variableManager)));
    List<ListItem> items = new ArrayList<>(itemCandidates.size());
    for (Object itemCandidate : itemCandidates) {
        VariableManager itemVariableManager = variableManager.createChild();
        itemVariableManager.put(CANDIDATE_VARIABLE, itemCandidate);
        String itemId = listDescription.getItemIdProvider().apply(itemVariableManager);
        String itemLabel = listDescription.getItemLabelProvider().apply(itemVariableManager);
        String itemKind = listDescription.getItemKindProvider().apply(itemVariableManager);
        String itemImageURL = listDescription.getItemImageURLProvider().apply(itemVariableManager);
        boolean isItemDeletable = listDescription.getItemDeletableProvider().apply(itemVariableManager);
        Function<VariableManager, IStatus> genericHandler = listDescription.getItemDeleteHandlerProvider();
        Supplier<IStatus> specializedHandler = () -> {
            return genericHandler.apply(itemVariableManager);
        };
        // @formatter:off
        ListItem item = ListItem.newListItem(itemId).label(itemLabel).kind(itemKind).imageURL(itemImageURL).deletable(isItemDeletable).deleteHandler(specializedHandler).build();
        // @formatter:on
        items.add(item);
    }
    // @formatter:off
    ListElementProps listElementProps = ListElementProps.newListElementProps(id).label(label).items(items).children(children).build();
    return new Element(ListElementProps.TYPE, listElementProps);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) IStatus(org.eclipse.sirius.components.representations.IStatus) Element(org.eclipse.sirius.components.representations.Element) DiagnosticComponentProps(org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps) ArrayList(java.util.ArrayList) ListElementProps(org.eclipse.sirius.components.forms.elements.ListElementProps) ListDescription(org.eclipse.sirius.components.forms.description.ListDescription) DiagnosticComponent(org.eclipse.sirius.components.forms.validation.DiagnosticComponent) ListItem(org.eclipse.sirius.components.forms.ListItem)

Aggregations

ArrayList (java.util.ArrayList)1 ListItem (org.eclipse.sirius.components.forms.ListItem)1 ListDescription (org.eclipse.sirius.components.forms.description.ListDescription)1 ListElementProps (org.eclipse.sirius.components.forms.elements.ListElementProps)1 DiagnosticComponent (org.eclipse.sirius.components.forms.validation.DiagnosticComponent)1 DiagnosticComponentProps (org.eclipse.sirius.components.forms.validation.DiagnosticComponentProps)1 Element (org.eclipse.sirius.components.representations.Element)1 IStatus (org.eclipse.sirius.components.representations.IStatus)1 VariableManager (org.eclipse.sirius.components.representations.VariableManager)1