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;
}
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
}
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;
}
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);
}
Aggregations