Search in sources :

Example 1 with StaticModelFormRenderingContext

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

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;
}
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 3 with StaticModelFormRenderingContext

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;
}
Also used : StaticModelFormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.impl.StaticModelFormRenderingContext) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 4 with StaticModelFormRenderingContext

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);
    });
}
Also used : StaticModelFormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.impl.StaticModelFormRenderingContext) Test(org.junit.Test) AbstractFormGenerationTest(org.kie.workbench.common.forms.adf.engine.shared.test.AbstractFormGenerationTest)

Example 5 with StaticModelFormRenderingContext

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"));
}
Also used : Address(org.kie.workbench.common.forms.adf.engine.shared.formGeneration.model.Address) StaticModelFormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.impl.StaticModelFormRenderingContext) FormElementFilter(org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Test(org.junit.Test) AbstractFormGenerationTest(org.kie.workbench.common.forms.adf.engine.shared.test.AbstractFormGenerationTest)

Aggregations

StaticModelFormRenderingContext (org.kie.workbench.common.forms.dynamic.service.shared.impl.StaticModelFormRenderingContext)5 FormElementFilter (org.kie.workbench.common.forms.adf.engine.shared.FormElementFilter)3 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)3 Test (org.junit.Test)2 AbstractFormGenerationTest (org.kie.workbench.common.forms.adf.engine.shared.test.AbstractFormGenerationTest)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)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 EntityRelationField (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EntityRelationField)1 HasNestedForm (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm)1