Search in sources :

Example 6 with HierarchicalDatasource

use of com.haulmont.cuba.gui.data.HierarchicalDatasource in project cuba by cuba-platform.

the class DesktopTreeTable method expandUpTo.

@Override
public void expandUpTo(int level) {
    if (getDatasource() == null) {
        return;
    }
    HierarchicalDatasource ds = getDatasource();
    java.util.List<Object> currentLevelItemIds = new ArrayList<>(ds.getRootItemIds());
    int i = 0;
    while (i < level && !currentLevelItemIds.isEmpty()) {
        for (Object itemId : new ArrayList<>(currentLevelItemIds)) {
            Entity<Object> item = datasource.getItem(itemId);
            impl.expandPath(((TreeTableModelAdapter) tableModel).getTreePath(item));
            currentLevelItemIds.remove(itemId);
            currentLevelItemIds.addAll(ds.getChildren(itemId));
        }
        i++;
    }
}
Also used : HierarchicalDatasource(com.haulmont.cuba.gui.data.HierarchicalDatasource) java.util(java.util)

Example 7 with HierarchicalDatasource

use of com.haulmont.cuba.gui.data.HierarchicalDatasource in project cuba by cuba-platform.

the class ExcelExporter method exportTable.

public void exportTable(Table<Entity> table, List<Table.Column> columns, Boolean exportExpanded, ExportDisplay display, List<String> filterDescription, String fileName, ExportMode exportMode) {
    if (display == null) {
        throw new IllegalArgumentException("ExportDisplay is null");
    }
    createWorkbookWithSheet();
    createFonts();
    createFormats();
    int r = 0;
    if (filterDescription != null) {
        for (r = 0; r < filterDescription.size(); r++) {
            String line = filterDescription.get(r);
            HSSFRow row = sheet.createRow(r);
            if (r == 0) {
                HSSFRichTextString richTextFilterName = new HSSFRichTextString(line);
                richTextFilterName.applyFont(boldFont);
                row.createCell(0).setCellValue(richTextFilterName);
            } else {
                row.createCell(0).setCellValue(line);
            }
        }
        r++;
    }
    HSSFRow row = sheet.createRow(r);
    createAutoColumnSizers(columns.size());
    float maxHeight = sheet.getDefaultRowHeightInPoints();
    CellStyle headerCellStyle = wb.createCellStyle();
    headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    for (Table.Column column : columns) {
        String caption = column.getCaption();
        int countOfReturnSymbols = StringUtils.countMatches(caption, "\n");
        if (countOfReturnSymbols > 0) {
            maxHeight = Math.max(maxHeight, (countOfReturnSymbols + 1) * sheet.getDefaultRowHeightInPoints());
            headerCellStyle.setWrapText(true);
        }
    }
    row.setHeightInPoints(maxHeight);
    for (int c = 0; c < columns.size(); c++) {
        Table.Column column = columns.get(c);
        String caption = column.getCaption();
        HSSFCell cell = row.createCell(c);
        HSSFRichTextString richTextString = new HSSFRichTextString(caption);
        richTextString.applyFont(boldFont);
        cell.setCellValue(richTextString);
        ExcelAutoColumnSizer sizer = new ExcelAutoColumnSizer();
        sizer.notifyCellValue(caption, boldFont);
        sizers[c] = sizer;
        cell.setCellStyle(headerCellStyle);
    }
    CollectionDatasource datasource = table.getDatasource();
    if (exportMode == ExportMode.SELECTED_ROWS && table.getSelected().size() > 0) {
        Set<Entity> selected = table.getSelected();
        List<Entity> ordered = ((Collection<Entity>) datasource.getItems()).stream().filter(selected::contains).collect(Collectors.toList());
        for (Entity item : ordered) {
            createRow(table, columns, 0, ++r, item.getId());
        }
    } else {
        if (table instanceof TreeTable) {
            TreeTable treeTable = (TreeTable) table;
            HierarchicalDatasource ds = treeTable.getDatasource();
            if (table.isAggregatable()) {
                r = createAggregatableRow(table, columns, ++r, 1, datasource);
            }
            for (Object itemId : ds.getRootItemIds()) {
                r = createHierarhicalRow(treeTable, columns, exportExpanded, r, itemId);
            }
        } else if (table instanceof GroupTable && datasource instanceof GroupDatasource && ((GroupDatasource) datasource).hasGroups()) {
            GroupDatasource ds = (GroupDatasource) datasource;
            if (table.isAggregatable()) {
                r = createAggregatableRow(table, columns, ++r, 1, datasource);
            }
            for (Object item : ds.rootGroups()) {
                r = createGroupRow((GroupTable) table, columns, ++r, (GroupInfo) item, 0);
            }
        } else {
            if (table.isAggregatable()) {
                r = createAggregatableRow(table, columns, ++r, 1, datasource);
            }
            for (Object itemId : datasource.getItemIds()) {
                createRow(table, columns, 0, ++r, itemId);
            }
        }
    }
    for (int c = 0; c < columns.size(); c++) {
        sheet.setColumnWidth(c, sizers[c].getWidth() * COL_WIDTH_MAGIC);
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        wb.write(out);
    } catch (IOException e) {
        throw new RuntimeException("Unable to write document", e);
    }
    if (fileName == null) {
        fileName = messages.getTools().getEntityCaption(datasource.getMetaClass());
    }
    display.show(new ByteArrayDataProvider(out.toByteArray()), fileName + ".xls", ExportFormat.XLS);
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) HierarchicalDatasource(com.haulmont.cuba.gui.data.HierarchicalDatasource) GroupDatasource(com.haulmont.cuba.gui.data.GroupDatasource) CellStyle(org.apache.poi.ss.usermodel.CellStyle)

