Search in sources :

Example 1 with TableBlock

use of org.xwiki.rendering.block.TableBlock in project xwiki-platform by xwiki.

the class AbstractTableBlockDataSource method buildDataset.

@Override
public void buildDataset(String macroContent, Map<String, String> parameters, MacroTransformationContext context) throws MacroExecutionException {
    validateParameters(parameters);
    TableBlock tableBlock = getTableBlock(macroContent, context);
    int[] dataRange = getDataRange(tableBlock);
    TableDatasetBuilder datasetBuilder;
    setChartModel(new SimpleChartModel());
    switch(getDatasetType()) {
        case CATEGORY:
            datasetBuilder = new TableCategoryDatasetBuilder();
            break;
        case PIE:
            datasetBuilder = new TablePieDatasetBuilder();
            break;
        case TIMETABLE_XY:
            datasetBuilder = new TableTimeTableXYDatasetBuilder();
            break;
        default:
            throw new MacroExecutionException(String.format("Unsupported dataset type [%s]", getDatasetType().getName()));
    }
    setAxes();
    datasetBuilder.setLocaleConfiguration(getLocaleConfiguration());
    datasetBuilder.setParameters(parameters);
    if (SERIES_COLUMNS.equals(series)) {
        datasetBuilder.setTranspose(true);
    }
    buildDataset(tableBlock, dataRange, datasetBuilder);
    setDataset(datasetBuilder.getDataset());
}
Also used : SimpleChartModel(org.xwiki.rendering.internal.macro.chart.source.SimpleChartModel) TableBlock(org.xwiki.rendering.block.TableBlock) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException)

Example 2 with TableBlock

use of org.xwiki.rendering.block.TableBlock in project xwiki-platform by xwiki.

the class DocumentTableBlockDataSource method getTableBlock.

@Override
protected TableBlock getTableBlock(String macroContent, MacroTransformationContext context) throws MacroExecutionException {
    XDOM xdom = computeXDOM(context);
    // Find the correct table block.
    List<TableBlock> tableBlocks = xdom.getBlocks(new ClassBlockMatcher(TableBlock.class), Block.Axes.DESCENDANT);
    TableBlock result = null;
    this.logger.debug("Table id is [{}], there are [{}] tables in the document [{}]", new Object[] { this.tableId, tableBlocks.size(), this.documentReference });
    if (null != tableId) {
        for (TableBlock tableBlock : tableBlocks) {
            String id = tableBlock.getParameter("id");
            if (null != id && id.equals(this.tableId)) {
                result = tableBlock;
                break;
            }
        }
    } else {
        result = (tableBlocks.size() > 0) ? tableBlocks.get(0) : null;
    }
    if (null == result) {
        throw new MacroExecutionException("Unable to find a matching data table.");
    }
    return result;
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) TableBlock(org.xwiki.rendering.block.TableBlock) ClassBlockMatcher(org.xwiki.rendering.block.match.ClassBlockMatcher) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException)

Example 3 with TableBlock

use of org.xwiki.rendering.block.TableBlock in project xwiki-platform by xwiki.

the class MacroContentTableBlockDataSource method getTableBlock.

@Override
protected TableBlock getTableBlock(String macroContent, MacroTransformationContext context) throws MacroExecutionException {
    // Since we are using an inline source the macro content cannot be empty/null.
    if (StringUtils.isEmpty(macroContent)) {
        throw new MacroExecutionException("A Chart Macro using an inline source must have a data table defined in " + "its content.");
    }
    // Parse the macro content into an XDOM.
    XDOM xdom = this.macroContentParser.parse(macroContent, context, true, false);
    // Take the first TableBlock found in the macro content.
    List<TableBlock> tableBlocks = xdom.getBlocks(new ClassBlockMatcher(TableBlock.class), Block.Axes.DESCENDANT);
    if (tableBlocks.size() == 0) {
        throw new MacroExecutionException("Unable to locate a suitable data table.");
    }
    return tableBlocks.get(0);
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) TableBlock(org.xwiki.rendering.block.TableBlock) ClassBlockMatcher(org.xwiki.rendering.block.match.ClassBlockMatcher) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException)

Aggregations

TableBlock (org.xwiki.rendering.block.TableBlock)3 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)3 XDOM (org.xwiki.rendering.block.XDOM)2 ClassBlockMatcher (org.xwiki.rendering.block.match.ClassBlockMatcher)2 SimpleChartModel (org.xwiki.rendering.internal.macro.chart.source.SimpleChartModel)1