use of org.kie.workbench.common.forms.dynamic.service.shared.impl.StaticModelFormRenderingContext in project kie-wb-common by kiegroup.
the class FormDisplayer method doRender.
private void doRender(Element<? extends Definition<?>> element, Object definition, Path diagramPath, FieldChangeHandler changeHandler) {
if (renderer.isInitialized()) {
LOGGER.fine("Clearing previous form");
renderer.unBind();
}
LOGGER.fine("Rendering a new form for element");
Collection<FormElementFilter> filters = FormFiltersProviderFactory.getFilterForDefinition(element.getUUID(), element, definition);
final BindableProxy<?> proxy = (BindableProxy<?>) BindableProxyFactory.getBindableProxy(definition);
final StaticModelFormRenderingContext generatedCtx = modelGenerator.getContextForModel(proxy.deepUnwrap(), filters.stream().toArray(FormElementFilter[]::new));
final FormRenderingContext<?> pathAwareCtx = new PathAwareFormContext<>(generatedCtx, diagramPath);
renderer.render(pathAwareCtx);
renderer.addFieldChangeHandler(changeHandler);
}
use of org.kie.workbench.common.forms.dynamic.service.shared.impl.StaticModelFormRenderingContext 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.dynamic.service.shared.impl.StaticModelFormRenderingContext in project kie-wb-common by kiegroup.
the class TestFormGenerator method getContextForEmployee.
public static StaticModelFormRenderingContext getContextForEmployee(Employee employee) {
FormDefinition form = getEmployeeForm();
StaticModelFormRenderingContext context = new StaticModelFormRenderingContext();
context.setRootForm(form);
context.setModel(employee);
context.getAvailableForms().put(form.getId(), form);
form = getAddressForm();
context.getAvailableForms().put(form.getId(), form);
return context;
}
use of org.kie.workbench.common.forms.dynamic.service.shared.impl.StaticModelFormRenderingContext in project kie-wb-common by kiegroup.
the class DynamicFormModelGeneratorTest method testGenerateContextForModel.
@Test
public void testGenerateContextForModel() {
StaticModelFormRenderingContext context = dynamicFormModelGenerator.getContextForModel(model);
assertNotNull(context);
assertNotNull(context.getRootForm());
assertEquals(3, context.getAvailableForms().size());
context.getAvailableForms().forEach((id, form) -> {
testGeneratedForm(form, id);
});
}
use of org.kie.workbench.common.forms.dynamic.service.shared.impl.StaticModelFormRenderingContext in project kie-wb-common by kiegroup.
the class DynamicFormModelGeneratorTest method testGenerateContextForModelWithFilters.
@Test
public void testGenerateContextForModelWithFilters() {
FormElementFilter nameFilter = new FormElementFilter("name", o -> true);
FormElementFilter lastNameFilter = new FormElementFilter("lastName", o -> false);
FormElementFilter addressStreetFilter = new FormElementFilter("address.street", o -> true);
FormElementFilter addressNumFilter = new FormElementFilter("address.number", o -> false);
StaticModelFormRenderingContext context = dynamicFormModelGenerator.getContextForModel(model, nameFilter, lastNameFilter, addressStreetFilter, addressNumFilter);
assertEquals(3, context.getAvailableForms().size());
FormDefinition rootForm = context.getRootForm();
assertNotNull(rootForm);
assertEquals(rootForm.getFields().size(), rootForm.getLayoutTemplate().getRows().size());
assertNotNull(rootForm.getFieldByBinding("name"));
assertNull(rootForm.getFieldByBinding("lastName"));
FormDefinition addressForm = context.getAvailableForms().get(Address.class.getName());
assertNotNull(addressForm);
assertEquals(addressForm.getFields().size(), addressForm.getLayoutTemplate().getRows().size());
assertNotNull(addressForm.getFieldByBinding("street"));
assertNull(addressForm.getFieldByBinding("number"));
}
Aggregations