use of org.eclipse.nebula.widgets.nattable.util.ICalculator in project nebula.widgets.nattable by eclipse.
the class GroupByDataLayer method getDataValueByPosition.
/**
* This method is used to retrieve a data value of an {@link ILayerCell}. It
* is intended to be used for conditional formatting. It allows to specify
* the {@link LabelStack} and to disable background calculation processing,
* since the conditional formatting needs the summary value without a delay.
*
* @param columnPosition
* The column position of the cell whose data value is requested.
* @param rowPosition
* The row position of the cell whose data value is requested.
* @param labelStack
* The {@link LabelStack} of the cell whose data value is
* requested. Needed to retrieve a possible existing
* {@link IGroupBySummaryProvider}.
* @param calculateInBackground
* <code>true</code> to calculate the summary value in the
* background, <code>false</code> if the calculation should be
* processed in the UI thread.
* @return The data value for the {@link ILayerCell} at the given
* coordinates.
*/
public Object getDataValueByPosition(final int columnPosition, final int rowPosition, LabelStack labelStack, boolean calculateInBackground) {
if (labelStack.hasLabel(GROUP_BY_OBJECT)) {
GroupByObject groupByObject = (GroupByObject) this.treeData.getDataAtIndex(rowPosition);
final IGroupBySummaryProvider<T> summaryProvider = getGroupBySummaryProvider(labelStack);
if (summaryProvider != null) {
final List<T> children = getItemsInGroup(groupByObject);
return this.valueCache.getCalculatedValue(columnPosition, rowPosition, new GroupByValueCacheKey(columnPosition, rowPosition, groupByObject), calculateInBackground, new ICalculator() {
@Override
public Object executeCalculation() {
return summaryProvider.summarize(columnPosition, children);
}
});
}
}
return super.getDataValueByPosition(columnPosition, rowPosition);
}
use of org.eclipse.nebula.widgets.nattable.util.ICalculator 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);
}
Aggregations