use of org.activityinfo.legacy.shared.reports.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);
}
use of org.activityinfo.legacy.shared.reports.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());
}
use of org.activityinfo.legacy.shared.reports.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()));
}
}
}
}
};
}
use of org.activityinfo.legacy.shared.reports.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"));
}
use of org.activityinfo.legacy.shared.reports.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"));
}
Aggregations