Search in sources :

Example 1 with TableColumnMeta

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta in project kie-wb-common by kiegroup.

the class BeanPropertiesProviderTest method testGetModelProperties.

protected void testGetModelProperties(String... columns) {
    field = new MultipleSubFormFieldDefinition();
    for (String column : columns) {
        field.getColumnMetas().add(new TableColumnMeta(column, column));
    }
    List<String> bannedColumns = new ArrayList<>(Arrays.asList(columns));
    if (!StringUtils.isEmpty(currentEditedMeta.getProperty())) {
        bannedColumns.remove(currentEditedMeta.getProperty());
    }
    field.setStandaloneClassName(TYPE_NAME);
    parentContext = new FormEditorRenderingContext(path);
    parentContext.setModel(field);
    context.setParentContext(parentContext);
    expectedFields = DATA_OBJECT_VALID_FIELDS - bannedColumns.size();
    SelectorData data = provider.getSelectorData(context);
    verify(service).getDataObjectProperties(any(), any());
    assertNotNull(data);
    assertNotNull(data.getValues());
    assertNull(data.getSelectedValue());
    assertFalse(data.getValues().isEmpty());
    assertEquals(expectedFields, data.getValues().size());
    for (String column : bannedColumns) {
        assertNull(data.getValues().get(column));
    }
    assertNull(data.getValues().get(DataObjectFormModelHandler.SERIAL_VERSION_UID));
    assertNull(data.getValues().get(PERSISTENCE_ID_PROPERTY));
}
Also used : FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) ArrayList(java.util.ArrayList) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData)

Example 2 with TableColumnMeta

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta in project kie-wb-common by kiegroup.

the class AbstractBPMNFormGeneratorService method processFieldDefinition.

protected void processFieldDefinition(FieldDefinition field, GenerationContext<SOURCE> context) {
    if (field instanceof EntityRelationField) {
        if (field instanceof HasNestedForm) {
            HasNestedForm nestedFormField = (HasNestedForm) field;
            FormDefinition nestedForm = findFormDefinitionForModelType(field.getStandaloneClassName(), context);
            if (nestedForm == null) {
                nestedForm = createModelFormDefinition(field.getStandaloneClassName(), context);
            }
            nestedFormField.setNestedForm(nestedForm.getId());
        } else if (field instanceof IsCRUDDefinition) {
            IsCRUDDefinition crudField = (IsCRUDDefinition) field;
            FormDefinition nestedForm = findFormDefinitionForModelType(field.getStandaloneClassName(), context);
            if (nestedForm == null) {
                nestedForm = createModelFormDefinition(field.getStandaloneClassName(), context);
                crudField.setCreationForm(nestedForm.getId());
                crudField.setEditionForm(nestedForm.getId());
                List<TableColumnMeta> tableColumnMetas = new ArrayList<>();
                nestedForm.getFields().forEach(nestedField -> {
                    tableColumnMetas.add(new TableColumnMeta(nestedField.getLabel(), nestedField.getBinding()));
                });
                crudField.setColumnMetas(tableColumnMetas);
            }
        }
    }
}
Also used : LayoutColumnDefinition(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutColumnDefinition) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) UIDGenerator(org.kie.workbench.common.forms.services.backend.util.UIDGenerator) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) FormLayoutComponent(org.kie.workbench.common.forms.model.FormLayoutComponent) IsCRUDDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition) BPMNFormGeneratorService(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.BPMNFormGeneratorService) JavaFormModel(org.kie.workbench.common.forms.model.JavaFormModel) JBPMFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.JBPMFormModel) LayoutComponent(org.uberfire.ext.layout.editor.api.editor.LayoutComponent) ArrayList(java.util.ArrayList) ColSpan(org.kie.workbench.common.forms.adf.definitions.settings.ColSpan) HasNestedForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm) TaskFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel) StaticFormLayoutTemplateGenerator(org.kie.workbench.common.forms.commons.shared.layout.impl.StaticFormLayoutTemplateGenerator) List(java.util.List) LayoutGenerator(org.kie.workbench.common.forms.adf.engine.shared.formGeneration.layout.LayoutGenerator) FormGenerationResult(org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult) EntityRelationField(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EntityRelationField) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) FieldManager(org.kie.workbench.common.forms.service.shared.FieldManager) LayoutSettings(org.kie.workbench.common.forms.adf.service.definitions.layout.LayoutSettings) DataObjectFormModel(org.kie.workbench.common.forms.data.modeller.model.DataObjectFormModel) EntityRelationField(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EntityRelationField) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) IsCRUDDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition) HasNestedForm(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm) ArrayList(java.util.ArrayList) List(java.util.List) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 3 with TableColumnMeta

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta in project kie-wb-common by kiegroup.

