use of org.activityinfo.shared.report.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;
}
use of org.activityinfo.shared.report.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());
}
}
}
};
}
use of org.activityinfo.shared.report.content.FilterDescription in project activityinfo by bedatadriven.
the class StaticElementRenderTest method getStatic.
public Report getStatic() throws JAXBException {
Report r = parseXml("static.xml");
r.setContent(new ReportContent());
r.getContent().setFilterDescriptions(new ArrayList<FilterDescription>());
return r;
}
use of org.activityinfo.shared.report.content.FilterDescription in project activityinfo by bedatadriven.
the class SearchPresenter method onSearch.
@Override
public void onSearch(SearchEvent searchEvent) {
if (!Strings.isNullOrEmpty(searchEvent.getQuery())) {
view.setSearchQuery(searchEvent.getQuery());
view.getLoadingMonitor().beforeRequest();
service.execute(new Search(searchEvent.getQuery()), view.getLoadingMonitor(), new AsyncCallback<SearchResult>() {
@Override
public void onFailure(Throwable caught) {
// TODO handle failure
view.getLoadingMonitor().onServerError();
}
@Override
public void onSuccess(SearchResult result) {
view.setSearchResults(result.getPivotTabelData());
Filter filter = result.getPivotTabelData() == null ? null : result.getPivotTabelData().getEffectiveFilter();
view.setFilter(createFilter(filter, result.getPivotTabelData()));
view.getLoadingMonitor().onCompleted();
view.setSitePoints(SitePointList.fromSitesList(result.getRecentAdditions()));
view.setSites(fromSitesList(result.getRecentAdditions()));
}
private Map<DimensionType, List<SearchResultEntity>> createFilter(Filter effectiveFilter, PivotContent pivotContent) {
Map<DimensionType, List<SearchResultEntity>> newFilter = new HashMap<DimensionType, List<SearchResultEntity>>();
if (effectiveFilter != null) {
for (DimensionType type : effectiveFilter.getRestrictedDimensions()) {
List<SearchResultEntity> entities = new ArrayList<SearchResultEntity>();
for (Integer entityId : effectiveFilter.getRestrictions(type)) {
String name = getName(entityId, type, pivotContent);
String link = GWT.getHostPageBaseURL() + "#search/" + type.toString() + ":" + name;
SearchResultEntity entity = new SearchResultEntity(entityId, name, link, type);
entities.add(entity);
}
newFilter.put(type, entities);
}
}
return newFilter;
}
private String getName(Integer entityId, DimensionType type, PivotContent pivotTable) {
for (FilterDescription fd : pivotTable.getFilterDescriptions()) {
if (fd.getDimensionType() == type) {
return fd.getLabels().get(entityId);
}
}
return "noName";
}
});
}
}
use of org.activityinfo.shared.report.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);
}
}
}
};
}
Aggregations