use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormGeneratorTest method testGenerateFormForModel.
@Test
public void testGenerateFormForModel() {
FormDefinition form = generator.generateFormForModel(model);
testGeneratedForm(form, Person.class.getName());
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormGeneratorTest method testGenerateFormForModelWithFilters.
@Test
public void testGenerateFormForModelWithFilters() {
FormDefinition form = generator.generateFormForModel(model, getFilters());
checkFormGeneratedWithFilters(form);
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class FormBuildingServiceImplTest method testGenerateFormForClassName.
@Test
public void testGenerateFormForClassName() {
FormDefinition form = formBuildingService.generateFormForClassName(Person.class.getName());
testGeneratedForm(form, Person.class.getName());
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class DynamicFormModelGenerator method getContextForModel.
public StaticModelFormRenderingContext getContextForModel(Object model, FormElementFilter... filters) {
PortablePreconditions.checkNotNull("model", model);
Optional<FormElementFilter[]> optional = Optional.ofNullable(filters);
Stream<FormElementFilter> streamFilter = optional.map(value -> Stream.of(value)).orElseGet(Stream::empty);
List<FormElementFilter> rootFormElemenFilters = new ArrayList<>();
List<FormElementFilter> nestedFormFilters = new ArrayList<>();
streamFilter.forEach(filter -> {
if (!filter.getElementName().contains(".")) {
rootFormElemenFilters.add(filter);
} else {
nestedFormFilters.add(filter);
}
});
FormDefinition formDefinition = formBuildingService.generateFormForModel(model, rootFormElemenFilters.stream().toArray(FormElementFilter[]::new));
if (formDefinition == null) {
return null;
}
StaticModelFormRenderingContext context = new StaticModelFormRenderingContext();
context.setModel(model);
context.setRootForm(formDefinition);
if (context.getModel() != null) {
initNestedFormSettings(formDefinition, context.getModel(), context, nestedFormFilters);
} else {
initNestedFormSettings(formDefinition, null, context, nestedFormFilters);
}
return context;
}
use of org.kie.workbench.common.forms.model.FormDefinition in project kie-wb-common by kiegroup.
the class DynamicFormModelGenerator method addNestedForm.
private void addNestedForm(Object model, StaticModelFormRenderingContext context, Collection<FormElementFilter> nestedFormFilters) {
if (!context.getAvailableForms().containsKey(model.getClass().getName())) {
FormDefinition nested = formBuildingService.generateFormForModel(model, nestedFormFilters.stream().toArray(FormElementFilter[]::new));
context.getAvailableForms().put(model.getClass().getName(), nested);
initNestedFormSettings(nested, model, context, nestedFormFilters);
}
}
Aggregations