the class MultipleSubFormWidget method initCrud.

protected void initCrud() {
    final List<ColumnMeta> metas = new ArrayList<>();
    HasProperties hasProperties = null;
    try {
        hasProperties = bindingHelper.getProxyDefinition();
    } catch (Exception e) {
        GWT.log("Unable to find proxy: " + e.getMessage());
    }
    for (TableColumnMeta meta : field.getColumnMetas()) {
        String type = String.class.getName();
        if (hasProperties != null) {
            type = hasProperties.getBeanProperties().get(meta.getProperty()).getType().getName();
        }
        ColumnGenerator generator = columnGeneratorManager.getGeneratorByType(type);
        if (generator != null) {
            ColumnMeta<HasProperties> columnMeta = new ColumnMeta<HasProperties>(generator.getColumn(meta.getProperty()), meta.getLabel());
            metas.add(columnMeta);
        }
    }
    dataProvider = new AsyncDataProvider<HasProperties>() {

        @Override
        protected void onRangeChanged(HasData<HasProperties> hasData) {
            if (tableValues != null) {
                updateRowCount(tableValues.size(), true);
                updateRowData(0, tableValues);
            } else {
                updateRowCount(0, true);
                updateRowData(0, new ArrayList<HasProperties>());
            }
        }
    };
    crudComponent.init(new CrudActionsHelper() {

        @Override
        public int getPageSize() {
            return PAGE_SIZE;
        }

        @Override
        public boolean showEmbeddedForms() {
            return true;
        }

        @Override
        public boolean isAllowCreate() {
            return !isReadOnly;
        }

        @Override
        public boolean isAllowEdit() {
            return !isReadOnly;
        }

        @Override
        public boolean isAllowDelete() {
            return !isReadOnly;
        }

        @Override
        public List<ColumnMeta> getGridColumns() {
            return metas;
        }

        @Override
        public AsyncDataProvider getDataProvider() {
            return dataProvider;
        }

        public IsFormView<Object> getCreateInstanceForm() {
            if (field.getCreationForm() != null) {
                BindableProxy<?> proxy = bindingHelper.getNewProxy();
                formRenderer.render(renderingContext.getCopyFor(field.getCreationForm(), proxy));
                return formRenderer;
            }
            return null;
        }

        public IsFormView<Object> getEditInstanceForm(int position) {
            if (field.getEditionForm() != null) {
                BindableProxy instanceProxy = bindingHelper.getProxyForModel(values.get(position));
                BindableProxy editionProxy = bindingHelper.getProxyForModel(instanceProxy.deepUnwrap());
                formRenderer.render(renderingContext.getCopyFor(field.getEditionForm(), editionProxy));
                return formRenderer;
            }
            return null;
        }

        @Override
        public void createInstance() {
            IsFormView form = getCreateInstanceForm();
            crudComponent.displayForm(translationService.getTranslation(CrudComponentConstants.CrudComponentViewImplNewInstanceTitle), form, new FormDisplayer.FormDisplayerCallback() {

                @Override
                public void onCancel() {
                    formRenderer.unBind();
                }

                @Override
                public void onAccept() {
                    if (values == null) {
                        values = new ArrayList<>();
                    }
                    values.add(formRenderer.getModel());
                    tableValues.add((HasProperties) formRenderer.getModel());
                    refreshCrud();
                    fireFieldChange();
                    formRenderer.unBind();
                }
            });
        }

        @Override
        public void editInstance(int index) {
            IsFormView form = getEditInstanceForm(index);
            crudComponent.displayForm(translationService.getTranslation(CrudComponentConstants.CrudComponentViewImplEditInstanceTitle), form, new FormDisplayer.FormDisplayerCallback() {

                @Override
                public void onCancel() {
                    formRenderer.unBind();
                }

                @Override
                public void onAccept() {
                    BindableProxy editionProxy = (BindableProxy) formRenderer.getModel();
                    BindableProxy realProxy = bindingHelper.getProxyForModel(values.get(index));
                    FormDefinition editionform = (FormDefinition) renderingContext.getAvailableForms().get(field.getEditionForm());
                    editionform.getFields().forEach(fieldDefinition -> {
                        if (fieldDefinition.getBinding() != null) {
                            realProxy.set(fieldDefinition.getBinding(), editionProxy.get(fieldDefinition.getBinding()));
                        }
                    });
                    bindingHelper.afterEdit(realProxy);
                    values.set(index, realProxy);
                    tableValues.set(index, realProxy);
                    refreshCrud();
                    fireFieldChange();
                    formRenderer.unBind();
                }
            });
        }

        @Override
        public void deleteInstance(int index) {
            values.remove(index);
            tableValues.remove(index);
            refreshCrud();
            fireFieldChange();
        }
    });
    initValues();
}
Also used : TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) BindableProxy(org.jboss.errai.databinding.client.BindableProxy) ArrayList(java.util.ArrayList) HasProperties(org.jboss.errai.databinding.client.HasProperties) CrudActionsHelper(org.kie.workbench.common.forms.crud.client.component.CrudActionsHelper) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) ColumnMeta(org.uberfire.ext.widgets.table.client.ColumnMeta) ColumnGenerator(org.kie.workbench.common.forms.dynamic.client.rendering.renderers.relations.multipleSubform.columns.ColumnGenerator) IsFormView(org.kie.workbench.common.forms.crud.client.component.formDisplay.IsFormView) AsyncDataProvider(com.google.gwt.view.client.AsyncDataProvider) ArrayList(java.util.ArrayList) List(java.util.List) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 4 with TableColumnMeta

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta in project kie-wb-common by kiegroup.

