Search in sources :

Example 6 with MetaPropertyPath

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

the class PropertyConditionDescriptor method getTreeCaption.

@Override
public String getTreeCaption() {
    if (!Strings.isNullOrEmpty(this.caption)) {
        return locCaption;
    } else {
        MessageTools messageTools = AppBeans.get(MessageTools.class);
        MetaPropertyPath mpp = datasourceMetaClass.getPropertyPath(name);
        return mpp != null ? messageTools.getPropertyCaption(datasourceMetaClass, name) : name;
    }
}
Also used : MessageTools(com.haulmont.cuba.core.global.MessageTools) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 7 with MetaPropertyPath

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

the class DynamicAttributesConditionFrame method fillCategorySelect.

protected void fillCategorySelect() {
    DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.NAME);
    MetaClass metaClass = condition.getDatasource().getMetaClass();
    if (!Strings.isNullOrEmpty(condition.getPropertyPath())) {
        MetaPropertyPath propertyPath = metaClass.getPropertyPath(condition.getPropertyPath());
        if (propertyPath == null) {
            throw new RuntimeException("Property path " + condition.getPropertyPath() + " doesn't exist");
        }
        metaClass = propertyPath.getRange().asClass();
    }
    Collection<Category> categories = dynamicAttributes.getCategoriesForMetaClass(metaClass);
    UUID catId = condition.getCategoryId();
    Category selectedCategory = null;
    Map<String, Object> categoriesMap = new TreeMap<>();
    if (categories.size() == 1 && (catId == null || Objects.equals(catId, categories.iterator().next().getId()))) {
        Category category = categories.iterator().next();
        categoryLookup.setVisible(false);
        categoryLabel.setVisible(false);
        attributeLookup.requestFocus();
        categoriesMap.put(category.getName(), category);
        categoryLookup.setOptionsMap(categoriesMap);
        categoryLookup.setValue(category);
        fillAttributeSelect(category);
    } else {
        categoryLookup.setVisible(true);
        categoryLabel.setVisible(true);
        for (Category category : categories) {
            categoriesMap.put(category.getName(), category);
            if (category.getId().equals(catId)) {
                selectedCategory = category;
            }
        }
        categoryLookup.setOptionsMap(categoriesMap);
        categoryLookup.setValue(selectedCategory);
    }
}
Also used : Category(com.haulmont.cuba.core.entity.Category) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) DynamicAttributes(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes)

Example 8 with MetaPropertyPath

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

the class ExcelExporter method createRow.

protected void createRow(Table table, List<Table.Column> columns, int startColumn, int rowNumber, Object itemId) {
    if (startColumn >= columns.size()) {
        return;
    }
    HSSFRow row = sheet.createRow(rowNumber);
    Instance instance = table.getDatasource().getItem(itemId);
    int level = 0;
    if (table instanceof TreeTable) {
        level = ((TreeTable) table).getLevel(itemId);
    }
    for (int c = startColumn; c < columns.size(); c++) {
        HSSFCell cell = row.createCell(c);
        Table.Column column = columns.get(c);
        Object cellValue = null;
        MetaPropertyPath propertyPath = null;
        if (column.getId() instanceof MetaPropertyPath) {
            propertyPath = (MetaPropertyPath) column.getId();
            Table.Printable printable = table.getPrintable(column);
            if (printable != null) {
                cellValue = printable.getValue((Entity) instance);
            } else {
                Element xmlDescriptor = column.getXmlDescriptor();
                if (xmlDescriptor != null && StringUtils.isNotEmpty(xmlDescriptor.attributeValue("captionProperty"))) {
                    String captionProperty = xmlDescriptor.attributeValue("captionProperty");
                    cellValue = InstanceUtils.getValueEx(instance, captionProperty);
                } else {
                    cellValue = InstanceUtils.getValueEx(instance, propertyPath.getPath());
                }
                if (column.getFormatter() != null)
                    cellValue = column.getFormatter().format(cellValue);
            }
        } else {
            Table.Printable printable = table.getPrintable(column);
            if (printable != null) {
                cellValue = printable.getValue((Entity) instance);
            }
        }
        formatValueCell(cell, cellValue, propertyPath, c, rowNumber, level, null);
    }
}
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)

Example 9 with MetaPropertyPath

