Search in sources :

Example 1 with CalculateSummaryRowValuesCommand

use of org.eclipse.nebula.widgets.nattable.summaryrow.command.CalculateSummaryRowValuesCommand in project nebula.widgets.nattable by eclipse.

the class SummaryRowIntegrationTest method shouldSummarizeAskPriceColumnImmediatelyOnPreCalculation.

@Test
public void shouldSummarizeAskPriceColumnImmediatelyOnPreCalculation() throws Exception {
    // Trigger summary calculation via command
    this.natTable.doCommand(new CalculateSummaryRowValuesCommand());
    Object askPriceSummary = this.natTable.getDataValueByPosition(this.askPriceColumnIndex, 4);
    assertEquals("110.0", askPriceSummary.toString());
}
Also used : CalculateSummaryRowValuesCommand(org.eclipse.nebula.widgets.nattable.summaryrow.command.CalculateSummaryRowValuesCommand) Test(org.junit.Test)

Example 2 with CalculateSummaryRowValuesCommand

use of org.eclipse.nebula.widgets.nattable.summaryrow.command.CalculateSummaryRowValuesCommand in project nebula.widgets.nattable by eclipse.

the class GroupByDataLayer method doCommand.

@Override
public boolean doCommand(ILayerCommand command) {
    if (command instanceof CalculateSummaryRowValuesCommand) {
        // summary values
        for (int i = 0; i < getRowCount(); i++) {
            if (this.treeData.getDataAtIndex(i) instanceof GroupByObject) {
                for (int j = 0; j < getColumnCount(); j++) {
                    LabelStack labelStack = getConfigLabelsByPosition(j, i);
                    final IGroupBySummaryProvider<T> summaryProvider = getGroupBySummaryProvider(labelStack);
                    if (summaryProvider != null) {
                        GroupByObject groupByObject = (GroupByObject) this.treeData.getDataAtIndex(i);
                        final List<T> children = getItemsInGroup(groupByObject);
                        final int col = j;
                        this.valueCache.getCalculatedValue(j, i, new GroupByValueCacheKey(j, i, groupByObject), false, new ICalculator() {

                            @Override
                            public Object executeCalculation() {
                                return summaryProvider.summarize(col, children);
                            }
                        });
                    }
                }
            }
        }
    // we do not return true here, as there might be other layers
    // involved in the composition that also need to calculate the
    // summary values immediately
    } else if (command instanceof DisposeResourcesCommand) {
        // ensure to clear the caches to avoid memory leaks
        this.treeFormat.clearComparatorCache();
        this.valueCache.killCache();
        this.valueCache.dispose();
    }
    return super.doCommand(command);
}
Also used : DisposeResourcesCommand(org.eclipse.nebula.widgets.nattable.command.DisposeResourcesCommand) CalculateSummaryRowValuesCommand(org.eclipse.nebula.widgets.nattable.summaryrow.command.CalculateSummaryRowValuesCommand) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ICalculator(org.eclipse.nebula.widgets.nattable.util.ICalculator)

Example 3 with CalculateSummaryRowValuesCommand

use of org.eclipse.nebula.widgets.nattable.summaryrow.command.CalculateSummaryRowValuesCommand in project nebula.widgets.nattable by eclipse.

the class NatExporter method exportLayer.

/**
 * Exports the given {@link ILayer} to the given {@link OutputStream} using
 * the provided {@link ITableExporter}.
 *
 * @param exporter
 *            The {@link ITableExporter} that should be used for exporting.
 * @param outputStream
 *            The {@link OutputStream} that should be used to write the
 *            export to.
 * @param layer
 *            The {@link ILayer} that should be exported.
 * @param configRegistry
 *            The {@link IConfigRegistry} needed to retrieve the export
 *            configurations.
 *
 * @since 1.5
 */
protected void exportLayer(final ITableExporter exporter, final OutputStream outputStream, final ILayer layer, final IConfigRegistry configRegistry) {
    if (this.preRender) {
        AutoResizeHelper.autoResize(layer, configRegistry);
    }
    IClientAreaProvider originalClientAreaProvider = layer.getClientAreaProvider();
    // This needs to be done so that the layer can return all the cells
    // not just the ones visible in the viewport
    layer.doCommand(new TurnViewportOffCommand());
    setClientAreaToMaximum(layer);
    // if a SummaryRowLayer is in the layer stack, we need to ensure that
    // the values are calculated
    layer.doCommand(new CalculateSummaryRowValuesCommand());
    // if a FormulaDataProvider is involved, we need to ensure that the
    // formula evaluation is disabled so the formula itself is exported
    // instead of the calculated value
    layer.doCommand(new DisableFormulaEvaluationCommand());
    ProgressBar progressBar = null;
    if (this.shell != null) {
        Shell childShell = new Shell(this.shell.getDisplay(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
        // $NON-NLS-1$
        childShell.setText(Messages.getString("NatExporter.exporting"));
        int endRow = layer.getRowCount() - 1;
        progressBar = new ProgressBar(childShell, SWT.SMOOTH);
        progressBar.setMinimum(0);
        progressBar.setMaximum(endRow);
        progressBar.setBounds(0, 0, 400, 25);
        progressBar.setFocus();
        childShell.pack();
        childShell.open();
    }
    try {
        exporter.exportTable(this.shell, progressBar, outputStream, layer, configRegistry);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        // These must be fired at the end of the thread execution
        layer.setClientAreaProvider(originalClientAreaProvider);
        layer.doCommand(new TurnViewportOnCommand());
        layer.doCommand(new EnableFormulaEvaluationCommand());
        if (progressBar != null) {
            Shell childShell = progressBar.getShell();
            progressBar.dispose();
            childShell.dispose();
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) CalculateSummaryRowValuesCommand(org.eclipse.nebula.widgets.nattable.summaryrow.command.CalculateSummaryRowValuesCommand) TurnViewportOnCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand) IClientAreaProvider(org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider) DisableFormulaEvaluationCommand(org.eclipse.nebula.widgets.nattable.formula.command.DisableFormulaEvaluationCommand) EnableFormulaEvaluationCommand(org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommand) TurnViewportOffCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand) ProgressBar(org.eclipse.swt.widgets.ProgressBar) IOException(java.io.IOException)

Aggregations

CalculateSummaryRowValuesCommand (org.eclipse.nebula.widgets.nattable.summaryrow.command.CalculateSummaryRowValuesCommand)3 IOException (java.io.IOException)1 DisposeResourcesCommand (org.eclipse.nebula.widgets.nattable.command.DisposeResourcesCommand)1 DisableFormulaEvaluationCommand (org.eclipse.nebula.widgets.nattable.formula.command.DisableFormulaEvaluationCommand)1 EnableFormulaEvaluationCommand (org.eclipse.nebula.widgets.nattable.formula.command.EnableFormulaEvaluationCommand)1 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)1 TurnViewportOffCommand (org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand)1 TurnViewportOnCommand (org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand)1 ICalculator (org.eclipse.nebula.widgets.nattable.util.ICalculator)1 IClientAreaProvider (org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider)1 ProgressBar (org.eclipse.swt.widgets.ProgressBar)1 Shell (org.eclipse.swt.widgets.Shell)1 Test (org.junit.Test)1