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);
}
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);
}
}
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();
}
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;
}
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());
}
}
}
Aggregations