use of com.haulmont.cuba.gui.dynamicattributes.DynamicAttributeCustomFieldGenerator in project cuba by cuba-platform.
the class FieldGroupLoader method loadDynamicAttributeFields.
protected List<FieldGroup.FieldConfig> loadDynamicAttributeFields(Datasource ds) {
if (ds != null && metadataTools.isPersistent(ds.getMetaClass())) {
String windowId = ComponentsHelper.getWindow(resultComponent).getId();
Set<CategoryAttribute> attributesToShow = dynamicAttributesGuiTools.getAttributesToShowOnTheScreen(ds.getMetaClass(), windowId, resultComponent.getId());
if (!attributesToShow.isEmpty()) {
List<FieldGroup.FieldConfig> fields = new ArrayList<>();
ds.setLoadDynamicAttributes(true);
for (CategoryAttribute attribute : attributesToShow) {
FieldGroup.FieldConfig field = resultComponent.createField(DynamicAttributesUtils.encodeAttributeCode(attribute.getCode()));
field.setProperty(DynamicAttributesUtils.encodeAttributeCode(attribute.getCode()));
field.setCaption(attribute.getLocaleName());
field.setDatasource(ds);
field.setRequired(attribute.getRequired());
field.setRequiredMessage(messages.formatMainMessage("validation.required.defaultMsg", attribute.getLocaleName()));
loadWidth(field, attribute.getWidth());
// Currently, ListEditor does not support datasource binding so we create custom field
if (BooleanUtils.isTrue(attribute.getIsCollection())) {
CustomFieldGenerator fieldGenerator = new DynamicAttributeCustomFieldGenerator();
Component fieldComponent = fieldGenerator.generateField(ds, DynamicAttributesUtils.encodeAttributeCode(attribute.getCode()));
field.setCustom(true);
field.setComponent(fieldComponent);
applyPermissions(fieldComponent);
}
fields.add(field);
}
dynamicAttributesGuiTools.listenDynamicAttributesChanges(ds);
return fields;
}
}
return Collections.emptyList();
}
use of com.haulmont.cuba.gui.dynamicattributes.DynamicAttributeCustomFieldGenerator in project cuba by cuba-platform.
the class BulkEditorFieldFactory method createListEditorField.
protected Field createListEditorField(Datasource datasource, MetaProperty property) {
DynamicAttributeCustomFieldGenerator generator = new DynamicAttributeCustomFieldGenerator();
// noinspection UnnecessaryLocalVariable
ListEditor editor = (ListEditor) generator.generateField(datasource, property.getName());
return editor;
}
Aggregations