Search in sources :

Example 1 with IfDescription

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

the class EStringIfDescriptionProviderTests method checkPredicate.

private Boolean checkPredicate(AdapterFactory adapterFactory, EAttribute attribute) {
    ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory(adapterFactory);
    EStringIfDescriptionProvider descriptionProvider = new EStringIfDescriptionProvider(composedAdapterFactory, new IPropertiesValidationProvider.NoOp());
    IfDescription ifDescription = descriptionProvider.getIfDescription();
    VariableManager variableManager = new VariableManager();
    variableManager.put(PropertiesDefaultDescriptionProvider.ESTRUCTURAL_FEATURE, attribute);
    Boolean predicateResult = ifDescription.getPredicate().apply(variableManager);
    return predicateResult;
}
Also used : IPropertiesValidationProvider(org.eclipse.sirius.components.emf.compatibility.properties.api.IPropertiesValidationProvider) VariableManager(org.eclipse.sirius.components.representations.VariableManager) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) IfDescription(org.eclipse.sirius.components.forms.description.IfDescription)

Example 2 with IfDescription

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

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

the class IfComponent method render.

@Override
public Element render() {
    VariableManager variableManager = this.props.getVariableManager();
    IfDescription ifDescription = this.props.getIfDescription();
    Boolean result = ifDescription.getPredicate().apply(variableManager);
    if (result.booleanValue()) {
        WidgetComponentProps widgetComponentProps = new WidgetComponentProps(variableManager, ifDescription.getWidgetDescription());
        return new Element(WidgetComponent.class, widgetComponentProps);
    }
    return null;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Element(org.eclipse.sirius.components.representations.Element) IfDescription(org.eclipse.sirius.components.forms.description.IfDescription)

Example 4 with IfDescription

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

IfDescription (org.eclipse.sirius.components.forms.description.IfDescription)4 VariableManager (org.eclipse.sirius.components.representations.VariableManager)4 ArrayList (java.util.ArrayList)2 ComposedAdapterFactory (org.eclipse.emf.edit.provider.ComposedAdapterFactory)2 IPropertiesValidationProvider (org.eclipse.sirius.components.emf.compatibility.properties.api.IPropertiesValidationProvider)2 ForDescription (org.eclipse.sirius.components.forms.description.ForDescription)2 Element (org.eclipse.sirius.components.representations.Element)2 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 EObject (org.eclipse.emf.ecore.EObject)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 EcorePackage (org.eclipse.emf.ecore.EcorePackage)1 IItemPropertyDescriptor (org.eclipse.emf.edit.provider.IItemPropertyDescriptor)1 IItemPropertySource (org.eclipse.emf.edit.provider.IItemPropertySource)1 IPropertiesDefaultDescriptionProvider (org.eclipse.sirius.components.collaborative.forms.api.IPropertiesDefaultDescriptionProvider)1 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)1