Search in sources :

Example 1 with TableColumn

use of org.activityinfo.shared.report.model.TableColumn in project activityinfo by bedatadriven.

the class ItextTableRenderer method renderTable.

private void renderTable(Document document, TableData data) throws DocumentException {
    int colDepth = data.getRootColumn().getDepth();
    List<TableColumn> colLeaves = data.getRootColumn().getLeaves();
    int colBreadth = colLeaves.size();
    Table table = new Table(colBreadth, 1);
    table.setUseVariableBorders(true);
    table.setWidth(100.0f);
    table.setBorderWidth(0);
    for (int depth = 1; depth <= colDepth; ++depth) {
        List<TableColumn> columns = data.getRootColumn().getDescendantsAtDepth(depth);
        for (TableColumn column : columns) {
            Cell cell = ThemeHelper.columnHeaderCell(column.getLabel(), column.isLeaf(), computeHAlign(column));
            cell.setColspan(Math.max(1, column.getChildren().size()));
            cell.setRowspan(colDepth - depth - column.getDepth() + 1);
            table.addCell(cell);
        }
    }
    table.endHeaders();
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
    NumberFormat numberFormat = NumberFormat.getIntegerInstance();
    numberFormat.setGroupingUsed(true);
    for (SiteDTO row : data.getRows()) {
        for (TableColumn column : colLeaves) {
            Object value = row.get(column.getSitePropertyName());
            String label = "";
            if (value instanceof Date) {
                label = dateFormat.format(value);
            } else if (value instanceof Number) {
                label = numberFormat.format(value);
            } else if (value != null) {
                label = value.toString();
            }
            table.addCell(ThemeHelper.bodyCell(label, false, 0, true, computeHAlign(column)));
        }
    }
    document.add(table);
}
Also used : Table(com.lowagie.text.Table) DateFormat(java.text.DateFormat) SiteDTO(org.activityinfo.shared.dto.SiteDTO) TableColumn(org.activityinfo.shared.report.model.TableColumn) Cell(com.lowagie.text.Cell) Date(java.util.Date) NumberFormat(java.text.NumberFormat)

Example 2 with TableColumn

use of org.activityinfo.shared.report.model.TableColumn in project activityinfo by bedatadriven.

the class TableGenerator method generateData.

public TableData generateData(TableElement element, Filter filter) {
    GetSites query = new GetSites(filter);
    if (!element.getSortBy().isEmpty()) {
        TableColumn sortBy = element.getSortBy().get(0);
        query.setSortInfo(new SortInfo(sortBy.getSitePropertyName(), sortBy.isOrderAscending() ? SortDir.ASC : SortDir.DESC));
    }
    SiteResult sites = getDispatcher().execute(query);
    return new TableData(element.getRootColumn(), sites.getData());
}
Also used : SiteResult(org.activityinfo.shared.command.result.SiteResult) GetSites(org.activityinfo.shared.command.GetSites) TableData(org.activityinfo.shared.report.content.TableData) TableColumn(org.activityinfo.shared.report.model.TableColumn) SortInfo(com.extjs.gxt.ui.client.data.SortInfo)

Example 3 with TableColumn

use of org.activityinfo.shared.report.model.TableColumn 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.shared.report.content.FilterDescription) TableColumn(org.activityinfo.shared.report.model.TableColumn) Date(java.util.Date) SiteDTO(org.activityinfo.shared.dto.SiteDTO) Row(org.apache.poi.ss.usermodel.Row) TableData(org.activityinfo.shared.report.content.TableData) Cell(org.apache.poi.ss.usermodel.Cell)

Example 4 with TableColumn

use of org.activityinfo.shared.report.model.TableColumn in project activityinfo by bedatadriven.

the class TableGeneratorTest method testMap.

