Search in sources :

Example 1 with TemplateTableBand

use of io.jmix.reports.entity.table.TemplateTableBand in project jmix by jmix-framework.

the class JmixTableFormatter method getTableData.

protected JmixTableData getTableData(TemplateTableDescription templateTableDescription, Map<String, List<KeyValueEntity>> transformedData, Map<String, Set<JmixTableData.ColumnInfo>> headerMap, Map<String, List<BandData>> childrenBands) {
    for (TemplateTableBand band : templateTableDescription.getTemplateTableBands()) {
        String bandName = band.getBandName();
        if (bandName.startsWith(HEADER_BAND_PREFIX)) {
            break;
        }
        List<BandData> bandDataList = childrenBands.get(bandName);
        if (bandDataList == null) {
            throw new ReportingException(String.format("Report template has an unknown band [%s]", bandName));
        }
        List<KeyValueEntity> entities = new ArrayList<>();
        Set<JmixTableData.ColumnInfo> headers = new LinkedHashSet<>();
        bandDataList.forEach(bandData -> {
            Map<String, Object> data = bandData.getData();
            final String pkName;
            final boolean pkInFetchPlan;
            if (data instanceof EntityMap) {
                Entity instance = ((EntityMap) data).getInstance();
                pkName = metadataTools.getPrimaryKeyName(metadata.getClass(instance));
                FetchPlan fetchPlan = ((EntityMap) data).getFetchPlan();
                pkInFetchPlan = fetchPlan != null && pkName != null && fetchPlan.containsProperty(pkName);
            } else {
                pkName = null;
                pkInFetchPlan = false;
            }
            KeyValueEntity entityRow = new KeyValueEntity();
            for (TemplateTableColumn column : band.getColumns()) {
                String key = column.getKey();
                Object value = data.get(key);
                if (INSTANCE_NAME_KEY.equals(key)) {
                    return;
                }
                if (checkAddHeader(pkName, pkInFetchPlan, key)) {
                    checkInstanceNameLoaded(value);
                    String transformationKey = transformationKey(key);
                    if (isFormat(bandName, key)) {
                        String formattedValue = getFormattedValue(bandName, key, value);
                        entityRow.setValue(transformationKey, formattedValue);
                    } else {
                        entityRow.setValue(transformationKey, value);
                    }
                }
            }
            if (headers.isEmpty() || headers.size() < data.size()) {
                for (TemplateTableColumn column : band.getColumns()) {
                    String key = column.getKey();
                    Object value = data.get(key);
                    if (INSTANCE_NAME_KEY.equals(key)) {
                        return;
                    }
                    if (checkAddHeader(pkName, pkInFetchPlan, key)) {
                        String transformationKey = transformationKey(key);
                        if (value != null) {
                            Class valueClass = getColumnClass(bandName, key, value);
                            headers.add(new JmixTableData.ColumnInfo(transformationKey, valueClass, column.getCaption(), column.getPosition()));
                        } else {
                            headers.add(new JmixTableData.ColumnInfo(transformationKey, String.class, column.getCaption(), column.getPosition()));
                        }
                    }
                }
            }
            entities.add(entityRow);
        });
        headers.removeIf(header -> containsLowerCaseDuplicate(header, headers));
        transformedData.put(bandName, entities);
        headerMap.put(bandName, headers);
    }
    return new JmixTableData(transformedData, headerMap);
}
Also used : KeyValueEntity(io.jmix.core.entity.KeyValueEntity) ReportingException(io.jmix.reports.exception.ReportingException) JmixTableData(io.jmix.reports.entity.JmixTableData) EntityMap(io.jmix.reports.app.EntityMap) TemplateTableColumn(io.jmix.reports.entity.table.TemplateTableColumn) TemplateTableBand(io.jmix.reports.entity.table.TemplateTableBand) KeyValueEntity(io.jmix.core.entity.KeyValueEntity) BandData(com.haulmont.yarg.structure.BandData)

Example 2 with TemplateTableBand

use of io.jmix.reports.entity.table.TemplateTableBand in project jmix by jmix-framework.

the class TableGenerator method generate.

