Search in sources :

Example 41 with MetaClass

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

the class AbstractComponentLoader method loadVisible.

protected boolean loadVisible(Component component, Element element) {
    if (component instanceof DatasourceComponent && ((DatasourceComponent) component).getDatasource() != null) {
        DatasourceComponent wiredComponent = (DatasourceComponent) component;
        MetaClass metaClass = wiredComponent.getDatasource().getMetaClass();
        MetaPropertyPath propertyPath = wiredComponent.getMetaPropertyPath();
        if (propertyPath != null && !security.isEntityAttrReadPermitted(metaClass, propertyPath.toString())) {
            component.setVisible(false);
            return false;
        }
    }
    String visible = element.attributeValue("visible");
    if (StringUtils.isNotEmpty(visible)) {
        boolean visibleValue = Boolean.parseBoolean(visible);
        component.setVisible(visibleValue);
        return visibleValue;
    }
    return true;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 42 with MetaClass

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

the class AbstractComponentLoader method loadEditable.

protected void loadEditable(Component component, Element element) {
    if (component instanceof Component.Editable) {
        if (component instanceof DatasourceComponent && ((DatasourceComponent) component).getDatasource() != null) {
            DatasourceComponent wiredComponent = (DatasourceComponent) component;
            MetaClass metaClass = wiredComponent.getDatasource().getMetaClass();
            MetaPropertyPath propertyPath = wiredComponent.getMetaPropertyPath();
            if (propertyPath != null && !security.isEntityAttrUpdatePermitted(metaClass, propertyPath.toString())) {
                ((Component.Editable) component).setEditable(false);
                return;
            }
        }
        final String editable = element.attributeValue("editable");
        if (!StringUtils.isEmpty(editable)) {
            ((Component.Editable) component).setEditable(Boolean.parseBoolean(editable));
        }
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 43 with MetaClass

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

the class DataGridLoader method loadColumn.

protected Column loadColumn(DataGrid component, Element element, Datasource ds) {
    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.getCurrentFrameId(), "DataGrid ID", component.getId());
        }
    }
    Column column;
    if (property != null) {
        MetaPropertyPath metaPropertyPath = AppBeans.get(MetadataTools.NAME, MetadataTools.class).resolveMetaPropertyPath(ds.getMetaClass(), 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));
    }
    // Default caption set to columns when it is added to a DataGrid,
    // so we need to set caption as null to get caption from
    // metaProperty if 'caption' attribute is empty
    column.setCaption(null);
    String caption = loadCaption(element);
    if (caption == null) {
        String columnCaption;
        if (column.getPropertyPath() != null) {
            MetaProperty metaProperty = column.getPropertyPath().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(column.getPropertyPath());
                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);
    } else {
        column.setCaption(caption);
    }
    column.setXmlDescriptor(element);
    Integer width = loadWidth(element, "width");
    if (width != null) {
        column.setWidth(width);
    }
    Integer minimumWidth = loadWidth(element, "minimumWidth");
    if (minimumWidth != null) {
        column.setMinimumWidth(minimumWidth);
    }
    Integer maximumWidth = loadWidth(element, "maximumWidth");
    if (maximumWidth != null) {
        column.setMaximumWidth(maximumWidth);
    }
    column.setFormatter(loadFormatter(element));
    return column;
}
Also used : MetadataTools(com.haulmont.cuba.core.global.MetadataTools) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) Column(com.haulmont.cuba.gui.components.DataGrid.Column) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 44 with MetaClass

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

the class FieldGroupLoader method loadVisible.

protected void loadVisible(FieldGroup resultComponent, FieldGroup.FieldConfig field) {
    Element element = field.getXmlDescriptor();
    if (element != null) {
        String visible = element.attributeValue("visible");
        if (StringUtils.isNotEmpty(visible)) {
            field.setVisible(Boolean.parseBoolean(visible));
        }
    }
    if (!field.isCustom() && BooleanUtils.isNotFalse(field.isVisible())) {
        MetaClass metaClass = getMetaClass(resultComponent, field);
        MetaPropertyPath propertyPath = metadataTools.resolveMetaPropertyPath(metaClass, field.getProperty());
        checkNotNullArgument(propertyPath, "Could not resolve property path '%s' in '%s'", field.getId(), metaClass);
        if (!security.isEntityAttrReadPermitted(metaClass, propertyPath.toString())) {
            field.setVisible(false);
        }
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) Element(org.dom4j.Element) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 45 with MetaClass

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

the class FieldGroupLoader method getDefaultCaption.

protected String getDefaultCaption(FieldGroup.FieldConfig fieldConfig, Datasource fieldDatasource) {
    String caption = fieldConfig.getCaption();
    if (caption == null) {
        String propertyId = fieldConfig.getProperty();
        MetaPropertyPath propertyPath = fieldDatasource != null ? fieldDatasource.getMetaClass().getPropertyPath(propertyId) : null;
        if (propertyPath != null) {
            MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
            String propertyName = propertyPath.getMetaProperty().getName();
            caption = messageTools.getPropertyCaption(propertyMetaClass, propertyName);
        }
    }
    return caption;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)302 MetaProperty (com.haulmont.chile.core.model.MetaProperty)103 Entity (com.haulmont.cuba.core.entity.Entity)54 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)36 Nullable (javax.annotation.Nullable)25 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)24 Element (org.dom4j.Element)21 java.util (java.util)18 Inject (javax.inject.Inject)17 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)16 Test (org.junit.Test)15 EntityManager (com.haulmont.cuba.core.EntityManager)14 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)14 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)13 Metadata (com.haulmont.cuba.core.global.Metadata)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)12 Collectors (java.util.stream.Collectors)11 Range (com.haulmont.chile.core.model.Range)10