Search in sources :

Example 1 with ForDescription

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

the class PropertiesDefaultDescriptionProvider method getGroupDescription.

private GroupDescription getGroupDescription() {
    List<AbstractControlDescription> controlDescriptions = new ArrayList<>();
    Function<VariableManager, List<?>> iterableProvider = variableManager -> {
        List<Object> objects = new ArrayList<>();
        Object self = variableManager.getVariables().get(VariableManager.SELF);
        if (self instanceof EObject) {
            EObject eObject = (EObject) self;
            // @formatter:off
            List<IItemPropertyDescriptor> propertyDescriptors = Optional.ofNullable(this.composedAdapterFactory.adapt(eObject, IItemPropertySource.class)).filter(IItemPropertySource.class::isInstance).map(IItemPropertySource.class::cast).map(iItemPropertySource -> iItemPropertySource.getPropertyDescriptors(eObject)).orElse(new ArrayList<>());
            propertyDescriptors.stream().map(propertyDescriptor -> propertyDescriptor.getFeature(eObject)).filter(EStructuralFeature.class::isInstance).map(EStructuralFeature.class::cast).forEach(objects::add);
        // @formatter:on
        }
        return objects;
    };
    List<IfDescription> ifDescriptions = new ArrayList<>();
    ifDescriptions.add(new EStringIfDescriptionProvider(this.composedAdapterFactory, this.propertiesValidationProvider).getIfDescription());
    ifDescriptions.add(new EBooleanIfDescriptionProvider(this.composedAdapterFactory, this.propertiesValidationProvider).getIfDescription());
    ifDescriptions.add(new EEnumIfDescriptionProvider(this.composedAdapterFactory, this.propertiesValidationProvider).getIfDescription());
    ifDescriptions.add(new MonoValuedNonContainmentReferenceIfDescriptionProvider(this.composedAdapterFactory, this.objectService, this.propertiesValidationProvider).getIfDescription());
    ifDescriptions.add(new MultiValuedNonContainmentReferenceIfDescriptionProvider(this.composedAdapterFactory, this.objectService, this.propertiesValidationProvider).getIfDescription());
    // @formatter:off
    var numericDataTypes = List.of(EcorePackage.Literals.EINT, EcorePackage.Literals.EINTEGER_OBJECT, EcorePackage.Literals.EDOUBLE, EcorePackage.Literals.EDOUBLE_OBJECT, EcorePackage.Literals.EFLOAT, EcorePackage.Literals.EFLOAT_OBJECT, EcorePackage.Literals.ELONG, EcorePackage.Literals.ELONG_OBJECT, EcorePackage.Literals.ESHORT, EcorePackage.Literals.ESHORT_OBJECT);
    // @formatter:on
    for (var dataType : numericDataTypes) {
        ifDescriptions.add(new NumberIfDescriptionProvider(dataType, this.composedAdapterFactory, this.propertiesValidationProvider, this.emfMessageService).getIfDescription());
    }
    // @formatter:off
    ForDescription forDescription = // $NON-NLS-1$
    ForDescription.newForDescription("forId").iterator(ESTRUCTURAL_FEATURE).iterableProvider(iterableProvider).ifDescriptions(ifDescriptions).build();
    // @formatter:on
    controlDescriptions.add(forDescription);
    // @formatter:off
    return // $NON-NLS-1$
    GroupDescription.newGroupDescription("groupId").idProvider(// $NON-NLS-1$
    variableManager -> "Core Properties").labelProvider(// $NON-NLS-1$
    variableManager -> "Core Properties").semanticElementsProvider(variableManager -> Collections.singletonList(variableManager.getVariables().get(VariableManager.SELF))).controlDescriptions(controlDescriptions).build();
// @formatter:on
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) PageDescription(org.eclipse.sirius.components.forms.description.PageDescription) EcorePackage(org.eclipse.emf.ecore.EcorePackage) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) IfDescription(org.eclipse.sirius.components.forms.description.IfDescription) IItemPropertyDescriptor(org.eclipse.emf.edit.provider.IItemPropertyDescriptor) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FormDescription(org.eclipse.sirius.components.forms.description.FormDescription) Service(org.springframework.stereotype.Service) IPropertiesValidationProvider(org.eclipse.sirius.components.emf.compatibility.properties.api.IPropertiesValidationProvider) ForDescription(org.eclipse.sirius.components.forms.description.ForDescription) GroupDescription(org.eclipse.sirius.components.forms.description.GroupDescription) IEMFMessageService(org.eclipse.sirius.components.emf.services.messages.IEMFMessageService) EObject(org.eclipse.emf.ecore.EObject) UUID(java.util.UUID) IPropertiesDefaultDescriptionProvider(org.eclipse.sirius.components.collaborative.forms.api.IPropertiesDefaultDescriptionProvider) IItemPropertySource(org.eclipse.emf.edit.provider.IItemPropertySource) Objects(java.util.Objects) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider) AbstractControlDescription(org.eclipse.sirius.components.forms.description.AbstractControlDescription) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Collections(java.util.Collections) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) ArrayList(java.util.ArrayList) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IItemPropertySource(org.eclipse.emf.edit.provider.IItemPropertySource) AbstractControlDescription(org.eclipse.sirius.components.forms.description.AbstractControlDescription) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) List(java.util.List) EObject(org.eclipse.emf.ecore.EObject) IfDescription(org.eclipse.sirius.components.forms.description.IfDescription) ForDescription(org.eclipse.sirius.components.forms.description.ForDescription)

Example 2 with ForDescription

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

the class FormRendererTests method checkResult.

