use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebAbstractTable method createColumns.
protected Collection<MetaPropertyPath> createColumns(com.vaadin.data.Container ds) {
@SuppressWarnings("unchecked") final Collection<MetaPropertyPath> properties = (Collection<MetaPropertyPath>) ds.getContainerPropertyIds();
Window window = ComponentsHelper.getWindowImplementation(this);
boolean isLookup = window instanceof Window.Lookup;
for (MetaPropertyPath propertyPath : properties) {
final Table.Column column = columns.get(propertyPath);
if (column != null && !(editable && BooleanUtils.isTrue(column.isEditable()))) {
final String isLink = column.getXmlDescriptor() == null ? null : column.getXmlDescriptor().attributeValue("link");
if (propertyPath.getRange().isClass()) {
if (!isLookup && StringUtils.isNotEmpty(isLink)) {
setClickListener(propertyPath.toString(), new LinkCellClickListener());
}
} else if (propertyPath.getRange().isDatatype()) {
if (!isLookup && !StringUtils.isEmpty(isLink)) {
setClickListener(propertyPath.toString(), new LinkCellClickListener());
} else if (editable && BooleanUtils.isTrue(column.isCalculatable())) {
addGeneratedColumn(propertyPath, new CalculatableColumnGenerator());
} else {
if (column.getMaxTextLength() != null) {
addGeneratedColumn(propertyPath, new AbbreviatedColumnGenerator(column));
setClickListener(propertyPath.toString(), new AbbreviatedCellClickListener());
}
}
} else if (!propertyPath.getRange().isEnum()) {
throw new UnsupportedOperationException();
}
}
}
return properties;
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebAbstractTable method checkAggregation.
protected void checkAggregation(AggregationInfo aggregationInfo) {
MetaPropertyPath propertyPath = aggregationInfo.getPropertyPath();
Class<?> javaType = propertyPath.getMetaProperty().getJavaType();
Aggregation<?> aggregation = Aggregations.get(javaType);
AggregationInfo.Type aggregationType = aggregationInfo.getType();
if (aggregationType == AggregationInfo.Type.CUSTOM)
return;
if (aggregation != null && aggregation.getSupportedAggregationTypes().contains(aggregationType))
return;
String msg = String.format("Unable to aggregate column \"%s\" with data type %s with default aggregation strategy: %s", propertyPath, propertyPath.getRange(), aggregationInfo.getType());
throw new IllegalArgumentException(msg);
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebAbstractTable method saveSettings.
@Override
public boolean saveSettings(Element element) {
if (!isSettingsEnabled()) {
return false;
}
if (isUsePresentations()) {
element.addAttribute("textSelection", String.valueOf(component.isTextSelectionEnabled()));
}
Element columnsElem = element.element("columns");
if (columnsElem != null) {
element.remove(columnsElem);
}
columnsElem = element.addElement("columns");
Object[] visibleColumns = component.getVisibleColumns();
for (Object column : visibleColumns) {
Element colElem = columnsElem.addElement("columns");
colElem.addAttribute("id", column.toString());
int width = component.getColumnWidth(column);
if (width > -1)
colElem.addAttribute("width", String.valueOf(width));
Boolean visible = !component.isColumnCollapsed(column);
colElem.addAttribute("visible", visible.toString());
}
MetaPropertyPath sortProperty = (MetaPropertyPath) component.getSortContainerPropertyId();
if (sortProperty != null) {
Boolean sortAscending = component.isSortAscending();
columnsElem.addAttribute("sortProperty", sortProperty.toString());
columnsElem.addAttribute("sortAscending", sortAscending.toString());
}
return true;
}
use of com.haulmont.chile.core.model.MetaPropertyPath 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.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebDataGrid method applyColumnSettings.
protected void applyColumnSettings(Element element, Collection<Column> oldColumns) {
final Element columnsElem = element.element("columns");
List<Column> newColumns = new ArrayList<>();
// add columns from saved settings
for (Element colElem : Dom4j.elements(columnsElem, "columns")) {
for (Column column : oldColumns) {
if (column.getId().equals(colElem.attributeValue("id"))) {
newColumns.add(column);
String width = colElem.attributeValue("width");
if (width != null) {
column.setWidth(Double.parseDouble(width));
} else {
column.setWidthAuto();
}
String collapsed = colElem.attributeValue("collapsed");
if (collapsed != null && component.isColumnReorderingAllowed()) {
column.setCollapsed(Boolean.parseBoolean(collapsed));
}
break;
}
}
}
// add columns not saved in settings (perhaps new)
for (Column column : oldColumns) {
if (!newColumns.contains(column)) {
newColumns.add(column);
}
}
// if the data grid contains only one column, always show it
if (newColumns.size() == 1) {
newColumns.get(0).setCollapsed(false);
}
List<Object> properties = newColumns.stream().map(column -> ((ColumnImpl) column).getColumnPropertyId()).collect(Collectors.toList());
// We don't save settings for columns hidden by security permissions,
// so we need to return them back to they initial positions
columnsOrder = restoreColumnsOrder(newColumns);
component.setColumnOrder(properties.toArray());
if (isSortable()) {
// apply sorting
component.clearSortOrder();
String sortPropertyName = columnsElem.attributeValue("sortProperty");
if (!StringUtils.isEmpty(sortPropertyName)) {
MetaPropertyPath sortProperty = datasource.getMetaClass().getPropertyPath(sortPropertyName);
if (properties.contains(sortProperty) && sortProperty != null) {
String sortDirection = columnsElem.attributeValue("sortDirection");
if (StringUtils.isNotEmpty(sortDirection)) {
List<com.vaadin.data.sort.SortOrder> sortOrders = Collections.singletonList(new com.vaadin.data.sort.SortOrder(sortProperty, com.vaadin.shared.data.sort.SortDirection.valueOf(sortDirection)));
component.setSortOrder(sortOrders);
}
}
}
}
}
Aggregations