the class MultipleSubFormFieldDefinitionTest method getFullFieldDefinition.

@Override
protected MultipleSubFormFieldDefinition getFullFieldDefinition() {
    MultipleSubFormFieldDefinition multipleSubFormFieldDefinition = new MultipleSubFormFieldDefinition();
    multipleSubFormFieldDefinition.setCreationForm("creationForm");
    multipleSubFormFieldDefinition.setEditionForm("editionForm");
    List<TableColumnMeta> columns = new ArrayList<>();
    columns.add(new TableColumnMeta("prop", "prop"));
    columns.add(new TableColumnMeta("prop2", "prop2"));
    multipleSubFormFieldDefinition.setColumnMetas(columns);
    return multipleSubFormFieldDefinition;
}
Also used : TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) ArrayList(java.util.ArrayList)

Example 5 with TableColumnMeta

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta in project kie-wb-common by kiegroup.

the class BeanPropertiesProvider method getSelectorData.

@Override
public SelectorData getSelectorData(FormRenderingContext context) {
    HashMap<String, String> values = new HashMap<>();
    if (context instanceof FormEditorRenderingContext && context.getParentContext() != null) {
        if (context.getParentContext().getModel() instanceof MultipleSubFormFieldDefinition) {
            FormEditorRenderingContext editorContext = (FormEditorRenderingContext) context;
            if (context.getParentContext() != null) {
                MultipleSubFormFieldDefinition subForm = (MultipleSubFormFieldDefinition) context.getParentContext().getModel();
                Path path = editorContext.getFormPath();
                String typeName = subForm.getStandaloneClassName();
                final TableColumnMeta currentMeta = (TableColumnMeta) context.getModel();
                Set<String> unavailableProperties = subForm.getColumnMetas().stream().map(TableColumnMeta::getProperty).collect(Collectors.toSet());
                if (currentMeta != null && !StringUtils.isEmpty(currentMeta.getProperty())) {
                    unavailableProperties.remove(currentMeta.getProperty());
                }
                dataObjectFinderService.getDataObjectProperties(typeName, path).stream().filter(property -> !unavailableProperties.contains(property.getName())).forEachOrdered(property -> values.put(property.getName(), property.getName()));
            }
        }
    }
    return new SelectorData(values, null);
}
Also used : Path(org.uberfire.backend.vfs.Path) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData) FormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) Set(java.util.Set) HashMap(java.util.HashMap) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) DataObjectFinderService(org.kie.workbench.common.forms.data.modeller.service.DataObjectFinderService) Inject(javax.inject.Inject) Dependent(javax.enterprise.context.Dependent) SystemSelectorDataProvider(org.kie.workbench.common.forms.dynamic.model.config.SystemSelectorDataProvider) FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) Path(org.uberfire.backend.vfs.Path) FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) HashMap(java.util.HashMap) TableColumnMeta(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData)

Aggregations

TableColumnMeta (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta)7 ArrayList (java.util.ArrayList)4 List (java.util.List)3 FormEditorRenderingContext (org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext)3 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)3 StringUtils (org.apache.commons.lang3.StringUtils)2 SelectorData (org.kie.workbench.common.forms.dynamic.model.config.SelectorData)2 HasNestedForm (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.HasNestedForm)2 IsCRUDDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.IsCRUDDefinition)2 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)2 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)2 AsyncDataProvider (com.google.gwt.view.client.AsyncDataProvider)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Dependent (javax.enterprise.context.Dependent)1 Inject (javax.inject.Inject)1