Search in sources :

Example 6 with Instance

use of com.haulmont.chile.core.model.Instance in project cuba by cuba-platform.

the class EmbeddedDatasourceImpl method getItem.

@Override
public T getItem() {
    backgroundWorker.checkUIAccess();
    final Instance item = masterDs.getItem();
    return getItem(item);
}
Also used : Instance(com.haulmont.chile.core.model.Instance)

Example 7 with Instance

use of com.haulmont.chile.core.model.Instance in project cuba by cuba-platform.

the class EmbeddedDatasourceImpl method setItem.

@Override
public void setItem(T item) {
    backgroundWorker.checkUIAccess();
    if (getItem() != null) {
        metadata.getTools().copy(item, getItem());
        itemsToUpdate.add(item);
    } else {
        final Instance parentItem = masterDs.getItem();
        parentItem.setValue(metaProperty.getName(), item);
    }
    setModified(true);
    ((DatasourceImplementation) masterDs).modified(masterDs.getItem());
}
Also used : Instance(com.haulmont.chile.core.model.Instance)

Example 8 with Instance

use of com.haulmont.chile.core.model.Instance in project cuba by cuba-platform.

the class ExcelExporter method createGroupRow.

protected int createGroupRow(GroupTable table, List<Table.Column> columns, int rowNumber, GroupInfo groupInfo, int groupNumber) {
    GroupTableItems<Entity> groupTableSource = (GroupTableItems) table.getItems();
    Row row = sheet.createRow(rowNumber);
    Map<Object, Object> aggregations = table.isAggregatable() ? table.getAggregationResults(groupInfo) : Collections.emptyMap();
    int i = 0;
    int initialGroupNumber = groupNumber;
    for (Table.Column column : columns) {
        if (i == initialGroupNumber) {
            Cell cell = row.createCell(i);
            Object val = groupInfo.getValue();
            if (val == null) {
                val = messages.getMessage(getClass(), "excelExporter.empty");
            }
            Collection children = groupTableSource.getGroupItemIds(groupInfo);
            if (children.isEmpty()) {
                return rowNumber;
            }
            Integer groupChildCount = null;
            if (table.isShowItemsCountForGroup()) {
                groupChildCount = children.size();
            }
            Object captionValue = val;
            Element xmlDescriptor = column.getXmlDescriptor();
            if (xmlDescriptor != null && StringUtils.isNotEmpty(xmlDescriptor.attributeValue("captionProperty"))) {
                String captionProperty = xmlDescriptor.attributeValue("captionProperty");
                Object itemId = children.iterator().next();
                Instance item = groupTableSource.getItemNN(itemId);
                captionValue = item.getValueEx(captionProperty);
            }
            GroupTable.GroupCellValueFormatter<Entity> groupCellValueFormatter = table.getGroupCellValueFormatter();
            if (groupCellValueFormatter != null) {
                // disable separate "(N)" printing
                groupChildCount = null;
                List<Entity> groupItems = ((Collection<Object>) groupTableSource.getGroupItemIds(groupInfo)).stream().map(groupTableSource::getItem).collect(Collectors.toList());
                GroupTable.GroupCellContext<Entity> cellContext = new GroupTable.GroupCellContext<>(groupInfo, captionValue, metadataTools.format(captionValue), groupItems);
                captionValue = groupCellValueFormatter.format(cellContext);
            }
            MetaPropertyPath columnId = (MetaPropertyPath) column.getId();
            formatValueCell(cell, captionValue, columnId, groupNumber++, rowNumber, 0, groupChildCount);
        } else {
            AggregationInfo agr = column.getAggregation();
            if (agr != null) {
                Object key = agr.getPropertyPath() != null ? agr.getPropertyPath() : column.getId();
                Object aggregationResult = aggregations.get(key);
                if (aggregationResult != null) {
                    Cell cell = row.createCell(i);
                    formatValueCell(cell, aggregationResult, null, i, rowNumber, 0, null);
                }
            }
        }
        i++;
    }
    int oldRowNumber = rowNumber;
    List<GroupInfo> children = groupTableSource.getChildren(groupInfo);
    if (children.size() > 0) {
        for (GroupInfo child : children) {
            rowNumber = createGroupRow(table, columns, ++rowNumber, child, groupNumber);
        }
    } else {
        Collection<?> itemIds = groupTableSource.getGroupItemIds(groupInfo);
        for (Object itemId : itemIds) {
            createRow(table, columns, groupNumber, ++rowNumber, itemId);
        }
    }
    if (checkIsRowNumberExceed(rowNumber)) {
        sheet.groupRow(oldRowNumber + 1, excelOptions.getMaxRowCount());
    } else {
        sheet.groupRow(oldRowNumber + 1, rowNumber);
    }
    return rowNumber;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Instance(com.haulmont.chile.core.model.Instance) Element(org.dom4j.Element) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) GroupTableItems(com.haulmont.cuba.gui.components.data.GroupTableItems) Table(com.haulmont.cuba.gui.components.Table) GroupInfo(com.haulmont.cuba.gui.data.GroupInfo)

