Search in sources :

Example 1 with CollectionFormatter

use of com.haulmont.cuba.gui.components.formatters.CollectionFormatter in project cuba by cuba-platform.

the class WebAbstractTable method addColumn.

@Override
public void addColumn(Table.Column column) {
    checkNotNullArgument(column, "Column must be non null");
    Object columnId = column.getId();
    component.addContainerProperty(columnId, column.getType(), null);
    if (StringUtils.isNotBlank(column.getDescription())) {
        component.setColumnDescription(columnId, column.getDescription());
    }
    if (StringUtils.isNotBlank(column.getValueDescription())) {
        component.setAggregationDescription(columnId, column.getValueDescription());
    } else if (column.getAggregation() != null && column.getAggregation().getType() != AggregationInfo.Type.CUSTOM) {
        Messages messages = AppBeans.get(Messages.NAME);
        String aggregationTypeLabel;
        switch(column.getAggregation().getType()) {
            case AVG:
                aggregationTypeLabel = "aggreagtion.avg";
                break;
            case COUNT:
                aggregationTypeLabel = "aggreagtion.count";
                break;
            case SUM:
                aggregationTypeLabel = "aggreagtion.sum";
                break;
            case MIN:
                aggregationTypeLabel = "aggreagtion.min";
                break;
            case MAX:
                aggregationTypeLabel = "aggreagtion.max";
                break;
            default:
                throw new IllegalArgumentException(String.format("AggregationType %s is not supported", column.getAggregation().getType().toString()));
        }
        component.setAggregationDescription(columnId, messages.getMainMessage(aggregationTypeLabel));
    }
    if (!column.isSortable()) {
        component.setColumnSortable(columnId, column.isSortable());
    }
    columns.put(columnId, column);
    columnsOrder.add(column);
    if (column.getWidth() != null) {
        component.setColumnWidth(columnId, column.getWidth());
    }
    if (column.getAlignment() != null) {
        component.setColumnAlignment(columnId, WebComponentsHelper.convertColumnAlignment(column.getAlignment()));
    }
    final String caption = getColumnCaption(columnId, column);
    setColumnHeader(columnId, caption);
    column.setOwner(this);
    if (column.getFormatter() == null && columnId instanceof MetaPropertyPath) {
        MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
        if (Collection.class.isAssignableFrom(metaProperty.getJavaType())) {
            final Formatter collectionFormatter = new CollectionFormatter();
            column.setFormatter(collectionFormatter);
        }
    }
    if (columnId instanceof MetaPropertyPath) {
        PersistenceManagerService persistenceManagerService = AppBeans.get(PersistenceManagerClient.NAME);
        MetaPropertyPath propertyPath = (MetaPropertyPath) columnId;
        MetaProperty metaProperty = propertyPath.getMetaProperty();
        MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
        String storeName = metadataTools.getStoreName(propertyMetaClass);
        if (metadataTools.isLob(metaProperty) && !persistenceManagerService.supportsLobSortingAndFiltering(storeName)) {
            component.setColumnSortable(columnId, false);
        }
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter) Formatter(com.haulmont.cuba.gui.components.Formatter) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) PersistenceManagerService(com.haulmont.cuba.core.app.PersistenceManagerService) MetaProperty(com.haulmont.chile.core.model.MetaProperty) CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter)

Example 2 with CollectionFormatter

use of com.haulmont.cuba.gui.components.formatters.CollectionFormatter in project cuba by cuba-platform.

the class DesktopAbstractTable method addColumn.

