Search in sources :

Example 71 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class AbstractTableLoader method loadColumn.

protected Table.Column loadColumn(Element element, Datasource ds) {
    String id = element.attributeValue("id");
    MetaPropertyPath metaPropertyPath = AppBeans.get(MetadataTools.NAME, MetadataTools.class).resolveMetaPropertyPath(ds.getMetaClass(), id);
    Table.Column column = new Table.Column(metaPropertyPath != null ? metaPropertyPath : id);
    String editable = element.attributeValue("editable");
    if (StringUtils.isNotEmpty(editable)) {
        column.setEditable(Boolean.parseBoolean(editable));
    }
    String collapsed = element.attributeValue("collapsed");
    if (StringUtils.isNotEmpty(collapsed)) {
        column.setCollapsed(Boolean.parseBoolean(collapsed));
    }
    String groupAllowed = element.attributeValue("groupAllowed");
    if (StringUtils.isNotEmpty(groupAllowed)) {
        column.setGroupAllowed(Boolean.parseBoolean(groupAllowed));
    }
    String sortable = element.attributeValue("sortable");
    if (StringUtils.isNotEmpty(sortable)) {
        column.setSortable(Boolean.parseBoolean(sortable));
    }
    loadCaption(column, element);
    loadDescription(column, element);
    if (column.getCaption() == null) {
        String columnCaption;
        if (column.getId() instanceof MetaPropertyPath) {
            MetaPropertyPath mpp = (MetaPropertyPath) column.getId();
            MetaProperty metaProperty = mpp.getMetaProperty();
            String propertyName = metaProperty.getName();
            if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
                CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
                columnCaption = LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames()) ? categoryAttribute.getLocaleName() : StringUtils.capitalize(categoryAttribute.getName());
            } else {
                MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(mpp);
                columnCaption = messageTools.getPropertyCaption(propertyMetaClass, propertyName);
            }
        } else {
            Class<?> declaringClass = ds.getMetaClass().getJavaClass();
            String className = declaringClass.getName();
            int i = className.lastIndexOf('.');
            if (i > -1)
                className = className.substring(i + 1);
            columnCaption = messages.getMessage(declaringClass, className + "." + id);
        }
        column.setCaption(columnCaption);
    }
    column.setXmlDescriptor(element);
    if (metaPropertyPath != null)
        column.setType(metaPropertyPath.getRangeJavaClass());
    String width = loadThemeString(element.attributeValue("width"));
    if (!StringUtils.isBlank(width)) {
        if (StringUtils.endsWith(width, "px")) {
            width = StringUtils.substring(width, 0, width.length() - 2);
        }
        try {
            column.setWidth(Integer.parseInt(width));
        } catch (NumberFormatException e) {
            throw new GuiDevelopmentException("Property 'width' must contain only numeric value", context.getCurrentFrameId(), "width", element.attributeValue("width"));
        }
    }
    String align = element.attributeValue("align");
    if (StringUtils.isNotBlank(align)) {
        column.setAlignment(Table.ColumnAlignment.valueOf(align));
    }
    column.setFormatter(loadFormatter(element));
    loadAggregation(column, element);
    loadCalculatable(column, element);
    loadMaxTextLength(column, element);
    return column;
}
Also used : MetadataTools(com.haulmont.cuba.core.global.MetadataTools) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 72 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class WebGroupTable method applyColumnSettings.

@Override
public void applyColumnSettings(Element element) {
    super.applyColumnSettings(element);
    final Element groupPropertiesElement = element.element("groupProperties");
    if (groupPropertiesElement != null) {
        final List elements = groupPropertiesElement.elements("property");
        final List<MetaPropertyPath> properties = new ArrayList<>(elements.size());
        for (final Object o : elements) {
            final MetaPropertyPath property = datasource.getMetaClass().getPropertyPath(((Element) o).attributeValue("id"));
            properties.add(property);
        }
        groupBy(properties.toArray());
    }
}
Also used : Element(org.dom4j.Element) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 73 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class WebLabel method resolveMetaPropertyPath.

protected MetaPropertyPath resolveMetaPropertyPath(MetaClass metaClass, String property) {
    MetaPropertyPath metaPropertyPath = AppBeans.get(MetadataTools.NAME, MetadataTools.class).resolveMetaPropertyPath(metaClass, property);
    Preconditions.checkNotNullArgument(metaPropertyPath, "Could not resolve property path '%s' in '%s'", property, metaClass);
    return metaPropertyPath;
}
Also used : MetadataTools(com.haulmont.cuba.core.global.MetadataTools) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 74 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class WebLookupField method tryToAssignCaptionProperty.

protected void tryToAssignCaptionProperty() {
    if (optionsDatasource != null && captionProperty != null && getCaptionMode() == CaptionMode.PROPERTY) {
        MetaPropertyPath propertyPath = optionsDatasource.getMetaClass().getPropertyPath(captionProperty);
        if (propertyPath != null && component.getContainerDataSource() != null) {
            ((LookupOptionsDsWrapper) component.getContainerDataSource()).addProperty(propertyPath);
            component.setItemCaptionPropertyId(propertyPath);
        } else {
            throw new IllegalArgumentException(String.format("Can't find property for given caption property: %s", captionProperty));
        }
    }
}
Also used : MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 75 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.

the class WebPickerField method checkDatasourceProperty.

public void checkDatasourceProperty(Datasource datasource, String property) {
    Preconditions.checkNotNullArgument(datasource);
    Preconditions.checkNotNullArgument(property);
    MetaPropertyPath metaPropertyPath = getResolvedMetaPropertyPath(datasource.getMetaClass(), property);
    if (!metaPropertyPath.getRange().isClass()) {
        throw new DevelopmentException(String.format("property '%s.%s' should have Entity type", datasource.getMetaClass().getName(), property));
    }
}
Also used : MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Aggregations

MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)84 MetaClass (com.haulmont.chile.core.model.MetaClass)34 MetaProperty (com.haulmont.chile.core.model.MetaProperty)27 Element (org.dom4j.Element)16 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)11 Entity (com.haulmont.cuba.core.entity.Entity)9 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)9 Datasource (com.haulmont.cuba.gui.data.Datasource)6 Table (com.haulmont.cuba.gui.components.Table)5 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 MessageTools (com.haulmont.cuba.core.global.MessageTools)4 Instance (com.haulmont.chile.core.model.Instance)3 Op (com.haulmont.cuba.core.global.filter.Op)3 FocusableTable (com.haulmont.cuba.desktop.sys.vcl.FocusableTable)3 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 Formatter (com.haulmont.cuba.gui.components.Formatter)3 Window (com.haulmont.cuba.gui.components.Window)3 CollectionFormatter (com.haulmont.cuba.gui.components.formatters.CollectionFormatter)3 GroupInfo (com.haulmont.cuba.gui.data.GroupInfo)3 java.util (java.util)3