Search in sources :

Example 71 with FieldDefinition

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

Example 72 with FieldDefinition

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

the class FormEditorHelper method switchToFieldType.

public FieldDefinition switchToFieldType(FieldDefinition field, String fieldCode) {
    FieldDefinition resultDefinition = fieldManager.getFieldFromProvider(fieldCode, field.getFieldTypeInfo());
    resultDefinition.copyFrom(field);
    resultDefinition.setId(field.getId());
    resultDefinition.setName(field.getName());
    removeField(field.getId(), false);
    return resultDefinition;
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition)

Example 73 with FieldDefinition

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

the class FormEditorHelper method removeField.

public void removeField(String fieldId, boolean addToAvailables) {
    FormDefinition formDefinition = content.getDefinition();
    FieldDefinition fieldToRemove = formDefinition.getFieldById(fieldId);
    if (fieldToRemove != null) {
        formDefinition.getFields().remove(fieldToRemove);
        if (addToAvailables) {
            FieldDefinition originalField = fieldToRemove;
            if (fieldToRemove.getBinding() == null) {
                return;
            }
            ModelProperty property = formDefinition.getModel().getProperty(fieldToRemove.getBinding());
            fieldToRemove = fieldManager.getDefinitionByModelProperty(property);
            fieldToRemove.setId(originalField.getId());
            availableFields.put(fieldToRemove.getId(), fieldToRemove);
        }
    }
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition)

Example 74 with FieldDefinition

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

the class FormEditorPresenter method addAllDraggableGroupComponent.

protected void addAllDraggableGroupComponent(Collection<FieldDefinition> fields) {
    String groupId = translationService.getTranslation(FormEditorConstants.FormEditorPresenterModelFields);
    Iterator<FieldDefinition> it = fields.iterator();
    while (it.hasNext()) {
        FieldDefinition field = it.next();
        EditorFieldLayoutComponent layoutFieldComponent = editorFieldLayoutComponents.get();
        if (layoutFieldComponent != null) {
            layoutFieldComponent.init(editorHelper.getRenderingContext(), field);
            layoutDragComponentPalette.addDraggableComponent(groupId, field.getId(), layoutFieldComponent);
        }
    }
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) EditorFieldLayoutComponent(org.kie.workbench.common.forms.editor.client.editor.rendering.EditorFieldLayoutComponent)

Example 75 with FieldDefinition

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

the class ChangesNotificationDisplayer method checkNewModelFields.

protected void checkNewModelFields() {
    FormModelSynchronizationResult synchronizationResult = content.getSynchronizationResult();
    if (synchronizationResult != null && synchronizationResult.hasNewProperties()) {
        Set<FieldDefinition> modelFields = synchronizationResult.getNewProperties().stream().filter(modelProperty -> content.getDefinition().getFieldByBinding(modelProperty.getName()) == null).map(fieldManager::getDefinitionByModelProperty).collect(Collectors.toSet());
        if (!modelFields.isEmpty()) {
            this.canDisplay = true;
            newPropertiesDisplayer.showAvailableFields(modelFields);
            view.getElement().appendChild(newPropertiesDisplayer.getElement());
        }
    }
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) FormModelSynchronizationResult(org.kie.workbench.common.forms.editor.model.FormModelSynchronizationResult)

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