Search in sources :

Example 21 with ModelProperty

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

the class FormModelSynchronizationUtilImplTest method testRemoveModelProperties.

@Test
public void testRemoveModelProperties() {
    ModelProperty name = formModel.getProperty("name");
    assertNotNull(name);
    formModelSynchronizationResult.getRemovedProperties().add(name);
    ModelProperty surname = formModel.getProperty("surname");
    assertNotNull(surname);
    formModelSynchronizationResult.getRemovedProperties().add(surname);
    ModelProperty birthday = formModel.getProperty("birthday");
    assertNotNull(birthday);
    formModelSynchronizationResult.getRemovedProperties().add(birthday);
    synchronizationUtil.init(form, formModelSynchronizationResult);
    int originalFormFields = form.getFields().size();
    synchronizationUtil.fixRemovedFields();
    assertEquals(originalFormFields, form.getFields().size());
    assertNull(form.getFieldByBinding(name.getName()));
    assertNull(form.getFieldByBinding(surname.getName()));
    assertNull(form.getFieldByBinding(birthday.getName()));
    FieldDefinition field = form.getFieldByName(name.getName());
    assertNotNull(field);
    assertNull(field.getBinding());
    field = form.getFieldByName(surname.getName());
    assertNotNull(field);
    assertNull(field.getBinding());
    field = form.getFieldByName(birthday.getName());
    assertNotNull(field);
    assertNull(field.getBinding());
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) 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) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) Test(org.junit.Test)

Example 22 with ModelProperty

use of org.kie.workbench.common.forms.model.ModelProperty 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 23 with ModelProperty

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

the class FormDefinitionGeneratorImplTest method checkTaskFormModel.

private void checkTaskFormModel(TaskFormModel formModel, String taskName, boolean readOnly) {
    Assertions.assertThat(formModel).hasFieldOrPropertyWithValue("processId", PROCESS_ID).hasFieldOrPropertyWithValue("taskName", taskName);
    Assertions.assertThat(formModel.getProperties()).isNotEmpty().hasSize(VARIABLES.size());
    VARIABLES.forEach((key, value) -> {
        ModelProperty property = formModel.getProperty(key);
        assertNotNull(property);
        assertEquals(value, property.getTypeInfo().getClassName());
        MetaDataEntry readOnlyEntry = property.getMetaData().getEntry(FieldReadOnlyEntry.NAME);
        Assertions.assertThat(readOnlyEntry).isNotNull().isInstanceOf(FieldReadOnlyEntry.class).hasFieldOrPropertyWithValue("value", readOnly);
    });
}
Also used : FieldReadOnlyEntry(org.kie.workbench.common.forms.model.impl.meta.entries.FieldReadOnlyEntry) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) MetaDataEntry(org.kie.workbench.common.forms.model.MetaDataEntry)

Example 24 with ModelProperty

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

the class FormDefinitionGenerator method updateNestedFormsModelProperties.

private void updateNestedFormsModelProperties(FormDefinition newFormDefinition, FieldDefinition nestedFormField, Form nestedForm) {
    nestedFormField.setStandaloneClassName(nestedForm.getHolders().iterator().next().getClassName());
    FormModel model = newFormDefinition.getModel();
    ModelProperty modelProperty = model.getProperty(nestedFormField.getBinding());
    if (modelProperty != null) {
        model.getProperties().remove(modelProperty);
        ModelPropertyImpl newProperty = new ModelPropertyImpl(nestedFormField.getBinding(), nestedFormField.getFieldTypeInfo());
        newProperty.getMetaData().getEntries().addAll(modelProperty.getMetaData().getEntries());
        model.getProperties().add(newProperty);
    }
}
Also used : FormModel(org.kie.workbench.common.forms.model.FormModel) ModelProperty(org.kie.workbench.common.forms.model.ModelProperty) ModelPropertyImpl(org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)

Aggregations

ModelProperty (org.kie.workbench.common.forms.model.ModelProperty)24 ArrayList (java.util.ArrayList)11 ModelPropertyImpl (org.kie.workbench.common.forms.model.impl.ModelPropertyImpl)11 TypeInfoImpl (org.kie.workbench.common.forms.model.impl.TypeInfoImpl)11 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)8 Test (org.junit.Test)7 FormDefinition (org.kie.workbench.common.forms.model.FormDefinition)7 TaskFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel)5 FormGenerationResult (org.kie.workbench.common.forms.jbpm.server.service.formGeneration.FormGenerationResult)4 HashMap (java.util.HashMap)3 CheckBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.checkBox.definition.CheckBoxFieldDefinition)3 IntegerBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.integerBox.definition.IntegerBoxFieldDefinition)3 TextBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition)3 BusinessProcessFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel)3 FormModel (org.kie.workbench.common.forms.model.FormModel)3 FieldReadOnlyEntry (org.kie.workbench.common.forms.model.impl.meta.entries.FieldReadOnlyEntry)3 List (java.util.List)2 Optional (java.util.Optional)2 Dependent (javax.enterprise.context.Dependent)2 Inject (javax.inject.Inject)2