use of io.jmix.dynattr.AttributeDefinition in project jmix by jmix-framework.
the class DynAttrMetaPropertyPathResolver method resolveMetaPropertyPath.
@Override
public MetaPropertyPath resolveMetaPropertyPath(MetaClass metaClass, String propertyPath) {
String[] properties = propertyPath.split("\\.");
MetaProperty[] metaProperties = new MetaProperty[properties.length];
MetaProperty currentProperty;
MetaClass currentClass = metaClass;
for (int i = 0; i < properties.length; i++) {
if (currentClass == null) {
return null;
}
currentProperty = currentClass.findProperty(properties[i]);
if (currentProperty == null) {
if (!DynAttrUtils.isDynamicAttributeProperty(properties[i])) {
return null;
}
AttributeDefinition attribute = dynAttrMetadata.getAttributeByCode(currentClass, DynAttrUtils.getAttributeCodeFromProperty(properties[i])).orElse(null);
if (attribute == null) {
return null;
}
currentProperty = attribute.getMetaProperty();
}
Range range = currentProperty.getRange();
currentClass = range.isClass() ? range.asClass() : null;
metaProperties[i] = currentProperty;
}
return new MetaPropertyPath(metaClass, metaProperties);
}
use of io.jmix.dynattr.AttributeDefinition in project jmix by jmix-framework.
the class ListEmbeddingStrategy method getColumnFormatter.
@SuppressWarnings("rawtypes")
protected Formatter getColumnFormatter(AttributeDefinition attribute) {
if (attribute.getDataType() == AttributeType.ENUMERATION) {
if (!attribute.isCollection()) {
return value -> {
if (value == null) {
return null;
} else {
return msgBundleTools.getLocalizedEnumeration(attribute.getEnumerationMsgBundle(), (String) value);
}
};
}
} else if (!Strings.isNullOrEmpty(attribute.getConfiguration().getNumberFormatPattern())) {
return value -> {
if (value == null) {
return null;
} else {
DecimalFormatSymbols symbols = new DecimalFormatSymbols(currentAuthentication.getLocale());
DecimalFormat format = new DecimalFormat(attribute.getConfiguration().getNumberFormatPattern(), symbols);
return format.format(value);
}
};
}
return null;
}
use of io.jmix.dynattr.AttributeDefinition in project jmix by jmix-framework.
the class DynamicAttributesPanel method addFieldsToForm.
protected void addFieldsToForm(Form newPropertiesForm, Map<AttributeDefinition, Component> fields) {
if (fields.keySet().stream().anyMatch(attr -> attr.getConfiguration().getColumnNumber() != null && attr.getConfiguration().getRowNumber() != null)) {
List<AttributeDefinition> attributesToAdd = fields.keySet().stream().filter(attr -> attr.getConfiguration().getColumnNumber() != null && attr.getConfiguration().getRowNumber() != null).collect(Collectors.toList());
int maxColumnIndex = attributesToAdd.stream().mapToInt(attr -> attr.getConfiguration().getColumnNumber()).max().orElse(0);
newPropertiesForm.setColumns(maxColumnIndex + 1);
for (int i = 0; i <= maxColumnIndex; i++) {
int columnIndex = i;
List<AttributeDefinition> columnAttributes = attributesToAdd.stream().filter(attr -> columnIndex == attr.getConfiguration().getColumnNumber()).sorted(Comparator.comparing(attr -> attr.getConfiguration().getRowNumber())).collect(Collectors.toList());
int currentRowNumber = 0;
for (AttributeDefinition attr : columnAttributes) {
while (attr.getConfiguration().getRowNumber() > currentRowNumber) {
// add empty row
newPropertiesForm.add(createEmptyComponent(), columnIndex, currentRowNumber);
currentRowNumber++;
}
newPropertiesForm.add(fields.get(attr), columnIndex, currentRowNumber);
currentRowNumber++;
}
}
} else {
int propertiesCount = getAttributesByCategory().size();
int rowsPerColumn = getRowsPerColumn(propertiesCount);
int columnNo = 0;
int fieldsCount = 0;
for (Component field : fields.values()) {
fieldsCount++;
newPropertiesForm.add(field, columnNo);
if (fieldsCount % rowsPerColumn == 0) {
columnNo++;
newPropertiesForm.setColumns(columnNo + 1);
}
}
}
}
use of io.jmix.dynattr.AttributeDefinition in project jmix by jmix-framework.
the class AttributeDefaultValues method initDefaultAttributeValues.
public void initDefaultAttributeValues(Object entity) {
MetaClass metaClass = metadata.getClass(entity);
Collection<AttributeDefinition> attributes = dynAttrMetadata.getAttributes(metaClass);
for (AttributeDefinition attribute : attributes) {
setDefaultAttributeValue(entity, attribute, timeSource.currentTimestamp());
}
}
use of io.jmix.dynattr.AttributeDefinition in project jmix by jmix-framework.
the class AttributeDependencies method getDependentAttributes.
public Set<AttributeDefinition> getDependentAttributes(AttributeDefinition attribute) {
Set<AttributeDefinition> dependentAttributes = new HashSet<>();
Collection<AttributeDefinition> attributes = dynAttrMetadata.getAttributes(attribute.getMetaProperty().getDomain());
for (AttributeDefinition currentAttribute : attributes) {
if (currentAttribute.getConfiguration().getDependsOnAttributeCodes() != null && !currentAttribute.getConfiguration().getDependsOnAttributeCodes().isEmpty()) {
List<AttributeDefinition> attributeDefinitions = currentAttribute.getConfiguration().getDependsOnAttributeCodes().stream().map(code -> dynAttrMetadata.getAttributeByCode(currentAttribute.getMetaProperty().getDomain(), code)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
if (attributeDefinitions.contains(attribute)) {
dependentAttributes.add(currentAttribute);
}
}
}
return dependentAttributes;
}
Aggregations