Search in sources :

Example 1 with HasPlaceHolder

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

the class DataObjectFormModelHandlerTest method checkCommonProperties.

private FieldDefinition checkCommonProperties(String dataFieldName) {
    ObjectProperty dataField = dataObject.getProperty(dataFieldName);
    FieldDefinition formField = fieldManager.getDefinitionByModelProperty(formModel.getProperty(dataFieldName));
    String dataFieldClassName = dataField.getClassName();
    TypeInfo fieldTypeInfo = formField.getFieldTypeInfo();
    // test common properties
    assertEquals(dataFieldClassName, fieldTypeInfo.getClassName());
    assertNotEquals(TypeKind.ENUM, fieldTypeInfo.getType());
    assertEquals(dataField.isMultiple(), fieldTypeInfo.isMultiple());
    assertEquals(dataField.getName().toLowerCase(), formField.getLabel().toLowerCase());
    assertEquals(dataField.getName(), formField.getBinding());
    assertEquals(dataFieldClassName, formField.getStandaloneClassName());
    assertFalse(formField.getReadOnly());
    assertFalse(formField.getRequired());
    assertTrue(formField.getValidateOnChange());
    // test interface specific properties
    if (formField instanceof HasPlaceHolder) {
        assertEquals(dataField.getName().toLowerCase(), ((HasPlaceHolder) formField).getPlaceHolder().toLowerCase());
    }
    if (formField instanceof HasMaxLength) {
        long maxLength = ((HasMaxLength) formField).getMaxLength();
        assertTrue(formField instanceof CharacterBoxFieldDefinition ? maxLength == 1 : maxLength == 100);
    }
    return formField;
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) HasMaxLength(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasMaxLength) CharacterBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.CharacterBoxFieldDefinition) HasPlaceHolder(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasPlaceHolder) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) CharacterBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.CharacterBoxFieldDefinition) DecimalBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition) CheckBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition) IntegerBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) DatePickerFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) TypeInfo(org.kie.workbench.common.forms.model.TypeInfo)

Example 2 with HasPlaceHolder

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

the class AbstractFieldManager method getDefinitionByModelProperty.

@Override
public FieldDefinition getDefinitionByModelProperty(ModelProperty modelProperty) {
    FieldTypeEntry fieldTypeEntry = (FieldTypeEntry) modelProperty.getMetaData().getEntry(FieldTypeEntry.NAME);
    FieldDefinition fieldDefinition = null;
    if (fieldTypeEntry != null) {
        fieldDefinition = getFieldFromProvider(fieldTypeEntry.getValue(), modelProperty.getTypeInfo());
    }
    if (fieldDefinition == null) {
        Optional<FieldDefinition> optional = Optional.ofNullable(getDefinitionByDataType(modelProperty.getTypeInfo()));
        if (optional.isPresent()) {
            fieldDefinition = optional.get();
        }
    }
    if (fieldDefinition != null) {
        fieldDefinition.setName(modelProperty.getName());
        fieldDefinition.setBinding(modelProperty.getName());
        String label = modelProperty.getName();
        label = label.substring(0, 1).toUpperCase() + label.substring(1);
        fieldDefinition.setLabel(label);
        fieldDefinition.setStandaloneClassName(modelProperty.getTypeInfo().getClassName());
        if (fieldDefinition instanceof HasPlaceHolder) {
            ((HasPlaceHolder) fieldDefinition).setPlaceHolder(label);
        }
        for (MetaDataEntry entry : modelProperty.getMetaData().getEntries()) {
            MetaDataEntryProcessor processor = metaDataEntryManager.getProcessorForEntry(entry);
            if (processor != null && processor.supports(fieldDefinition)) {
                processor.process(entry, fieldDefinition);
            }
        }
        return fieldDefinition;
    }
    return null;
}
Also used : HasPlaceHolder(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasPlaceHolder) FieldTypeEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldTypeEntry) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) SubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition) MultipleSubFormFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition) MetaDataEntryProcessor(org.kie.workbench.common.forms.service.shared.meta.processing.MetaDataEntryProcessor) MetaDataEntry(org.kie.workbench.common.forms.model.MetaDataEntry)

Example 3 with HasPlaceHolder

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

the class FormEditorHelper method getFormField.

public FieldDefinition getFormField(String fieldId) {
    FieldDefinition result = content.getDefinition().getFieldById(fieldId);
    if (result == null) {
        result = availableFields.get(fieldId);
        if (result == null) {
            if (unbindedFields.containsKey(fieldId)) {
                Pair<EditorFieldLayoutComponent, FieldDefinition> pair = unbindedFields.get(fieldId);
                result = pair.getK2();
                result.setLabel(result.getFieldType().getTypeName());
                if (result instanceof HasPlaceHolder) {
                    ((HasPlaceHolder) result).setPlaceHolder(result.getFieldType().getTypeName());
                }
                unbindedFields.remove(result.getId());
                FieldDefinition newField = fieldManager.getDefinitionByFieldType(result.getFieldType());
                newField.setName(generateUnboundFieldName(newField));
                EditorFieldLayoutComponent component = pair.getK1();
                component.init(content.getRenderingContext(), newField);
                unbindedFields.put(newField.getId(), new Pair<>(component, newField));
            }
        }
    }
    return result;
}
Also used : HasPlaceHolder(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasPlaceHolder) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) EditorFieldLayoutComponent(org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent)

Aggregations

HasPlaceHolder (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasPlaceHolder)3 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)3 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)2 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)2 EditorFieldLayoutComponent (org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent)1 HasMaxLength (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasMaxLength)1 CheckBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition)1 DatePickerFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition)1 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)1 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)1 CharacterBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.CharacterBoxFieldDefinition)1 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)1 MetaDataEntry (org.kie.workbench.common.forms.model.MetaDataEntry)1 TypeInfo (org.kie.workbench.common.forms.model.TypeInfo)1 FieldTypeEntry (org.kie.workbench.common.forms.model.impl.meta.entries.FieldTypeEntry)1 MetaDataEntryProcessor (org.kie.workbench.common.forms.service.shared.meta.processing.MetaDataEntryProcessor)1 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)1