Search in sources :

Example 1 with FilterDescription

use of org.activityinfo.legacy.shared.reports.content.FilterDescription in project activityinfo by bedatadriven.

the class ExcelChartRenderer method render.

@Override
public void render(Workbook book, PivotChartReportElement element) {
    /* Generate the actual pivot table data */
    element.getContent().getData();
    /* Generate the excel sheet */
    new BaseExcelRenderer<PivotChartReportElement>(book, element) {

        @Override
        public List<FilterDescription> generateFilterDescriptions() {
            return element.getContent().getFilterDescriptions();
        }

        @Override
        public void generate() {
            PivotTableData data = this.element.getContent().getData();
            List<PivotTableData.Axis> rows = data.getRootRow().getLeaves();
            List<PivotTableData.Axis> cols = data.getRootColumn().getLeaves();
            Row headerRow = sheet.createRow(rowIndex++);
            for (int i = 0; i != cols.size(); ++i) {
                Cell colHeaderCell = headerRow.createCell(i + 1);
                colHeaderCell.setCellValue(factory.createRichTextString(cols.get(i).flattenLabel()));
            }
            for (int i = 0; i != rows.size(); ++i) {
                Row row = sheet.createRow(rowIndex++);
                // header
                Cell rowHeaderCell = row.createCell(0);
                rowHeaderCell.setCellValue(factory.createRichTextString(rows.get(i).flattenLabel()));
                // values
                for (int j = 0; j != cols.size(); ++j) {
                    Cell valueCell = row.createCell(j + 1);
                    valueCell.setCellValue(rows.get(i).getCell(cols.get(j)).getValue());
                }
            }
        }
    };
}
Also used : PivotTableData(org.activityinfo.legacy.shared.reports.content.PivotTableData) FilterDescription(org.activityinfo.legacy.shared.reports.content.FilterDescription) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell)

Example 2 with FilterDescription

use of org.activityinfo.legacy.shared.reports.content.FilterDescription in project activityinfo by bedatadriven.

the class BaseGenerator method generateFilterDescriptions.

protected List<FilterDescription> generateFilterDescriptions(Filter filter, Set<DimensionType> excludeDims, User user) {
    List<FilterDescription> list = new ArrayList<FilterDescription>();
    Set<DimensionType> filterDims = filter.getRestrictedDimensions();
    filterDims.removeAll(excludeDims);
    for (DimensionType type : filterDims) {
        DimensionLabels labels = dispatcher.execute(new GetDimensionLabels(type, filter.getRestrictions(type)));
        list.add(new FilterDescription(type, labels.getLabels()));
    }
    return list;
}
Also used : DimensionType(org.activityinfo.legacy.shared.command.DimensionType) GetDimensionLabels(org.activityinfo.legacy.shared.command.GetDimensionLabels) FilterDescription(org.activityinfo.legacy.shared.reports.content.FilterDescription) ArrayList(java.util.ArrayList) GetDimensionLabels(org.activityinfo.legacy.shared.command.GetDimensionLabels) DimensionLabels(org.activityinfo.legacy.shared.command.GetDimensionLabels.DimensionLabels)

Example 3 with FilterDescription

use of org.activityinfo.legacy.shared.reports.content.FilterDescription in project activityinfo by bedatadriven.

the class StaticElementRenderTest method setup.

@Before
public void setup() throws JAXBException {
    report = Reports.parseXml(getClass(), "static.xml");
    report.setContent(new ReportContent());
    report.getContent().setFilterDescriptions(new ArrayList<FilterDescription>());
}
Also used : ReportContent(org.activityinfo.legacy.shared.reports.content.ReportContent) FilterDescription(org.activityinfo.legacy.shared.reports.content.FilterDescription) Before(org.junit.Before)

Example 4 with FilterDescription

use of org.activityinfo.legacy.shared.reports.content.FilterDescription in project activityinfo by bedatadriven.

the class ExcelTableRenderer method render.

@Override
public void render(Workbook book, TableElement element) {
    final TableData tableData = element.getContent().getData();
    new BaseExcelTableRenderer<TableElement, TableColumn>(book, element) {

        @Override
        public List<FilterDescription> generateFilterDescriptions() {
            return element.getContent().getFilterDescriptions();
        }

        @Override
        public void generate() {
            /* Generate the column headers for the table */
            initColHeaderStyles(element.getRootColumn());
            generateColumnHeaders(0, element.getRootColumn());
            int headerHeight = rowIndex;
            sheet.createFreezePane(element.getFrozenColumns(), headerHeight);
            /* Prepare the generators and indexes */
            List<TableColumn> leaves = element.getRootColumn().getLeaves();
            String[] colIndexes = new String[leaves.size()];
            for (int i = 0; i != leaves.size(); ++i) {
                colIndexes[i] = leaves.get(i).getSitePropertyName();
            }
            for (SiteDTO rowData : tableData.getRows()) {
                Row row = sheet.createRow(rowIndex++);
                for (int i = 0; i != colIndexes.length; ++i) {
                    Object value = null;
                    if (colIndexes[i] != null) {
                        value = rowData.get(colIndexes[i]);
                    }
                    Cell cell = row.createCell(i);
                    if (value instanceof Number) {
                        cell.setCellValue(((Number) value).doubleValue());
                    } else if (value instanceof Date) {
                        cell.setCellValue((Date) value);
                    } else if (value instanceof Boolean) {
                        cell.setCellValue((Boolean) value);
                    } else if (value != null) {
                        cell.setCellValue(factory.createRichTextString(value.toString()));
                    }
                }
            }
        }
    };
}
Also used : FilterDescription(org.activityinfo.legacy.shared.reports.content.FilterDescription) TableColumn(org.activityinfo.legacy.shared.reports.model.TableColumn) Date(java.util.Date) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Row(org.apache.poi.ss.usermodel.Row) TableData(org.activityinfo.legacy.shared.reports.content.TableData) Cell(org.apache.poi.ss.usermodel.Cell)