@Override
public byte[] generate(ReportData reportData) {
    TemplateTableDescription templateTableDescription = dataManager.create(TemplateTableDescription.class);
    List<TemplateTableBand> bands = new LinkedList<>();
    for (int i = 0; i < reportData.getReportRegions().size(); i++) {
        ReportRegion reportRegion = reportData.getReportRegions().get(i);
        TemplateTableBand band = dataManager.create(TemplateTableBand.class);
        band.setPosition(i);
        band.setBandName(reportRegion.getNameForBand());
        List<TemplateTableColumn> columns = new LinkedList<>();
        for (int j = 0; j < reportRegion.getRegionProperties().size(); j++) {
            RegionProperty regionProperty = reportData.getReportRegions().get(i).getRegionProperties().get(j);
            String caption = regionProperty.getHierarchicalLocalizedNameExceptRoot().replace('.', ' ');
            TemplateTableColumn column = dataManager.create(TemplateTableColumn.class);
            column.setPosition(j);
            column.setKey(regionProperty.getHierarchicalNameExceptRoot());
            column.setCaption(caption);
            columns.add(column);
        }
        band.setColumns(columns);
        bands.add(band);
    }
    templateTableDescription.setTemplateTableBands(bands);
    return TemplateTableDescription.toJsonString(templateTableDescription).getBytes(StandardCharsets.UTF_8);
}
Also used : TemplateTableDescription(io.jmix.reports.entity.table.TemplateTableDescription) RegionProperty(io.jmix.reports.entity.wizard.RegionProperty) TemplateTableColumn(io.jmix.reports.entity.table.TemplateTableColumn) TemplateTableBand(io.jmix.reports.entity.table.TemplateTableBand) ReportRegion(io.jmix.reports.entity.wizard.ReportRegion) LinkedList(java.util.LinkedList)

Example 3 with TemplateTableBand

use of io.jmix.reports.entity.table.TemplateTableBand in project jmix by jmix-framework.

the class TableEditFragment method onColumnsTableCreate.

@Subscribe("columnsTable.create")
protected void onColumnsTableCreate(Action.ActionPerformedEvent event) {
    TemplateTableBand selectBand = bandsTable.getSingleSelected();
    if (selectBand != null) {
        TemplateTableColumn item = metadata.create(TemplateTableColumn.class);
        item.setPosition(tableColumnsDc.getItems().size());
        tableColumnsDc.getMutableItems().add(item);
    } else {
        notifications.create(Notifications.NotificationType.HUMANIZED).withCaption(messages.getMessage(getClass(), "template.bandRequired")).show();
    }
}
Also used : TemplateTableColumn(io.jmix.reports.entity.table.TemplateTableColumn) TemplateTableBand(io.jmix.reports.entity.table.TemplateTableBand) Subscribe(io.jmix.ui.screen.Subscribe)

Example 4 with TemplateTableBand

use of io.jmix.reports.entity.table.TemplateTableBand in project jmix by jmix-framework.

the class TableEditFragment method onBandsTableCreate.

@Subscribe("bandsTable.create")
protected void onBandsTableCreate(Action.ActionPerformedEvent event) {
    TemplateTableBand templateTableBand = metadata.create(TemplateTableBand.class);
    templateTableBand.setPosition(tableBandsDc.getItems().size());
    tableBandsDc.getMutableItems().add(templateTableBand);
}
Also used : TemplateTableBand(io.jmix.reports.entity.table.TemplateTableBand) Subscribe(io.jmix.ui.screen.Subscribe)

Example 5 with TemplateTableBand

use of io.jmix.reports.entity.table.TemplateTableBand in project jmix by jmix-framework.

the class TableEditFragment method bandsTableRemoveAfterActionPerformedHandler.

@Install(to = "bandsTable.remove", subject = "afterActionPerformedHandler")
protected void bandsTableRemoveAfterActionPerformedHandler(RemoveOperation.AfterActionPerformedEvent<TemplateTableBand> event) {
    TemplateTableBand deletedColumn = event.getItems().iterator().next();
    int deletedPosition = deletedColumn.getPosition();
    for (TemplateTableBand templateTableBand : tableBandsDc.getItems()) {
        if (templateTableBand.getPosition() > deletedPosition) {
            int currentPosition = templateTableBand.getPosition();
            templateTableBand.setPosition(currentPosition - 1);
        }
    }
}
Also used : TemplateTableBand(io.jmix.reports.entity.table.TemplateTableBand) Install(io.jmix.ui.screen.Install)

Aggregations

TemplateTableBand (io.jmix.reports.entity.table.TemplateTableBand)6 TemplateTableColumn (io.jmix.reports.entity.table.TemplateTableColumn)3 Subscribe (io.jmix.ui.screen.Subscribe)2 BandData (com.haulmont.yarg.structure.BandData)1 KeyValueEntity (io.jmix.core.entity.KeyValueEntity)1 EntityMap (io.jmix.reports.app.EntityMap)1 JmixTableData (io.jmix.reports.entity.JmixTableData)1 TemplateTableDescription (io.jmix.reports.entity.table.TemplateTableDescription)1 RegionProperty (io.jmix.reports.entity.wizard.RegionProperty)1 ReportRegion (io.jmix.reports.entity.wizard.ReportRegion)1 ReportingException (io.jmix.reports.exception.ReportingException)1 Install (io.jmix.ui.screen.Install)1 LinkedList (java.util.LinkedList)1