use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class AbstractTable method checkAggregation.
protected void checkAggregation(AggregationInfo aggregationInfo) {
AggregationInfo.Type aggregationType = aggregationInfo.getType();
if (aggregationType == AggregationInfo.Type.CUSTOM) {
return;
}
MetaPropertyPath propertyPath = aggregationInfo.getPropertyPath();
Class<?> javaType = propertyPath.getMetaProperty().getJavaType();
Aggregation<?> aggregation = aggregations.get(javaType);
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 io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class AbstractTable method getParsedAggregationValue.
@Nullable
protected Object getParsedAggregationValue(String value, Object columnId) throws ParseException {
Object parsedValue = value;
for (Column column : getColumns()) {
if (column.getId().equals(columnId)) {
AggregationInfo aggregationInfo = column.getAggregation();
if (aggregationInfo == null || aggregationInfo.getFormatter() != null) {
return parsedValue;
}
MetaPropertyPath propertyPath = aggregationInfo.getPropertyPath();
Class<?> resultClass;
Range range = propertyPath != null ? propertyPath.getRange() : null;
if (range != null && range.isDatatype()) {
if (aggregationInfo.getType() == AggregationInfo.Type.COUNT) {
return parsedValue;
}
if (aggregationInfo.getStrategy() == null) {
Class<?> rangeJavaClass = propertyPath.getRangeJavaClass();
Aggregation aggregation = aggregations.get(rangeJavaClass);
resultClass = aggregation.getResultClass();
} else {
resultClass = aggregationInfo.getStrategy().getResultClass();
}
} else if (aggregationInfo.getStrategy() == null) {
return parsedValue;
} else {
resultClass = aggregationInfo.getStrategy().getResultClass();
}
parsedValue = datatypeRegistry.get(resultClass).parse(value, locale);
break;
}
}
return parsedValue;
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class AbstractTable method enableEditableColumns.
protected void enableEditableColumns(EntityTableItems<E> entityTableSource, Collection<MetaPropertyPath> propertyIds) {
MetaClass metaClass = entityTableSource.getEntityMetaClass();
List<MetaPropertyPath> editableColumns = new ArrayList<>(propertyIds.size());
for (MetaPropertyPath propertyId : propertyIds) {
UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, propertyId.toString());
accessManager.applyRegisteredConstraints(attributeContext);
if (!attributeContext.canModify()) {
continue;
}
Column column = getColumn(propertyId.toString());
if (column != null && BooleanUtils.isTrue(column.isEditable())) {
com.vaadin.v7.ui.Table.ColumnGenerator generator = component.getColumnGenerator(column.getId());
if (generator != null) {
if (generator instanceof SystemTableColumnGenerator) {
// remove default generator
component.removeGeneratedColumn(propertyId);
} else {
// do not edit generated columns
continue;
}
}
editableColumns.add(propertyId);
}
}
setEditableColumns(editableColumns);
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class AbstractTable method addColumnInternal.
protected void addColumnInternal(Column<E> column, int index) {
checkNotNullArgument(column, "Column must be non null");
Object columnId = column.getId();
component.addContainerProperty(columnId, getColumnType(column), 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) {
setColumnAggregationDescriptionByType(column, columnId);
}
if (!column.isSortable()) {
component.setColumnSortable(columnId, column.isSortable());
}
columns.put(columnId, column);
columnsOrder.add(index, column);
if (column.getWidth() != null) {
component.setColumnWidth(columnId, column.getWidth());
}
if (column.getAlignment() != null) {
component.setColumnAlignment(columnId, WrapperUtils.convertColumnAlignment(column.getAlignment()));
}
setColumnHeader(columnId, getColumnCaption(columnId, column));
component.setColumnCaptionAsHtml(columnId, column.isCaptionAsHtml());
if (column.getExpandRatio() != -1) {
component.setColumnExpandRatio(columnId, column.getExpandRatio());
}
column.setOwner(this);
MetaPropertyPath propertyPath = column.getMetaPropertyPath();
if (propertyPath != null) {
MetaProperty metaProperty = propertyPath.getMetaProperty();
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
if (metadataTools.isLob(metaProperty) && !propertyMetaClass.getStore().supportsLobSortingAndFiltering()) {
component.setColumnSortable(columnId, false);
}
}
if (column.isAggregationEditable()) {
component.addAggregationEditableColumn(columnId);
}
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class AbstractTable method addGeneratedColumn.
@Override
public void addGeneratedColumn(String columnId, ColumnGenerator<? super E> generator) {
checkNotNullArgument(columnId, "columnId is null");
checkNotNullArgument(generator, "generator is null for column id '%s'", columnId);
EntityTableItems<E> entityTableSource = (EntityTableItems<E>) getItems();
MetaPropertyPath targetCol = entityTableSource != null ? entityTableSource.getEntityMetaClass().getPropertyPath(columnId) : null;
Object generatedColumnId = targetCol != null ? targetCol : columnId;
Column column = getColumn(columnId);
Column associatedRuntimeColumn = null;
if (column == null) {
Column<E> newColumn = createColumn(generatedColumnId, this);
columns.put(newColumn.getId(), newColumn);
columnsOrder.add(newColumn);
associatedRuntimeColumn = newColumn;
}
// save column order
Object[] visibleColumns = component.getVisibleColumns();
boolean removeOldGeneratedColumn = component.getColumnGenerator(generatedColumnId) != null;
// replace generator for column if exist
if (removeOldGeneratedColumn) {
component.removeGeneratedColumn(generatedColumnId);
}
component.addGeneratedColumn(generatedColumnId, new CustomColumnGenerator(generator, associatedRuntimeColumn) {
@Nullable
@Override
public Object generateCell(com.vaadin.v7.ui.Table source, Object itemId, Object columnId) {
EntityTableItems<E> entityTableSource = (EntityTableItems<E>) getItems();
if (entityTableSource == null) {
return null;
}
E entity = entityTableSource.getItem(itemId);
io.jmix.ui.component.Component component = getColumnGenerator().generateCell(entity);
if (component == null) {
return null;
}
if (component instanceof PlainTextCell) {
return ((PlainTextCell) component).getText();
}
if (component instanceof BelongToFrame) {
BelongToFrame belongToFrame = (BelongToFrame) component;
if (belongToFrame.getFrame() == null) {
belongToFrame.setFrame(getFrame());
}
}
component.setParent(AbstractTable.this);
AbstractComponent vComponent = component.unwrapComposition(AbstractComponent.class);
if (component instanceof HasValueSource) {
HasValueSource<?> hasValueSource = (HasValueSource) component;
vComponent.setData(hasValueSource);
}
// wrap field for show required asterisk
if ((vComponent instanceof com.vaadin.v7.ui.Field) && (((com.vaadin.v7.ui.Field) vComponent).isRequired())) {
VerticalLayout layout = new VerticalLayout();
layout.setMargin(false);
layout.setSpacing(false);
layout.addComponent(vComponent);
if (vComponent.getWidth() < 0) {
layout.setWidthUndefined();
}
layout.addComponent(vComponent);
vComponent = layout;
}
return vComponent;
}
});
if (removeOldGeneratedColumn) {
// restore column order
component.setVisibleColumns(visibleColumns);
}
}
Aggregations