Example 5 with FilterDescription

use of org.activityinfo.legacy.shared.reports.content.FilterDescription in project activityinfo by bedatadriven.

the class ExcelPivotTableRenderer method render.

@Override
public void render(Workbook book, PivotTableReportElement element) {
    /* Generate the actual pivot table data */
    final PivotTableData table = element.getContent().getData();
    /* Generate the excel sheet */
    new BaseExcelTableRenderer<PivotTableReportElement, PivotTableData.Axis>(book, element) {

        @Override
        public List<FilterDescription> generateFilterDescriptions() {
            return element.getContent().getFilterDescriptions();
        }

        private CellStyle[] rowHeaderStyles;

        @Override
        public void generate() {
            /* Initialize Cell Styles */
            initColHeaderStyles(table.getRootColumn());
            initRowHeaderStyles();
            /* Generate the column headers */
            generateColumnHeaders(1, table.getRootColumn());
            int headerHeight = rowIndex;
            /* Create the rows */
            // row headers are in column 1
            sheet.setColumnWidth(0, 40 * 256);
            generateRows(table.getRootRow().getChildList(), 0);
            /* Finalize the sheet */
            sheet.setRowSumsBelow(false);
            sheet.createFreezePane(1, headerHeight);
        }

        protected void initRowHeaderStyles() {
            int depth = table.getRootRow().getDepth();
            rowHeaderStyles = new CellStyle[depth];
            for (int i = 0; i != depth; ++i) {
                CellStyle style = book.createCellStyle();
                style.setIndention((short) i);
                style.setWrapText(true);
                Font font = createBaseFont();
                if (i + 1 != depth) {
                    /* Has sub headers */
                    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
                } else {
                    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
                }
                style.setFont(font);
                rowHeaderStyles[i] = style;
            }
        }

        protected void generateRows(List<PivotTableData.Axis> rows, int indent) {
            for (PivotTableData.Axis pivotRow : rows) {
                Row row = sheet.createRow(rowIndex++);
                Cell headerCell = row.createCell(0);
                headerCell.setCellValue(factory.createRichTextString(pivotRow.getLabel()));
                headerCell.setCellStyle(rowHeaderStyles[indent]);
                if (pivotRow.isLeaf()) {
                    for (Entry<PivotTableData.Axis, Integer> entry : colIndexMap.entrySet()) {
                        PivotTableData.Cell pivotCell = pivotRow.getCell(entry.getKey());
                        if (pivotCell != null) {
                            Cell cell = row.createCell(entry.getValue());
                            cell.setCellValue(pivotCell.getValue());
                        }
                    }
                } else {
                    int groupStart = rowIndex;
                    generateRows(pivotRow.getChildList(), indent + 1);
                    int groupEnd = rowIndex;
                    sheet.groupRow(groupStart, groupEnd);
                }
            }
        }
    };
}
Also used : FilterDescription(org.activityinfo.legacy.shared.reports.content.FilterDescription) PivotTableData(org.activityinfo.legacy.shared.reports.content.PivotTableData) List(java.util.List)

Aggregations

FilterDescription (org.activityinfo.legacy.shared.reports.content.FilterDescription)6 PivotTableData (org.activityinfo.legacy.shared.reports.content.PivotTableData)2 Cell (org.apache.poi.ss.usermodel.Cell)2 Row (org.apache.poi.ss.usermodel.Row)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 DimensionType (org.activityinfo.legacy.shared.command.DimensionType)1 GetDimensionLabels (org.activityinfo.legacy.shared.command.GetDimensionLabels)1 DimensionLabels (org.activityinfo.legacy.shared.command.GetDimensionLabels.DimensionLabels)1 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)1 ReportContent (org.activityinfo.legacy.shared.reports.content.ReportContent)1 TableData (org.activityinfo.legacy.shared.reports.content.TableData)1 PivotTableReportElement (org.activityinfo.legacy.shared.reports.model.PivotTableReportElement)1 TableColumn (org.activityinfo.legacy.shared.reports.model.TableColumn)1 DummyPivotTableData2 (org.activityinfo.server.report.DummyPivotTableData2)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 Before (org.junit.Before)1 Test (org.junit.Test)1