use of org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter 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.adf.engine.shared.FormElementFilter in project kie-wb-common by kiegroup.
the class FormGeneratorTest method getFilters.
protected FormElementFilter[] getFilters() {
FormElementFilter nameFilter = new FormElementFilter("name", o -> false);
FormElementFilter lastNameFilter = new FormElementFilter("lastName", o -> false);
return new FormElementFilter[] { nameFilter, lastNameFilter };
}
use of org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter 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.adf.engine.shared.FormElementFilter 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);
}
}
use of org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter in project kie-wb-common by kiegroup.
the class StartEventFilterProviderFactoryTest method testStartEventFilterProviderParentNull.
@Test
public void testStartEventFilterProviderParentNull() {
when(parentNode.asNode()).thenReturn(null);
when(parentNode.getContent()).thenReturn(null);
Class<?> filterClass = StartErrorEvent.class;
startEventFilterProvider = new StartEventFilterProvider(sessionManager, filterClass);
assertEquals(filterClass, startEventFilterProvider.getDefinitionType());
Collection<FormElementFilter> formElementFilters = startEventFilterProvider.provideFilters(ELEMENT_UUID, element, definition);
FormElementFilter formElementFilter = formElementFilters.iterator().next();
assertEquals(1, formElementFilters.size());
assertEquals(ELEMENT_NAME, formElementFilter.getElementName());
assertFalse(formElementFilter.getPredicate().test(definition));
}
Aggregations