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