use of io.jmix.reports.entity.wizard.RegionProperty in project jmix by jmix-framework.
the class XlsxGenerator method generatePackage.
@Override
protected OpcPackage generatePackage(ReportData reportData) throws Docx4JException, JAXBException {
SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
// String sheetInternalName = ((Messages) AppBeans.get(Messages.NAME)).getMessage(getClass(), SHEET);
WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/" + SHEET + ".xml"), SHEET, 1);
SheetData sheetData = sheet.getJaxbElement().getSheetData();
ObjectFactory factory = org.xlsx4j.jaxb.Context.getsmlObjectFactory();
CTCalcPr ctCalcPr = factory.createCTCalcPr();
ctCalcPr.setCalcMode(STCalcMode.AUTO);
pkg.getWorkbookPart().getJaxbElement().setCalcPr(ctCalcPr);
Styles styles = new Styles(new PartName("/xl/styles.xml"));
styles.setJaxbElement(generateStyleSheet(factory));
DefinedNames definedNames = factory.createDefinedNames();
// first row of sheet is '1'
long rowNum = 1;
long startedRowForRegion;
long endedRowForRegion;
int maxColCount = 0;
for (ReportRegion reportRegion : reportData.getReportRegions()) {
if (reportRegion.isTabulatedRegion()) {
// insert empty row before table
rowNum++;
// first column of sheet is '1'
int colNum = 1;
for (RegionProperty regionProperty : reportRegion.getRegionProperties()) {
sheetData.getRow().add(createRow(factory, regionProperty.getHierarchicalLocalizedNameExceptRoot(), colNum++, rowNum));
}
rowNum++;
startedRowForRegion = rowNum;
colNum = 1;
for (RegionProperty regionProperty : reportRegion.getRegionProperties()) {
sheetData.getRow().add(createRow(factory, reportTemplatePlaceholder.getPlaceholderValue(regionProperty.getHierarchicalNameExceptRoot(), reportRegion), colNum++, rowNum));
}
endedRowForRegion = rowNum;
maxColCount = maxColCount > colNum ? maxColCount : colNum;
rowNum++;
// insert empty row after table
rowNum++;
} else {
startedRowForRegion = rowNum;
for (RegionProperty regionProperty : reportRegion.getRegionProperties()) {
Row row = factory.createRow();
row.setR(rowNum);
row.getC().add(createCell(factory, regionProperty.getHierarchicalLocalizedNameExceptRoot() + ":", 1, rowNum));
row.getC().add(createCell(factory, reportTemplatePlaceholder.getPlaceholderValue(regionProperty.getHierarchicalNameExceptRoot(), reportRegion), 2, rowNum));
sheetData.getRow().add(row);
rowNum++;
}
endedRowForRegion = rowNum - 1;
maxColCount = maxColCount > 2 ? maxColCount : 2;
}
addDefinedNames(SHEET, factory, definedNames, startedRowForRegion, endedRowForRegion, reportRegion);
}
List<Cols> lstCols = sheet.getJaxbElement().getCols();
Cols cols = factory.createCols();
for (int i = 0; i < maxColCount; i++) {
Col col = factory.createCol();
col.setMin(i + 1);
col.setMax(i + 1);
col.setBestFit(Boolean.TRUE);
col.setCustomWidth(true);
col.setWidth(30.);
cols.getCol().add(col);
}
lstCols.add(cols);
pkg.getWorkbookPart().getJaxbElement().setDefinedNames(definedNames);
sheet.addTargetPart(styles);
Parts parts = pkg.getParts();
Part workBook = parts.get(new PartName("/xl/workbook.xml"));
workBook.addTargetPart(styles);
return pkg;
}
use of io.jmix.reports.entity.wizard.RegionProperty in project jmix by jmix-framework.
the class RegionEditor method onRemoveItemAction.
@Subscribe("propertiesTable.removeItemAction")
public void onRemoveItemAction(Action.ActionPerformedEvent event) {
for (RegionProperty item : propertiesTable.getSelected()) {
reportRegionPropertiesTableDc.getMutableItems().remove(item);
normalizeRegionPropertiesOrderNum();
}
}
use of io.jmix.reports.entity.wizard.RegionProperty in project jmix by jmix-framework.
the class RegionEditor method normalizeRegionPropertiesOrderNum.
protected void normalizeRegionPropertiesOrderNum() {
long normalizedIdx = 0;
List<RegionProperty> allItems = new ArrayList<>(reportRegionPropertiesTableDc.getItems());
for (RegionProperty item : allItems) {
// first must to be 1
item.setOrderNum(++normalizedIdx);
}
}
use of io.jmix.reports.entity.wizard.RegionProperty in project jmix by jmix-framework.
the class RegionEditor method addProperty.
protected void addProperty() {
@SuppressWarnings("unchecked") List<EntityTreeNode> nodesList = CollectionUtils.transform(reportRegionPropertiesTableDc.getItems(), o -> ((RegionProperty) o).getEntityTreeNode());
Set<EntityTreeNode> alreadyAddedNodes = new HashSet<>(nodesList);
Set<EntityTreeNode> selectedItems = entityTree.getSelected();
List<RegionProperty> addedItems = new ArrayList<>();
boolean alreadyAdded = false;
for (EntityTreeNode entityTreeNode : selectedItems) {
if (entityTreeNode.getMetaClassName() != null) {
continue;
}
if (!alreadyAddedNodes.contains(entityTreeNode)) {
RegionProperty regionProperty = metadata.create(RegionProperty.class);
regionProperty.setEntityTreeNode(entityTreeNode);
// first element must be not zero cause later we do sorting by multiplying that values
regionProperty.setOrderNum((long) reportRegionPropertiesTableDc.getItems().size() + 1);
reportRegionPropertiesTableDc.getMutableItems().add(regionProperty);
addedItems.add(regionProperty);
} else {
alreadyAdded = true;
}
}
if (addedItems.isEmpty()) {
if (alreadyAdded) {
notifications.create(Notifications.NotificationType.TRAY).withCaption(messages.getMessage(getClass(), "elementsAlreadyAdded")).show();
} else if (selectedItems.size() != 0) {
notifications.create(Notifications.NotificationType.HUMANIZED).withCaption(messages.getMessage(getClass(), "selectPropertyFromEntity")).show();
} else {
notifications.create(Notifications.NotificationType.TRAY).withCaption(messages.getMessage(getClass(), "elementsWasNotAdded")).show();
}
} else {
propertiesTable.setSelected(addedItems);
}
}
use of io.jmix.reports.entity.wizard.RegionProperty in project jmix by jmix-framework.
the class ChartGenerator method generatePieChart.
protected byte[] generatePieChart(ReportData reportData) {
ReportRegion reportRegion = reportData.getReportRegions().get(0);
PieChartDescription pieChartDescription = metadata.create(PieChartDescription.class);
pieChartDescription.setBandName(reportRegion.getNameForBand());
pieChartDescription.setUnits("");
List<RegionProperty> regionProperties = reportRegion.getRegionProperties();
RegionProperty firstProperty = regionProperties.get(0);
pieChartDescription.setTitleField(firstProperty.getEntityTreeNode().getMetaPropertyName());
if (regionProperties.size() > 1) {
for (int i = 1; i < regionProperties.size(); i++) {
RegionProperty regionProperty = regionProperties.get(i);
MetaClass parentMetaClass = metadata.getClass(regionProperty.getEntityTreeNode().getParentMetaClassName());
MetaProperty metaProperty = parentMetaClass.getProperty(regionProperty.getEntityTreeNode().getMetaPropertyName());
Class<?> javaType = metaProperty.getJavaType();
if (Number.class.isAssignableFrom(javaType)) {
pieChartDescription.setValueField(metaProperty.getName());
break;
}
}
}
return AbstractChartDescription.toJsonString(pieChartDescription).getBytes(StandardCharsets.UTF_8);
}
Aggregations