private void checkResult(FormDescription description) {
    // test SiriusViewExtensionDescriptionConverter
    assertThat(description).isNotNull();
    assertThat(description.getGroupDescriptions()).hasSize(1);
    assertThat(description.getPageDescriptions()).hasSize(1);
    assertThat(description.getPageDescriptions().get(0).getGroupDescriptions()).hasSize(1);
    assertThat(description.getPageDescriptions()).hasSize(1);
    assertThat(description.getPageDescriptions().get(0).getGroupDescriptions().get(0)).isEqualTo(description.getGroupDescriptions().get(0));
    assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream())).hasSize(6);
    assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(CheckboxDescription.class::isInstance)).hasSize(1);
    assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(RadioDescription.class::isInstance)).hasSize(1);
    assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(SelectDescription.class::isInstance)).hasSize(1);
    assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(TextfieldDescription.class::isInstance)).hasSize(1);
    assertThat(description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(TextfieldDescription.class::isInstance)).hasSize(1);
    Optional<ForDescription> forOptional = description.getGroupDescriptions().stream().flatMap(g -> g.getControlDescriptions().stream()).filter(ForDescription.class::isInstance).map(ForDescription.class::cast).findFirst();
    assertThat(forOptional).isNotEmpty();
    assertThat(forOptional.get().getIfDescriptions()).hasSize(1);
    assertThat(forOptional.get().getIfDescriptions().stream().findFirst().get().getWidgetDescription()).isNotNull();
    // Test FormRenderer
    VariableManager variableManager = new VariableManager();
    variableManager.put(VariableManager.SELF, List.of(EcorePackage.eINSTANCE));
    FormRenderer formRenderer = new FormRenderer();
    FormComponentProps props = new FormComponentProps(variableManager, description);
    Element element = new Element(FormComponent.class, props);
    Form form = formRenderer.render(element);
    assertThat(form.getPages()).hasSize(1);
    assertThat(form.getPages().stream().flatMap(p -> p.getGroups().stream())).hasSize(1);
    assertThat(form.getPages().stream().flatMap(p -> p.getGroups().stream()).flatMap(g -> g.getWidgets().stream())).hasSize(5);
    List<Group> groups = form.getPages().stream().flatMap(p -> p.getGroups().stream()).collect(Collectors.toList());
    this.checkIdsInGroups(groups);
}
Also used : Form(org.eclipse.sirius.components.forms.Form) EcorePackage(org.eclipse.emf.ecore.EcorePackage) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Category(org.eclipse.sirius.properties.Category) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FormRenderer(org.eclipse.sirius.components.forms.renderer.FormRenderer) AbstractWidget(org.eclipse.sirius.components.forms.AbstractWidget) ViewExtensionDescription(org.eclipse.sirius.properties.ViewExtensionDescription) FormDescription(org.eclipse.sirius.components.forms.description.FormDescription) FormComponent(org.eclipse.sirius.components.forms.components.FormComponent) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) ModelOperationHandlerSwitch(org.eclipse.sirius.components.emf.compatibility.modeloperations.ModelOperationHandlerSwitch) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) ForDescription(org.eclipse.sirius.components.forms.description.ForDescription) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) PropertiesFactory(org.eclipse.sirius.properties.PropertiesFactory) SemanticCandidatesProvider(org.eclipse.sirius.components.emf.compatibility.SemanticCandidatesProvider) ViewExtensionDescriptionConverter(org.eclipse.sirius.components.compatibility.forms.ViewExtensionDescriptionConverter) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Element(org.eclipse.sirius.components.representations.Element) IRepresentationMetadataSearchService(org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService) Test(org.junit.jupiter.api.Test) List(java.util.List) Group(org.eclipse.sirius.components.forms.Group) FormComponentProps(org.eclipse.sirius.components.forms.components.FormComponentProps) Optional(java.util.Optional) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IdentifiedElementLabelProvider(org.eclipse.sirius.components.compatibility.services.representations.IdentifiedElementLabelProvider) AQLInterpreterFactory(org.eclipse.sirius.components.emf.compatibility.AQLInterpreterFactory) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) CheckboxDescription(org.eclipse.sirius.components.forms.description.CheckboxDescription) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Group(org.eclipse.sirius.components.forms.Group) RadioDescription(org.eclipse.sirius.components.forms.description.RadioDescription) Form(org.eclipse.sirius.components.forms.Form) Element(org.eclipse.sirius.components.representations.Element) FormRenderer(org.eclipse.sirius.components.forms.renderer.FormRenderer) SelectDescription(org.eclipse.sirius.components.forms.description.SelectDescription) TextfieldDescription(org.eclipse.sirius.components.forms.description.TextfieldDescription) FormComponentProps(org.eclipse.sirius.components.forms.components.FormComponentProps) ForDescription(org.eclipse.sirius.components.forms.description.ForDescription)

Example 3 with ForDescription

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

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

ForDescription (org.eclipse.sirius.components.forms.description.ForDescription)4 VariableManager (org.eclipse.sirius.components.representations.VariableManager)4 ArrayList (java.util.ArrayList)3 Element (org.eclipse.sirius.components.representations.Element)3 List (java.util.List)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 EcorePackage (org.eclipse.emf.ecore.EcorePackage)2 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)2 AbstractControlDescription (org.eclipse.sirius.components.forms.description.AbstractControlDescription)2 FormDescription (org.eclipse.sirius.components.forms.description.FormDescription)2 GroupDescription (org.eclipse.sirius.components.forms.description.GroupDescription)2 IfDescription (org.eclipse.sirius.components.forms.description.IfDescription)2 Fragment (org.eclipse.sirius.components.representations.Fragment)2 FragmentProps (org.eclipse.sirius.components.representations.FragmentProps)2 Collections (java.util.Collections)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1