@Override
public void addColumn(Column column) {
    checkNotNullArgument(column, "Column must be non null");
    Object columnId = column.getId();
    columns.put(columnId, column);
    columnsOrder.add(column);
    if (tableModel != null) {
        tableModel.addColumn(column);
    }
    if (datasource != null && column.isEditable() && columnId instanceof MetaPropertyPath) {
        if (!editableColumns.contains(columnId)) {
            editableColumns.add((MetaPropertyPath) columnId);
        }
    }
    setColumnIdentifiers();
    refresh();
    column.setOwner(this);
    if (column.getFormatter() == null && columnId instanceof MetaPropertyPath) {
        MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
        if (Collection.class.isAssignableFrom(metaProperty.getJavaType())) {
            final Formatter collectionFormatter = new CollectionFormatter();
            column.setFormatter(collectionFormatter);
        }
    }
}
Also used : CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter) Formatter(com.haulmont.cuba.gui.components.Formatter) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty) CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter)

Example 3 with CollectionFormatter

use of com.haulmont.cuba.gui.components.formatters.CollectionFormatter in project cuba by cuba-platform.

the class WebDataGrid method setupGridColumnProperties.

protected void setupGridColumnProperties(Grid.Column gridColumn, Column column) {
    gridColumn.setHeaderCaption(column.getCaption());
    gridColumn.setHidingToggleCaption(column.getCollapsingToggleCaption());
    if (column.isWidthAuto()) {
        gridColumn.setWidthUndefined();
    } else {
        gridColumn.setWidth(column.getWidth());
    }
    gridColumn.setExpandRatio(column.getExpandRatio());
    gridColumn.setMinimumWidth(column.getMinimumWidth());
    gridColumn.setMaximumWidth(column.getMaximumWidth());
    gridColumn.setHidden(column.isCollapsed());
    gridColumn.setHidable(column.isCollapsible() && column.getOwner().isColumnsCollapsingAllowed());
    gridColumn.setResizable(column.isResizable());
    gridColumn.setEditable(column.isEditable());
    AppUI current = AppUI.getCurrent();
    if (current != null && current.isTestMode()) {
        addColumnId(gridColumn, column);
    }
    // workaround to prevent exception from GridColumn while Grid is using default IndexedContainer
    if (getContainerDataSource() instanceof SortableDataGridIndexedCollectionDsWrapper) {
        gridColumn.setSortable(column.isSortable() && column.getOwner().isSortable());
    }
    ((ColumnImpl) column).setGridColumn(gridColumn);
    if (column.getFormatter() != null) {
        FormatterBasedConverter converter = new FormatterBasedConverter(column.getFormatter());
        gridColumn.setConverter(converter);
    } else {
        MetaProperty metaProperty = column.getPropertyPath() != null ? column.getPropertyPath().getMetaProperty() : null;
        if (metaProperty != null && Collection.class.isAssignableFrom(metaProperty.getJavaType())) {
            final FormatterBasedConverter converter = new FormatterBasedConverter(new CollectionFormatter());
            gridColumn.setConverter(converter);
        } else {
            setDefaultConverter(gridColumn, metaProperty, column.getType());
            setDefaultRenderer(gridColumn, metaProperty, column.getType());
        }
    }
}
Also used : SortableDataGridIndexedCollectionDsWrapper(com.haulmont.cuba.web.gui.data.SortableDataGridIndexedCollectionDsWrapper) MetaProperty(com.haulmont.chile.core.model.MetaProperty) AppUI(com.haulmont.cuba.web.AppUI) FormatterBasedConverter(com.haulmont.cuba.web.toolkit.ui.converters.FormatterBasedConverter) CollectionFormatter(com.haulmont.cuba.gui.components.formatters.CollectionFormatter)

Aggregations

MetaProperty (com.haulmont.chile.core.model.MetaProperty)3 CollectionFormatter (com.haulmont.cuba.gui.components.formatters.CollectionFormatter)3 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)2 Formatter (com.haulmont.cuba.gui.components.Formatter)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 PersistenceManagerService (com.haulmont.cuba.core.app.PersistenceManagerService)1 AppUI (com.haulmont.cuba.web.AppUI)1 SortableDataGridIndexedCollectionDsWrapper (com.haulmont.cuba.web.gui.data.SortableDataGridIndexedCollectionDsWrapper)1 FormatterBasedConverter (com.haulmont.cuba.web.toolkit.ui.converters.FormatterBasedConverter)1