Search in sources :

Example 11 with SelectorData

use of org.kie.workbench.common.forms.dynamic.model.config.SelectorData 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)

Example 12 with SelectorData

use of org.kie.workbench.common.forms.dynamic.model.config.SelectorData in project kie-wb-common by kiegroup.

the class VFSSelectorFormProvider method getSelectorData.

@Override
public SelectorData getSelectorData(FormRenderingContext context) {
    Map<String, String> values = new TreeMap<>();
    if (context.getModel() instanceof EntityRelationField) {
        FormEditorRenderingContext editorContext = (FormEditorRenderingContext) context;
        FieldDefinition field = (FieldDefinition) context.getModel();
        List<FormDefinition> forms;
        if (field != null) {
            forms = vfsFormFinderService.findFormsForType(field.getStandaloneClassName(), editorContext.getFormPath());
        } else {
            forms = vfsFormFinderService.findAllForms(editorContext.getFormPath());
        }
        for (FormDefinition form : forms) {
            values.put(form.getId(), form.getName());
        }
    }
    return new SelectorData(values, null);
}
Also used : EntityRelationField(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.EntityRelationField) FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TreeMap(java.util.TreeMap) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData)

Aggregations

SelectorData (org.kie.workbench.common.forms.dynamic.model.config.SelectorData)12 Test (org.junit.Test)7 Map (java.util.Map)5 Element (org.kie.workbench.common.stunner.core.graph.Element)5 FormEditorRenderingContext (org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TableColumnMeta (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.TableColumnMeta)2 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)2 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 Collectors (java.util.stream.Collectors)1 Dependent (javax.enterprise.context.Dependent)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang3.StringUtils)1 DataObjectFinderService (org.kie.workbench.common.forms.data.modeller.service.DataObjectFinderService)1 AbstractDataObjectFinderTest (org.kie.workbench.common.forms.data.modeller.service.impl.AbstractDataObjectFinderTest)1 SystemSelectorDataProvider (org.kie.workbench.common.forms.dynamic.model.config.SystemSelectorDataProvider)1 FormRenderingContext (org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext)1 SelectorFieldBaseDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.SelectorFieldBaseDefinition)1