Search in sources :

Example 1 with FormatterBasedConverter

use of com.haulmont.cuba.web.toolkit.ui.converters.FormatterBasedConverter 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)1 CollectionFormatter (com.haulmont.cuba.gui.components.formatters.CollectionFormatter)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