use of io.jmix.dynattr.AttributeDefinition in project jmix by jmix-framework.
the class FieldGroupLoader method loadDynamicAttributeFields.
protected List<FieldGroup.FieldConfig> loadDynamicAttributeFields(Datasource ds) {
if (ds != null && getMetadataTools().isJpaEntity(ds.getMetaClass())) {
String windowId = getWindowId(context);
Set<AttributeDefinition> attributes = getDynamicAttributesGuiTools().getAttributesToShowOnTheScreen(ds.getMetaClass(), windowId, resultComponent.getId());
if (!attributes.isEmpty()) {
List<FieldGroup.FieldConfig> fields = new ArrayList<>();
ds.setLoadDynamicAttributes(true);
for (AttributeDefinition attribute : attributes) {
FieldGroup.FieldConfig field = resultComponent.createField(DynAttrUtils.getPropertyFromAttributeCode(attribute.getCode()));
field.setProperty(DynAttrUtils.getPropertyFromAttributeCode(attribute.getCode()));
field.setCaption(getMessageBundleTools().getLocalizedValue(attribute.getNameMsgBundle(), attribute.getName()));
field.setDescription(getMessageBundleTools().getLocalizedValue(attribute.getDescriptionsMsgBundle(), attribute.getDescription()));
field.setDatasource(ds);
field.setRequired(attribute.isRequired());
field.setRequiredMessage(getMessages().formatMessage("", "validation.required.defaultMsg", getMessageBundleTools().getLocalizedValue(attribute.getNameMsgBundle(), attribute.getName())));
loadWidth(field, attribute.getConfiguration().getFormWidth());
if (!Boolean.TRUE.equals(attribute.isCollection())) {
Collection<Consumer<?>> validators = getDynamicAttributesGuiTools().createValidators(attribute);
if (validators != null && !validators.isEmpty()) {
for (Consumer<?> validator : validators) {
field.addValidator(validator);
}
}
}
fields.add(field);
}
getDynamicAttributesGuiTools().listenDynamicAttributesChanges(ds);
return fields;
}
}
return Collections.emptyList();
}
use of io.jmix.dynattr.AttributeDefinition in project jmix by jmix-framework.
the class DynAttrPropertyFilterComponentGenerationStrategy method createComponentInternal.
@Override
protected Component createComponentInternal(ComponentGenerationContext context, MetaClass metaClass, String propertyName) {
AttributeDefinition attribute = dynamicModelMetadata.getAttributeByCode(metaClass, DynAttrUtils.getAttributeCodeFromProperty(propertyName)).orElse(null);
if (attribute == null) {
return null;
}
PropertyFilterComponentGenerationContext pfContext = (PropertyFilterComponentGenerationContext) context;
PropertyFilter.Operation.Type type = pfContext.getOperation().getType();
Component resultComponent;
if (type == PropertyFilter.Operation.Type.UNARY) {
resultComponent = createUnaryField(context);
} else if (attribute.isCollection() || type == PropertyFilter.Operation.Type.LIST) {
resultComponent = createCollectionField(context, attribute);
} else if (attribute.getDataType() == ENTITY) {
resultComponent = createClassField(context, attribute);
} else if (type == PropertyFilter.Operation.Type.INTERVAL) {
resultComponent = createIntervalField(context);
} else {
resultComponent = createDatatypeField(context, attribute);
}
return resultComponent;
}
use of io.jmix.dynattr.AttributeDefinition in project jmix by jmix-framework.
the class DynamicAttributesPanel method initPropertiesForm.
protected void initPropertiesForm() {
propertiesForm.removeAll();
Map<AttributeDefinition, Component> fields = new HashMap<>();
for (AttributeDefinition attribute : getAttributesByCategory()) {
Component resultComponent = generateFieldComponent(attribute);
fields.put(attribute, resultComponent);
}
addFieldsToForm(propertiesForm, fields);
initFieldCaptionWidth(propertiesForm);
}
Aggregations