Search in sources :

Example 11 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath 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 12 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath 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 13 with MetaPropertyPath

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

the class AbstractTableLoader method addDynamicAttributes.

protected void addDynamicAttributes(Table component, Datasource ds, List<Table.Column> availableColumns) {
    if (metadataTools.isPersistent(ds.getMetaClass())) {
        Set<CategoryAttribute> attributesToShow = dynamicAttributesGuiTools.getAttributesToShowOnTheScreen(ds.getMetaClass(), context.getFullFrameId(), component.getId());
        if (CollectionUtils.isNotEmpty(attributesToShow)) {
            ds.setLoadDynamicAttributes(true);
            for (CategoryAttribute attribute : attributesToShow) {
                final MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(ds.getMetaClass(), attribute);
                Object columnWithSameId = IterableUtils.find(availableColumns, o -> o.getId().equals(metaPropertyPath));
                if (columnWithSameId != null) {
                    continue;
                }
                final Table.Column column = new Table.Column(metaPropertyPath);
                column.setCaption(LocaleHelper.isLocalizedValueDefined(attribute.getLocaleNames()) ? attribute.getLocaleName() : StringUtils.capitalize(attribute.getName()));
                if (attribute.getDataType().equals(PropertyType.STRING)) {
                    column.setMaxTextLength(clientConfig.getDynamicAttributesTableColumnMaxTextLength());
                }
                if (attribute.getDataType().equals(PropertyType.ENUMERATION)) {
                    column.setFormatter(value -> LocaleHelper.getEnumLocalizedValue((String) value, attribute.getEnumerationLocales()));
                }
                component.addColumn(column);
            }
        }
        dynamicAttributesGuiTools.listenDynamicAttributesChanges(ds);
    }
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 14 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath 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 15 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath 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)

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