Example 8 with HierarchicalDatasource

use of com.haulmont.cuba.gui.data.HierarchicalDatasource in project cuba by cuba-platform.

the class ExcelExporter method createHierarhicalRow.

protected int createHierarhicalRow(TreeTable table, List<Table.Column> columns, Boolean exportExpanded, int rowNumber, Object itemId) {
    HierarchicalDatasource hd = table.getDatasource();
    createRow(table, columns, 0, ++rowNumber, itemId);
    if (BooleanUtils.isTrue(exportExpanded) && !table.isExpanded(itemId) && !hd.getChildren(itemId).isEmpty()) {
        return rowNumber;
    } else {
        final Collection children = hd.getChildren(itemId);
        if (children != null && !children.isEmpty()) {
            for (Object id : children) {
                if (BooleanUtils.isTrue(exportExpanded) && !table.isExpanded(id) && !hd.getChildren(id).isEmpty()) {
                    createRow(table, columns, 0, ++rowNumber, id);
                    continue;
                }
                rowNumber = createHierarhicalRow(table, columns, exportExpanded, rowNumber, id);
            }
        }
    }
    return rowNumber;
}
Also used : HierarchicalDatasource(com.haulmont.cuba.gui.data.HierarchicalDatasource)

Example 9 with HierarchicalDatasource

use of com.haulmont.cuba.gui.data.HierarchicalDatasource in project cuba by cuba-platform.

the class TreeLoader method loadTreeChildren.

protected void loadTreeChildren() {
    Element itemsElem = element.element("treechildren");
    if (itemsElem == null)
        return;
    String datasource = itemsElem.attributeValue("datasource");
    if (!StringUtils.isBlank(datasource)) {
        HierarchicalDatasource ds = (HierarchicalDatasource) context.getDsContext().get(datasource);
        resultComponent.setDatasource(ds);
        String captionProperty = itemsElem.attributeValue("captionProperty");
        if (!StringUtils.isEmpty(captionProperty)) {
            resultComponent.setCaptionProperty(captionProperty);
            resultComponent.setCaptionMode(CaptionMode.PROPERTY);
        }
    }
}
Also used : HierarchicalDatasource(com.haulmont.cuba.gui.data.HierarchicalDatasource) Element(org.dom4j.Element)

Aggregations

HierarchicalDatasource (com.haulmont.cuba.gui.data.HierarchicalDatasource)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)3 java.util (java.util)3 Entity (com.haulmont.cuba.core.entity.Entity)2 IOException (java.io.IOException)2 Files (com.google.common.io.Files)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 MetaClass (com.haulmont.chile.core.model.MetaClass)1 ConstraintLocalizationService (com.haulmont.cuba.core.app.ConstraintLocalizationService)1 CollectionImportPolicy (com.haulmont.cuba.core.app.importexport.CollectionImportPolicy)1 EntityImportExportService (com.haulmont.cuba.core.app.importexport.EntityImportExportService)1 EntityImportView (com.haulmont.cuba.core.app.importexport.EntityImportView)1 ReferenceImportBehaviour (com.haulmont.cuba.core.app.importexport.ReferenceImportBehaviour)1 BaseUuidEntity (com.haulmont.cuba.core.entity.BaseUuidEntity)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 DenyingClause (com.haulmont.cuba.core.global.filter.DenyingClause)1 QueryFilter (com.haulmont.cuba.core.global.filter.QueryFilter)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 UserRemoveAction (com.haulmont.cuba.gui.app.security.user.browse.UserRemoveAction)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1