Search in sources :

Example 16 with MetaProperty

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);
    }
}
Also used : Length(org.hibernate.validator.constraints.Length) Size(javax.validation.constraints.Size) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 17 with MetaProperty

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;
    }
}
Also used : MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Property(com.vaadin.v7.data.Property) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Nullable(javax.annotation.Nullable)

Example 18 with MetaProperty

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();
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 19 with MetaProperty

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;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) Column(io.jmix.ui.component.DataGrid.Column) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 20 with MetaProperty

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);
            }
        });
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Aggregations

MetaProperty (io.jmix.core.metamodel.model.MetaProperty)267 MetaClass (io.jmix.core.metamodel.model.MetaClass)162 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)53 Nullable (javax.annotation.Nullable)36 Range (io.jmix.core.metamodel.model.Range)23 Autowired (org.springframework.beans.factory.annotation.Autowired)23 Collectors (java.util.stream.Collectors)22 java.util (java.util)20 Component (org.springframework.stereotype.Component)18 Entity (io.jmix.core.Entity)17 EntityValues (io.jmix.core.entity.EntityValues)17 io.jmix.core (io.jmix.core)16 Logger (org.slf4j.Logger)15 LoggerFactory (org.slf4j.LoggerFactory)15 ArrayList (java.util.ArrayList)12 Collection (java.util.Collection)12 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)10 Metadata (io.jmix.core.Metadata)9 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8