Search in sources :

Example 36 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FieldManagerTest method testGetDefinitionByModelPropertyWithoutMetaData.

@Test
public void testGetDefinitionByModelPropertyWithoutMetaData() {
    FieldDefinition fieldDefinition = fieldManager.getDefinitionByModelProperty(property);
    Assertions.assertThat(fieldDefinition).isNotNull().isInstanceOf(TextBoxFieldDefinition.class).hasFieldOrPropertyWithValue("name", PROPERTY_NAME).hasFieldOrPropertyWithValue("label", PROPERTY_LABEL).hasFieldOrPropertyWithValue("placeHolder", PROPERTY_LABEL).hasFieldOrPropertyWithValue("required", Boolean.FALSE).hasFieldOrPropertyWithValue("readOnly", Boolean.FALSE).hasFieldOrPropertyWithValue("binding", PROPERTY_NAME);
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) Test(org.junit.Test)

Example 37 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FormModelSynchronizationUtilImpl method addNewField.

protected void addNewField(ModelProperty newProperty, Function<ModelProperty, FieldDefinition> fieldProviderFunction) {
    if (!Optional.ofNullable(form.getFieldByBinding(newProperty.getName())).isPresent()) {
        logger.info("Adding new form field for variable '" + newProperty.getName() + "'.");
        FieldDefinition newField = fieldProviderFunction.apply(newProperty);
        form.getFields().add(newField);
    }
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition)

Example 38 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FormEditorHelper method initHelper.

public void initHelper(FormModelerContent content) {
    this.content = content;
    if (unbindedFields != null && !unbindedFields.isEmpty()) {
        return;
    }
    for (FieldType baseType : enabledPaletteFieldTypes) {
        EditorFieldLayoutComponent layoutComponent = editorFieldLayoutComponents.get();
        if (layoutComponent != null) {
            FieldDefinition field = fieldManager.getDefinitionByFieldType(baseType);
            field.setName(generateUnboundFieldName(field));
            layoutComponent.init(content.getRenderingContext(), field);
            unbindedFields.put(field.getId(), new Pair<>(layoutComponent, field));
        }
    }
    addAvailableFields();
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) EditorFieldLayoutComponent(org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent) FieldType(org.kie.workbench.common.forms.model.FieldType)

Example 39 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FormEditorHelper method switchToField.

public FieldDefinition switchToField(FieldDefinition originalField, String newBinding) {
    if (newBinding != null && !"".equals(newBinding)) {
        Optional<FieldDefinition> availableFieldOptional = availableFields.values().stream().filter(availableField -> availableField.getBinding().equals(newBinding)).findFirst();
        if (availableFieldOptional.isPresent()) {
            FieldDefinition availableField = availableFieldOptional.get();
            FieldDefinition resultField = fieldManager.getFieldFromProvider(originalField.getFieldType().getTypeName(), availableField.getFieldTypeInfo());
            if (resultField == null) {
                // this happens when trying to bind to a property which is of an unsupported type for the current FieldFefintion
                resultField = fieldManager.getFieldFromProvider(availableField.getFieldType().getTypeName(), availableField.getFieldTypeInfo());
            }
            resultField.copyFrom(originalField);
            resultField.setId(availableField.getId());
            resultField.setName(availableField.getName());
            resultField.setStandaloneClassName(availableField.getStandaloneClassName());
            resultField.setBinding(newBinding);
            return resultField;
        }
    }
    // If we arrive here is because we have a dynamic binding or we are unbinding a field
    FieldDefinition resultField = fieldManager.getFieldFromProvider(originalField.getFieldType().getTypeName(), originalField.getFieldTypeInfo());
    if (newBinding == null || newBinding.equals("")) {
        // unbinding a field
        resultField.setName(generateUnboundFieldName(resultField));
        resultField.setBinding("");
    }
    resultField.copyFrom(originalField);
    resultField.setBinding(newBinding);
    if (resultField.getName() == null) {
        // edge case we only get here with dynamic bindings
        resultField.setName(newBinding);
    }
    return resultField;
}
Also used : HasPlaceHolder(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.HasPlaceHolder) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) FormModelerContent(org.kie.workbench.common.forms.editor.model.FormModelerContent) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) FieldType(org.kie.workbench.common.forms.model.FieldType) EditorFieldLayoutComponent(org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent) Map(java.util.Map) FormEditorRenderingContext(org.kie.workbench.common.forms.editor.service.shared.FormEditorRenderingContext) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) FieldManager(org.kie.workbench.common.forms.service.shared.FieldManager) Pair(org.uberfire.commons.data.Pair) IOC(org.jboss.errai.ioc.client.container.IOC) Collection(java.util.Collection) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) FormModel(org.kie.workbench.common.forms.model.FormModel) Dependent(javax.enterprise.context.Dependent) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) Comparator(java.util.Comparator) SyncBeanDef(org.jboss.errai.ioc.client.container.SyncBeanDef) FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition)

Example 40 with FieldDefinition

use of org.kie.workbench.common.forms.model.FieldDefinition in project kie-wb-common by kiegroup.

the class FormEditorPresenter method removeAllDraggableGroupComponent.

protected void removeAllDraggableGroupComponent(Collection<FieldDefinition> fields) {
    String groupId = translationService.getTranslation(FormEditorConstants.FormEditorPresenterModelFields);
    Iterator<FieldDefinition> it = fields.iterator();
    while (it.hasNext()) {
        FieldDefinition field = it.next();
        if (layoutDragComponentPalette.hasDraggableComponent(groupId, field.getId())) {
            layoutDragComponentPalette.removeDraggableComponent(groupId, field.getId());
        }
    }
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition)

Aggregations

FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)85 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)42 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)29 Test (org.junit.Test)27 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)24 TextAreaFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition)22 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)21 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)20 CheckBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition)18 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)17 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)14 DatePickerFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.datePicker.definition.DatePickerFieldDefinition)13 ArrayList (java.util.ArrayList)11 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)9 LayoutComponent (org.uberfire.ext.layout.editor.api.editor.LayoutComponent)8 Form (org.kie.workbench.common.forms.migration.legacy.model.Form)7 ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)7 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)7 LayoutColumn (org.uberfire.ext.layout.editor.api.editor.LayoutColumn)7 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)7