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());
}
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);
}
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();
}
}
}
Aggregations