use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class DataAwareComponentsTools method setupMaxLength.
/**
* Sets max length for textual UI component using Entity metadata.
*
* @param component UI component
* @param valueSource value source
*/
public void setupMaxLength(TextInputField.MaxLengthLimited component, EntityValueSource valueSource) {
MetaProperty metaProperty = valueSource.getMetaPropertyPath().getMetaProperty();
Map<String, Object> annotations = metaProperty.getAnnotations();
Integer maxLength = (Integer) annotations.get(MetadataTools.LENGTH_ANN_NAME);
if (maxLength != null) {
component.setMaxLength(maxLength);
}
Integer sizeMax = (Integer) annotations.get(Size.class.getName() + "_max");
if (sizeMax != null) {
component.setMaxLength(sizeMax);
}
Integer lengthMax = (Integer) annotations.get(Length.class.getName() + "_max");
if (lengthMax != null) {
component.setMaxLength(lengthMax);
}
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class AbbreviatedColumnGenerator method generateCell.
@Nullable
@Override
public Object generateCell(com.vaadin.v7.ui.Table source, Object itemId, Object columnId) {
Property property = source.getItem(itemId).getItemProperty(columnId);
Object value = property.getValue();
if (value == null) {
return null;
}
MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
String stringValue = metadataTools.format(value, metaProperty);
String cellValue = stringValue;
boolean isMultiLineCell = StringUtils.contains(stringValue, "\n");
if (isMultiLineCell) {
cellValue = StringUtils.replaceChars(cellValue, '\n', ' ');
}
int maxTextLength = column.getMaxTextLength();
if (stringValue.length() > maxTextLength + MAX_TEXT_LENGTH_GAP || isMultiLineCell) {
return StringUtils.abbreviate(cellValue, maxTextLength);
} else {
return cellValue;
}
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class PropertyFilterSupport method getPropertyFilterCaption.
/**
* Returns default caption for {@link PropertyFilter}.
*
* @param metaClass an entity meta class associated with property filter
* @param property an entity attribute associated with property filter
*/
public String getPropertyFilterCaption(MetaClass metaClass, String property) {
MetaPropertyPath mpp = metadataTools.resolveMetaPropertyPathOrNull(metaClass, property);
if (mpp == null) {
return property;
} else {
MetaProperty[] metaProperties = mpp.getMetaProperties();
StringBuilder sb = new StringBuilder();
MetaPropertyPath parentMpp = null;
MetaClass tempMetaClass;
for (int i = 0; i < metaProperties.length; i++) {
if (i == 0) {
parentMpp = new MetaPropertyPath(metaClass, metaProperties[i]);
tempMetaClass = metaClass;
} else {
parentMpp = new MetaPropertyPath(parentMpp, metaProperties[i]);
tempMetaClass = metadataTools.getPropertyEnclosingMetaClass(parentMpp);
}
sb.append(messageTools.getPropertyCaption(tempMetaClass, metaProperties[i].getName()));
if (i < metaProperties.length - 1) {
sb.append(".");
}
}
return sb.toString();
}
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class AbstractDataGridLoader method loadColumn.
protected Column loadColumn(DataGrid component, Element element, MetaClass metaClass) {
String id = element.attributeValue("id");
String property = element.attributeValue("property");
if (id == null) {
if (property != null) {
id = property;
} else {
throw new GuiDevelopmentException("A column must have whether id or property specified", context, "DataGrid ID", component.getId());
}
}
Column column;
if (property != null) {
MetaPropertyPath metaPropertyPath = getMetadataTools().resolveMetaPropertyPathOrNull(metaClass, property);
column = component.addColumn(id, metaPropertyPath);
} else {
column = component.addColumn(id, null);
}
String expandRatio = element.attributeValue("expandRatio");
if (StringUtils.isNotEmpty(expandRatio)) {
column.setExpandRatio(Integer.parseInt(expandRatio));
}
String collapsed = element.attributeValue("collapsed");
if (StringUtils.isNotEmpty(collapsed)) {
column.setCollapsed(Boolean.parseBoolean(collapsed));
}
String collapsible = element.attributeValue("collapsible");
if (StringUtils.isNotEmpty(collapsible)) {
column.setCollapsible(Boolean.parseBoolean(collapsible));
}
String collapsingToggleCaption = element.attributeValue("collapsingToggleCaption");
if (StringUtils.isNotEmpty(collapsingToggleCaption)) {
collapsingToggleCaption = loadResourceString(collapsingToggleCaption);
column.setCollapsingToggleCaption(collapsingToggleCaption);
}
String sortable = element.attributeValue("sortable");
if (StringUtils.isNotEmpty(sortable)) {
column.setSortable(Boolean.parseBoolean(sortable));
}
String resizable = element.attributeValue("resizable");
if (StringUtils.isNotEmpty(resizable)) {
column.setResizable(Boolean.parseBoolean(resizable));
}
String editable = element.attributeValue("editable");
if (StringUtils.isNotEmpty(editable)) {
column.setEditable(Boolean.parseBoolean(editable));
}
String sort = element.attributeValue("sort");
if (StringUtils.isNotBlank(sort)) {
loadColumnSort(component, column, sort);
}
String caption = loadCaption(element);
if (caption == null) {
String columnCaption;
if (column.getPropertyPath() != null) {
MetaProperty metaProperty = column.getPropertyPath().getMetaProperty();
String propertyName = metaProperty.getName();
MetaClass propertyMetaClass = getMetadataTools().getPropertyEnclosingMetaClass(column.getPropertyPath());
columnCaption = getMessageTools().getPropertyCaption(propertyMetaClass, propertyName);
} else {
Class<?> declaringClass = metaClass.getJavaClass();
String className = declaringClass.getName();
int i = className.lastIndexOf('.');
if (i > -1) {
className = className.substring(i + 1);
}
columnCaption = getMessages().getMessage(declaringClass, className + "." + id);
}
column.setCaption(columnCaption);
} else {
column.setCaption(caption);
}
((Component.HasXmlDescriptor) column).setXmlDescriptor(element);
Integer width = loadSizeInPx(element, "width");
if (width != null) {
column.setWidth(width);
}
Integer minimumWidth = loadSizeInPx(element, "minimumWidth");
if (minimumWidth != null) {
column.setMinimumWidth(minimumWidth);
}
Integer maximumWidth = loadSizeInPx(element, "maximumWidth");
if (maximumWidth != null) {
column.setMaximumWidth(maximumWidth);
}
loadColumnVisualDisplay(column, element);
loadAggregation(column, element);
return column;
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class RuntimePropertiesFrame method loadEditable.
protected void loadEditable(FieldGroup fieldGroup, FieldGroup.FieldConfig field) {
if (fieldGroup.isEditable()) {
MetaClass metaClass = rds.resolveCategorizedEntityClass();
getAttributeByPropertyName(metaClass, field.getProperty()).ifPresent(attribute -> {
MetaProperty metaProperty = attribute.getMetaProperty();
MetaPropertyPath propertyPath = new MetaPropertyPath(metaClass, metaProperty);
boolean editableFromPermissions = security.isEntityAttrUpdatePermitted(metaClass, propertyPath.toString());
if (!editableFromPermissions) {
field.setEditable(false);
}
boolean visibleFromPermissions = security.isEntityAttrReadPermitted(metaClass, propertyPath.toString());
if (!visibleFromPermissions) {
field.setVisible(false);
}
});
}
}
Aggregations