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);
}
}
}
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);
}
}
}
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());
}
}
}
Aggregations