Search in sources :

Example 6 with RegionProperty

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;
}
Also used : SpreadsheetMLPackage(org.docx4j.openpackaging.packages.SpreadsheetMLPackage) RegionProperty(io.jmix.reports.entity.wizard.RegionProperty) WorksheetPart(org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart) PartName(org.docx4j.openpackaging.parts.PartName) Parts(org.docx4j.openpackaging.parts.Parts) Part(org.docx4j.openpackaging.parts.Part) WorksheetPart(org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart) ReportRegion(io.jmix.reports.entity.wizard.ReportRegion) Styles(org.docx4j.openpackaging.parts.SpreadsheetML.Styles)

Example 7 with RegionProperty

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();
    }
}
Also used : RegionProperty(io.jmix.reports.entity.wizard.RegionProperty)

Example 8 with RegionProperty

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);
    }
}
Also used : RegionProperty(io.jmix.reports.entity.wizard.RegionProperty) ArrayList(java.util.ArrayList)

Example 9 with RegionProperty

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);
    }
}
Also used : RegionProperty(io.jmix.reports.entity.wizard.RegionProperty) EntityTreeNode(io.jmix.reports.entity.wizard.EntityTreeNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 10 with RegionProperty

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);
}
Also used : RegionProperty(io.jmix.reports.entity.wizard.RegionProperty) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) ReportRegion(io.jmix.reports.entity.wizard.ReportRegion)

Aggregations

RegionProperty (io.jmix.reports.entity.wizard.RegionProperty)10 ReportRegion (io.jmix.reports.entity.wizard.ReportRegion)7 ArrayList (java.util.ArrayList)4 MetaClass (io.jmix.core.metamodel.model.MetaClass)2 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)2 TemplateTableBand (io.jmix.reports.entity.table.TemplateTableBand)1 TemplateTableColumn (io.jmix.reports.entity.table.TemplateTableColumn)1 TemplateTableDescription (io.jmix.reports.entity.table.TemplateTableDescription)1 EntityTreeNode (io.jmix.reports.entity.wizard.EntityTreeNode)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 SpreadsheetMLPackage (org.docx4j.openpackaging.packages.SpreadsheetMLPackage)1 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)1 Part (org.docx4j.openpackaging.parts.Part)1 PartName (org.docx4j.openpackaging.parts.PartName)1 Parts (org.docx4j.openpackaging.parts.Parts)1 Styles (org.docx4j.openpackaging.parts.SpreadsheetML.Styles)1 WorksheetPart (org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart)1 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)1 Tbl (org.docx4j.wml.Tbl)1