Search in sources :

Example 1 with ListDescription

use of org.eclipse.sirius.components.forms.description.ListDescription in project sirius-components by eclipse-sirius.

the class WidgetComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    AbstractWidgetDescription widgetDescription = this.props.getWidgetDescription();
    Element element = null;
    if (widgetDescription instanceof TextfieldDescription) {
        TextfieldComponentProps textfieldProps = new TextfieldComponentProps(variableManager, (TextfieldDescription) widgetDescription);
        element = new Element(TextfieldComponent.class, textfieldProps);
    } else if (widgetDescription instanceof TextareaDescription) {
        TextareaComponentProps textareaProps = new TextareaComponentProps(variableManager, (TextareaDescription) widgetDescription);
        element = new Element(TextareaComponent.class, textareaProps);
    } else if (widgetDescription instanceof CheckboxDescription) {
        CheckboxComponentProps checkboxProps = new CheckboxComponentProps(variableManager, (CheckboxDescription) widgetDescription);
        element = new Element(CheckboxComponent.class, checkboxProps);
    } else if (widgetDescription instanceof SelectDescription) {
        SelectComponentProps selectProps = new SelectComponentProps(variableManager, (SelectDescription) widgetDescription);
        element = new Element(SelectComponent.class, selectProps);
    } else if (widgetDescription instanceof MultiSelectDescription) {
        MultiSelectComponentProps multiSelectProps = new MultiSelectComponentProps(variableManager, (MultiSelectDescription) widgetDescription);
        element = new Element(MultiSelectComponent.class, multiSelectProps);
    } else if (widgetDescription instanceof RadioDescription) {
        RadioComponentProps radioProps = new RadioComponentProps(variableManager, (RadioDescription) widgetDescription);
        element = new Element(RadioComponent.class, radioProps);
    } else if (widgetDescription instanceof ListDescription) {
        ListComponentProps listProps = new ListComponentProps(variableManager, (ListDescription) widgetDescription);
        element = new Element(ListComponent.class, listProps);
    } else if (widgetDescription instanceof LinkDescription) {
        LinkComponentProps linkProps = new LinkComponentProps(variableManager, (LinkDescription) widgetDescription);
        element = new Element(LinkComponent.class, linkProps);
    } else {
        // $NON-NLS-1$
        String pattern = "Unsupported widget description: {}";
        this.logger.warn(pattern, widgetDescription.getClass().getSimpleName());
    }
    return element;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) LinkDescription(org.eclipse.sirius.components.forms.description.LinkDescription) Element(org.eclipse.sirius.components.representations.Element) MultiSelectDescription(org.eclipse.sirius.components.forms.description.MultiSelectDescription) ListDescription(org.eclipse.sirius.components.forms.description.ListDescription) AbstractWidgetDescription(org.eclipse.sirius.components.forms.description.AbstractWidgetDescription) TextareaDescription(org.eclipse.sirius.components.forms.description.TextareaDescription) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) MultiSelectDescription(org.eclipse.sirius.components.forms.description.MultiSelectDescription)

Example 2 with ListDescription

use of org.eclipse.sirius.components.forms.description.ListDescription in project sirius-web by eclipse-sirius.

the class RepresentationsDescriptionProvider method getGroupDescription.

private GroupDescription getGroupDescription() {
    List<AbstractControlDescription> controlDescriptions = new ArrayList<>();
    // @formatter:off
    ListDescription listDescription = // $NON-NLS-1$
    ListDescription.newListDescription("RepresentationsList").idProvider(new WidgetIdProvider()).labelProvider(// $NON-NLS-1$
    (variableManager) -> "Representations").itemsProvider(this.getItemsProvider()).itemIdProvider(this.getItemIdProvider()).itemLabelProvider(this.getItemLabelProvider()).itemImageURLProvider(this.getItemImageURLProvider()).itemDeletableProvider(this.getItemDeletableProvider()).itemDeleteHandlerProvider(this.getItemDeleteHandlerProvider()).itemKindProvider(this.getItemKindProvider()).diagnosticsProvider((variableManager) -> List.of()).kindProvider(// $NON-NLS-1$
    (object) -> "").messageProvider(// $NON-NLS-1$
    (object) -> "").build();
    // @formatter:on
    controlDescriptions.add(listDescription);
    // @formatter:off
    return // $NON-NLS-1$
    GroupDescription.newGroupDescription("representationsGroupId").idProvider(// $NON-NLS-1$
    variableManager -> "Representations Group").labelProvider(// $NON-NLS-1$
    variableManager -> "Representations Group").semanticElementsProvider(variableManager -> Collections.singletonList(variableManager.getVariables().get(VariableManager.SELF))).controlDescriptions(controlDescriptions).build();
// @formatter:on
}
Also used : IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) PageDescription(org.eclipse.sirius.components.forms.description.PageDescription) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) ListDescription(org.eclipse.sirius.components.forms.description.ListDescription) ListComponent(org.eclipse.sirius.components.forms.components.ListComponent) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FormDescription(org.eclipse.sirius.components.forms.description.FormDescription) IStatus(org.eclipse.sirius.components.representations.IStatus) Service(org.springframework.stereotype.Service) Map(java.util.Map) EditingContextEventProcessor(org.eclipse.sirius.components.collaborative.editingcontext.EditingContextEventProcessor) RepresentationMetadata(org.eclipse.sirius.components.core.RepresentationMetadata) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) IRepresentationsDescriptionProvider(org.eclipse.sirius.components.collaborative.forms.api.IRepresentationsDescriptionProvider) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) UUID(java.util.UUID) IRepresentationService(org.eclipse.sirius.web.services.api.representations.IRepresentationService) Objects(java.util.Objects) WidgetIdProvider(org.eclipse.sirius.components.compatibility.forms.WidgetIdProvider) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider) AbstractControlDescription(org.eclipse.sirius.components.forms.description.AbstractControlDescription) ImageConstants(org.eclipse.sirius.components.compatibility.services.ImageConstants) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Collections(java.util.Collections) IRepresentationImageProvider(org.eclipse.sirius.components.collaborative.api.IRepresentationImageProvider) AbstractControlDescription(org.eclipse.sirius.components.forms.description.AbstractControlDescription) ArrayList(java.util.ArrayList) ListDescription(org.eclipse.sirius.components.forms.description.ListDescription) WidgetIdProvider(org.eclipse.sirius.components.compatibility.forms.WidgetIdProvider)

Example 3 with ListDescription

use of org.eclipse.sirius.components.forms.description.ListDescription 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

ListDescription (org.eclipse.sirius.components.forms.description.ListDescription)3 VariableManager (org.eclipse.sirius.components.representations.VariableManager)3 ArrayList (java.util.ArrayList)2 Element (org.eclipse.sirius.components.representations.Element)2 IStatus (org.eclipse.sirius.components.representations.IStatus)2 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)1 IRepresentationImageProvider (org.eclipse.sirius.components.collaborative.api.IRepresentationImageProvider)1 EditingContextEventProcessor (org.eclipse.sirius.components.collaborative.editingcontext.EditingContextEventProcessor)1 IRepresentationsDescriptionProvider (org.eclipse.sirius.components.collaborative.forms.api.IRepresentationsDescriptionProvider)1 WidgetIdProvider (org.eclipse.sirius.components.compatibility.forms.WidgetIdProvider)1 ImageConstants (org.eclipse.sirius.components.compatibility.services.ImageConstants)1 RepresentationMetadata (org.eclipse.sirius.components.core.RepresentationMetadata)1