Example 9 with Instance

use of com.haulmont.chile.core.model.Instance in project cuba by cuba-platform.

the class AbstractComparator method compareAsc.

protected int compareAsc(Object o1, Object o2) {
    int c;
    if (o1 instanceof String && o2 instanceof String) {
        c = ((String) o1).compareToIgnoreCase((String) o2);
    } else if (o1 instanceof Comparable && o2 instanceof Comparable) {
        c = ((Comparable) o1).compareTo(o2);
    } else if (o1 instanceof Instance && o2 instanceof Instance) {
        MetaClass metaClass = metadata.getClassNN(o1.getClass());
        Collection<MetaProperty> namePatternProperties = metadata.getTools().getNamePatternProperties(metaClass, true);
        if (namePatternProperties.isEmpty()) {
            c = ((Instance) o1).getInstanceName().compareToIgnoreCase(((Instance) o2).getInstanceName());
        } else {
            c = 0;
            for (MetaProperty property : namePatternProperties) {
                Object v1 = ((Instance) o1).getValue(property.getName());
                Object v2 = ((Instance) o2).getValue(property.getName());
                c = compareAsc(v1, v2);
                if (c != 0)
                    break;
            }
        }
    } else if (Objects.equals(o1, o2)) {
        c = 0;
    } else if (o1 == null && o2 != null) {
        c = nullsLast;
    } else {
        c = -nullsLast;
    }
    return c;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) Instance(com.haulmont.chile.core.model.Instance) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 10 with Instance

use of com.haulmont.chile.core.model.Instance in project cuba by cuba-platform.

the class WebGroupTable method formatGroupPropertyValue.

protected String formatGroupPropertyValue(GroupInfo<MetaPropertyPath> groupId, @Nullable Object value) {
    if (value == null) {
        return "";
    }
    MetaPropertyPath propertyPath = groupId.getProperty();
    Table.Column<E> column = columns.get(propertyPath);
    if (column != null) {
        if (column.getFormatter() != null) {
            return column.getFormatter().apply(value);
        } else if (column.getXmlDescriptor() != null) {
            // vaadin8 move to Column
            String captionProperty = column.getXmlDescriptor().attributeValue("captionProperty");
            if (StringUtils.isNotEmpty(captionProperty)) {
                Collection<?> children = component.getGroupItemIds(groupId);
                if (children.isEmpty()) {
                    return null;
                }
                Object itemId = children.iterator().next();
                TableDataContainer container = (TableDataContainer) component.getContainerDataSource();
                Instance item = (Instance) container.getInternalItem(itemId);
                Object captionValue = item.getValueEx(captionProperty);
                // vaadin8 use metadataTools format with metaproperty
                return metadataTools.format(captionValue);
            }
        }
    }
    return metadataTools.format(value, propertyPath.getMetaProperty());
}
Also used : TableDataContainer(com.haulmont.cuba.web.gui.components.table.TableDataContainer) GroupTableDataContainer(com.haulmont.cuba.web.gui.components.table.GroupTableDataContainer) GroupTable(com.haulmont.cuba.gui.components.GroupTable) Table(com.haulmont.cuba.gui.components.Table) CubaGroupTable(com.haulmont.cuba.web.widgets.CubaGroupTable) Instance(com.haulmont.chile.core.model.Instance) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Aggregations

Instance (com.haulmont.chile.core.model.Instance)18 MetaClass (com.haulmont.chile.core.model.MetaClass)4 MetaProperty (com.haulmont.chile.core.model.MetaProperty)4 AbstractInstance (com.haulmont.chile.core.model.impl.AbstractInstance)4 Entity (com.haulmont.cuba.core.entity.Entity)4 Table (com.haulmont.cuba.gui.components.Table)3 Nullable (javax.annotation.Nullable)3 Logger (org.slf4j.Logger)3 Datatype (com.haulmont.chile.core.datatypes.Datatype)2 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)2 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)2 Messages (com.haulmont.cuba.core.global.Messages)2 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 java.util (java.util)2 Consumer (java.util.function.Consumer)2 LoggerFactory (org.slf4j.LoggerFactory)2 Sets (com.google.common.collect.Sets)1 EventHub (com.haulmont.bali.events.EventHub)1 Subscription (com.haulmont.bali.events.Subscription)1