use of com.haulmont.chile.core.model.MetaPropertyPath 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) {
    GroupDatasource ds = table.getDatasource();
    HSSFRow 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) {
            HSSFCell cell = row.createCell(i);
            Object val = groupInfo.getValue();
            if (val == null) {
                val = messages.getMessage(getClass(), "excelExporter.empty");
            }
            Collection children = table.getDatasource().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 = ds.getItem(itemId);
                captionValue = item.getValueEx(captionProperty);
            }
            @SuppressWarnings("unchecked") GroupTable.GroupCellValueFormatter<Entity> groupCellValueFormatter = table.getGroupCellValueFormatter();
            if (groupCellValueFormatter != null) {
                // disable separate "(N)" printing
                groupChildCount = null;
                List<Entity> groupItems = ((Collection<Object>) ds.getGroupItemIds(groupInfo)).stream().map((Function<Object, Entity>) ds::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 aggregationResult = aggregations.get(agr.getPropertyPath());
                if (aggregationResult != null) {
                    HSSFCell cell = row.createCell(i);
                    formatValueCell(cell, aggregationResult, null, i, rowNumber, 0, null);
                }
            }
        }
        i++;
    }
    int oldRowNumber = rowNumber;
    List<GroupInfo> children = ds.getChildren(groupInfo);
    if (children.size() > 0) {
        for (GroupInfo child : children) {
            rowNumber = createGroupRow(table, columns, ++rowNumber, child, groupNumber);
        }
    } else {
        Collection<Object> itemIds = ds.getGroupItemIds(groupInfo);
        for (Object itemId : itemIds) {
            createRow(table, columns, groupNumber, ++rowNumber, itemId);
        }
    }
    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) Function(java.util.function.Function) GroupInfo(com.haulmont.cuba.gui.data.GroupInfo) GroupDatasource(com.haulmont.cuba.gui.data.GroupDatasource)

Example 10 with MetaPropertyPath

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

the class ExcelExporter method createDataGridRow.

protected void createDataGridRow(DataGrid dataGrid, List<DataGrid.Column> columns, int startColumn, int rowNumber, Object itemId) {
    if (startColumn >= columns.size()) {
        return;
    }
    HSSFRow row = sheet.createRow(rowNumber);
    Instance instance = dataGrid.getDatasource().getItem(itemId);
    int level = 0;
    for (int c = startColumn; c < columns.size(); c++) {
        HSSFCell cell = row.createCell(c);
        DataGrid.Column column = columns.get(c);
        Object cellValue;
        MetaPropertyPath propertyPath = null;
        if (column.getPropertyPath() != null) {
            propertyPath = column.getPropertyPath();
            cellValue = InstanceUtils.getValueEx(instance, propertyPath.getPath());
            if (column.getFormatter() != null) {
                cellValue = column.getFormatter().format(cellValue);
            }
        } else {
            DataGrid.ColumnGenerator generator = dataGrid.getColumnGenerator(column.getId());
            DataGrid.ColumnGeneratorEvent event = new DataGrid.ColumnGeneratorEvent(dataGrid, instance, column.getId());
            cellValue = generator.getValue(event);
        }
        formatValueCell(cell, cellValue, propertyPath, c, rowNumber, level, null);
    }
}
Also used : Instance(com.haulmont.chile.core.model.Instance) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Aggregations

MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)84 MetaClass (com.haulmont.chile.core.model.MetaClass)34 MetaProperty (com.haulmont.chile.core.model.MetaProperty)27 Element (org.dom4j.Element)16 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)11 Entity (com.haulmont.cuba.core.entity.Entity)9 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)9 Datasource (com.haulmont.cuba.gui.data.Datasource)6 Table (com.haulmont.cuba.gui.components.Table)5 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 MessageTools (com.haulmont.cuba.core.global.MessageTools)4 Instance (com.haulmont.chile.core.model.Instance)3 Op (com.haulmont.cuba.core.global.filter.Op)3 FocusableTable (com.haulmont.cuba.desktop.sys.vcl.FocusableTable)3 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 Formatter (com.haulmont.cuba.gui.components.Formatter)3 Window (com.haulmont.cuba.gui.components.Window)3 CollectionFormatter (com.haulmont.cuba.gui.components.formatters.CollectionFormatter)3 GroupInfo (com.haulmont.cuba.gui.data.GroupInfo)3 java.util (java.util)3