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);
}
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);
}
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();
}
}
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);
}
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);
}
}
}
Aggregations