Search in sources :

Example 1 with FormElementFilter

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);
}
Also used : BindableProxy(org.jboss.errai.databinding.client.BindableProxy) StaticModelFormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.impl.StaticModelFormRenderingContext) FormElementFilter(org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter) PathAwareFormContext(org.kie.workbench.common.stunner.forms.context.PathAwareFormContext)

Example 2 with FormElementFilter

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 };
}
Also used : FormElementFilter(org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter)

Example 3 with FormElementFilter

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;
}
Also used : TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) Collection(java.util.Collection) FormElementFilter(org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter) IsCRUDDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HasNestedForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm) Inject(javax.inject.Inject) PropertyValueExtractor(org.kie.workbench.common.forms.adf.engine.shared.formGeneration.util.PropertyValueExtractor) List(java.util.List) Stream(java.util.stream.Stream) StaticModelFormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.impl.StaticModelFormRenderingContext) Dependent(javax.enterprise.context.Dependent) FormBuildingService(org.kie.workbench.common.forms.adf.engine.shared.FormBuildingService) Optional(java.util.Optional) EntityRelationField(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EntityRelationField) PortablePreconditions(org.kie.soup.commons.validation.PortablePreconditions) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) ArrayList(java.util.ArrayList) StaticModelFormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.impl.StaticModelFormRenderingContext) FormElementFilter(org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter) Stream(java.util.stream.Stream) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 4 with FormElementFilter

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);
    }
}
Also used : FormElementFilter(org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 5 with FormElementFilter

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));
}
Also used : FormElementFilter(org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter) StartErrorEvent(org.kie.workbench.common.stunner.bpmn.definition.StartErrorEvent) Test(org.junit.Test)

Aggregations

FormElementFilter (org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter)10 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)4 StaticModelFormRenderingContext (org.kie.workbench.common.forms.dynamic.service.shared.impl.StaticModelFormRenderingContext)3 Collection (java.util.Collection)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 Predicate (java.util.function.Predicate)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Dependent (javax.enterprise.context.Dependent)1 Inject (javax.inject.Inject)1 BindableProxy (org.jboss.errai.databinding.client.BindableProxy)1 PortablePreconditions (org.kie.soup.commons.validation.PortablePreconditions)1 FormBuildingService (org.kie.workbench.common.forms.adf.engine.shared.FormBuildingService)1 Address (org.kie.workbench.common.forms.adf.engine.shared.formGeneration.model.Address)1 PropertyValueExtractor (org.kie.workbench.common.forms.adf.engine.shared.formGeneration.util.PropertyValueExtractor)1