Search in sources :

Example 26 with MetaPropertyPath

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);
}
Also used : MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Example 27 with MetaPropertyPath

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;
}
Also used : Aggregation(io.jmix.ui.component.data.aggregation.Aggregation) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) Range(io.jmix.core.metamodel.model.Range) Nullable(javax.annotation.Nullable)

Example 28 with MetaPropertyPath

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);
}
Also used : JmixEnhancedTable(io.jmix.ui.widget.JmixEnhancedTable) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) MetaClass(io.jmix.core.metamodel.model.MetaClass) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Example 29 with MetaPropertyPath

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);
    }
}
Also used : KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 30 with MetaPropertyPath

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);
    }
}
Also used : MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) EntityTableItems(io.jmix.ui.component.data.meta.EntityTableItems) AbstractComponent(com.vaadin.ui.AbstractComponent) com.vaadin.ui(com.vaadin.ui) AbstractComponent(com.vaadin.ui.AbstractComponent) Component(com.vaadin.ui.Component) HasValueSource(io.jmix.ui.component.data.HasValueSource) Nullable(javax.annotation.Nullable)

Aggregations

MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)134 MetaClass (io.jmix.core.metamodel.model.MetaClass)68 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)52 Nullable (javax.annotation.Nullable)19 Table (io.jmix.ui.component.Table)15 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)12 MetadataTools (io.jmix.core.MetadataTools)10 Element (org.dom4j.Element)10 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8 UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)8 JmixEnhancedTable (io.jmix.ui.widget.JmixEnhancedTable)7 EntityTableItems (io.jmix.ui.component.data.meta.EntityTableItems)6 java.util (java.util)6 Collectors (java.util.stream.Collectors)6 Range (io.jmix.core.metamodel.model.Range)5 HasValueSource (io.jmix.ui.component.data.HasValueSource)5 ValueSource (io.jmix.ui.component.data.ValueSource)4 AbstractTable (io.jmix.ui.component.impl.AbstractTable)4 TableSettings (io.jmix.ui.settings.component.TableSettings)4