// 
// @Test
// public void tableWithMap() {
// 
// MapReportElement map = new MapReportElement();
// map.setBaseMapId(GoogleBaseMap.ROADMAP.getId());
// 
// BubbleMapLayer layer = new BubbleMapLayer();
// layer.addIndicator(INDICATOR_ID);
// map.addLayer(layer);
// 
// TableElement table = new TableElement();
// table.setMap(map);
// 
// TableColumn column = new TableColumn("Location", "location.name");
// table.addColumn(column);
// 
// TableColumn mapColumn = new TableColumn("Map", "map");
// table.addColumn(mapColumn);
// 
// DispatcherSync dispatcher = createDispatcher();
// TableGenerator gtor = new TableGenerator(dispatcher, new
// MapGenerator(dispatcher, null, null));
// gtor.generate(user, table, null, null);
// 
// Assert.assertNotNull("content is set", table.getContent());
// 
// TableData data = table.getContent().getData();
// List<SiteDTO> rows = data.getRows();
// Assert.assertEquals("row count", 1, rows.size());
// 
// SiteDTO row = rows.get(0);
// assertThat((String)row.get(column.getSitePropertyName()),
// equalTo("tampa bay"));
// assertThat((String)row.get("map"), equalTo("1"));
// }
@Test
public void testMap() {
    TableElement table = new TableElement();
    table.addColumn(new TableColumn("Index", "map"));
    table.addColumn(new TableColumn("Site", "location.name"));
    MapReportElement map = new MapReportElement();
    map.setBaseMapId("map1");
    CircledMapLayer layer = new BubbleMapLayer();
    layer.setLabelSequence(new ArabicNumberSequence());
    map.addLayer(layer);
    table.setMap(map);
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(GetSites.class))).andReturn(new SiteResult(dummySite())).anyTimes();
    TileBaseMap baseMap1 = new TileBaseMap();
    baseMap1.setId("map1");
    baseMap1.setMinZoom(0);
    baseMap1.setMaxZoom(12);
    baseMap1.setCopyright("(C)");
    baseMap1.setName("Grand Canyon");
    baseMap1.setTileUrlPattern("http://s/test.png");
    expect(dispatcher.execute(isA(GetBaseMaps.class))).andReturn(new BaseMapResult(Collections.singletonList(baseMap1)));
    replay(dispatcher);
    TableGenerator gtor = new TableGenerator(dispatcher, new MapGenerator(dispatcher, new MockIndicatorDAO()));
    gtor.generate(user, table, null, null);
    MapContent mapContent = map.getContent();
    Assert.assertNotNull("map content", mapContent);
    Assert.assertEquals("marker count", 1, mapContent.getMarkers().size());
    Assert.assertEquals("label on marker", "1", ((BubbleMapMarker) mapContent.getMarkers().get(0)).getLabel());
    Map<Integer, String> siteLabels = mapContent.siteLabelMap();
    Assert.assertEquals("site id in map", "1", siteLabels.get(1));
    SiteDTO row = table.getContent().getData().getRows().get(0);
    Assert.assertEquals("label on row", "1", row.get("map"));
}
Also used : ArabicNumberSequence(org.activityinfo.shared.report.model.labeling.ArabicNumberSequence) MapContent(org.activityinfo.shared.report.content.MapContent) BaseMapResult(org.activityinfo.shared.command.result.BaseMapResult) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) TableColumn(org.activityinfo.shared.report.model.TableColumn) TableElement(org.activityinfo.shared.report.model.TableElement) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) SiteResult(org.activityinfo.shared.command.result.SiteResult) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) CircledMapLayer(org.activityinfo.shared.report.model.layers.CircledMapLayer) GetBaseMaps(org.activityinfo.shared.command.GetBaseMaps) SiteDTO(org.activityinfo.shared.dto.SiteDTO) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 5 with TableColumn

use of org.activityinfo.shared.report.model.TableColumn in project activityinfo by bedatadriven.

the class TableGeneratorTest method simpleTable.

@Test
public void simpleTable() {
    TableElement table = new TableElement();
    TableColumn column = new TableColumn("Location", "location.name");
    table.addColumn(column);
    TableGenerator gtor = new TableGenerator(createDispatcher(), null);
    gtor.generate(user, table, null, null);
    Assert.assertNotNull("content is set", table.getContent());
    TableData data = table.getContent().getData();
    List<SiteDTO> rows = data.getRows();
    Assert.assertEquals("row count", 1, rows.size());
    SiteDTO row = rows.get(0);
    assertThat((String) row.get(column.getSitePropertyName()), equalTo("tampa bay"));
}
Also used : SiteDTO(org.activityinfo.shared.dto.SiteDTO) TableData(org.activityinfo.shared.report.content.TableData) TableColumn(org.activityinfo.shared.report.model.TableColumn) TableElement(org.activityinfo.shared.report.model.TableElement) Test(org.junit.Test)

Aggregations

TableColumn (org.activityinfo.shared.report.model.TableColumn)5 SiteDTO (org.activityinfo.shared.dto.SiteDTO)4 TableData (org.activityinfo.shared.report.content.TableData)3 Date (java.util.Date)2 SiteResult (org.activityinfo.shared.command.result.SiteResult)2 TableElement (org.activityinfo.shared.report.model.TableElement)2 Test (org.junit.Test)2 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)1 Cell (com.lowagie.text.Cell)1 Table (com.lowagie.text.Table)1 DateFormat (java.text.DateFormat)1 NumberFormat (java.text.NumberFormat)1 DispatcherSync (org.activityinfo.server.command.DispatcherSync)1 GetBaseMaps (org.activityinfo.shared.command.GetBaseMaps)1 GetSites (org.activityinfo.shared.command.GetSites)1 BaseMapResult (org.activityinfo.shared.command.result.BaseMapResult)1 TileBaseMap (org.activityinfo.shared.map.TileBaseMap)1 FilterDescription (org.activityinfo.shared.report.content.FilterDescription)1 MapContent (org.activityinfo.shared.report.content.MapContent)1 MapReportElement (org.activityinfo.shared.report.model.MapReportElement)1