Search in sources :

Example 1 with RowUpdateEvent

use of net.sourceforge.nattable.layer.event.RowUpdateEvent in project translationstudio8 by heartsome.

the class SummaryRowLayer method getDataValueByPosition.

/**
	 * Calculates the summary for the column using the {@link ISummaryProvider} from the {@link IConfigRegistry}.<br/>
	 * In order to prevent the table from freezing (for large data sets), the summary is calculated in a separate Thread. While
	 * summary is being calculated {@link ISummaryProvider#DEFAULT_SUMMARY_VALUE} is returned.
	 * 
	 * NOTE: Since this is a {@link IUniqueIndexLayer} sitting close to the {@link DataLayer}, columnPosition == columnIndex
	 */
@Override
public Object getDataValueByPosition(final int columnPosition, final int rowPosition) {
    if (isSummaryRowPosition(rowPosition)) {
        if (getSummaryFromCache(columnPosition) != null) {
            return getSummaryFromCache(columnPosition);
        } else {
            // Get the summary provider from the configuration registry
            LabelStack labelStack = getConfigLabelsByPosition(columnPosition, rowPosition);
            String[] configLabels = labelStack.getLabels().toArray(ArrayUtil.STRING_TYPE_ARRAY);
            final ISummaryProvider summaryProvider = configRegistry.getConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, DisplayMode.NORMAL, configLabels);
            // If there is no Summary provider - skip processing
            if (summaryProvider == ISummaryProvider.NONE) {
                return ISummaryProvider.DEFAULT_SUMMARY_VALUE;
            }
            // Start thread to calculate summary
            new Thread() {

                @Override
                public void run() {
                    Object summaryValue = calculateColumnSummary(columnPosition, summaryProvider);
                    addToCache(columnPosition, summaryValue);
                    fireLayerEvent(new RowUpdateEvent(SummaryRowLayer.this, rowPosition));
                }
            }.start();
        }
        return ISummaryProvider.DEFAULT_SUMMARY_VALUE;
    }
    return super.getDataValueByPosition(columnPosition, rowPosition);
}
Also used : LabelStack(net.sourceforge.nattable.layer.LabelStack) RowUpdateEvent(net.sourceforge.nattable.layer.event.RowUpdateEvent)

Aggregations

LabelStack (net.sourceforge.nattable.layer.LabelStack)1 RowUpdateEvent (net.sourceforge.nattable.layer.event.RowUpdateEvent)1