Skip to main content



      Home
Home » Eclipse Projects » NatTable » Working with the SummaryRowLayer and TreeLayer
Working with the SummaryRowLayer and TreeLayer [message #1243311] Mon, 10 February 2014 15:40 Go to next message
Eclipse UserFriend
Hello,

I modified the _572_TreeGridExample to include the SummaryRowLayer. It seems that the SummaryRow will only calculate the sum of the cells whos row group is expanded. Is this intentional?

Looking at the SummationSummaryProvider:

public Object summarize(int columnIndex) {
    int rowCount = dataProvider.getRowCount();
			
    float summaryValue = 0;

    for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
        Object dataValue = dataProvider.getDataValue(columnIndex, rowIndex);

        if (dataValue instanceof Number) {
            summaryValue = summaryValue + Float.parseFloat(dataValue.toString());
        } else if (strict) {
            return DEFAULT_SUMMARY_VALUE;
        }
    }

    return summaryValue;
}


When the tree is fully expanded the DataProvider returns 10 rows and the method calculates the sum for the entire column. However, when the a row group is collapsed, the DataProvider returns 9 rows and the method does not calculate the sum using the collapsed row. This is true for both the GlazedListDataProvider and the ListDataProvider.

I would like to be able to code the SummaryProvider so that it will calculate the sum using the underlying data regardless of whether the data in that row is hidden by the tree.

Is this possible with one of the existing DataProviders? or possibly some other class?

Thanks,

Evan

[Updated on: Mon, 10 February 2014 15:41] by Moderator

Re: Working with the SummaryRowLayer and TreeLayer [message #1243624 is a reply to message #1243311] Tue, 11 February 2014 03:07 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

the reason for this is quite simple and relies on how GlazedLists works. To keep it simple, the GlazedLists implementations are transformations of the underlying list. So if you collapse a node, the children are not simply hidden by some mechanism, for the TreeList they don't exist. If you iterate over the TreeList, the children of a collapsed node will not be retrieved.
So it is not the IDataProvider implementation that causes the described behaviour, it is the collection on which it operates.

The IDataProvider used to show the data in the NatTable is of course using the TreeList to get the correct values.

To solve that you have two options AFAICS:
1. Create a second IDataProvider that is working with the underlying list. This one should only be used for the summary provider to not breaking any other functionality.
2. Create a custom summary provider that is not operating on an IDataProvider but on the original list itself.

IMHO option 1 should be easier as you don't need to take care of column positions.

BTW, the same applies for filtering. But in case of filtering this behaviour might be intended to only calculate the summary of the values that are not filtered. Otherwise you need the same modifications.

HTH,
Dirk
Re: Working with the SummaryRowLayer and TreeLayer [message #1243793 is a reply to message #1243624] Tue, 11 February 2014 07:57 Go to previous message
Eclipse UserFriend
Thanks for the reply Dirk. I'll give that a shot.
Previous Topic:Which line is currently visible?
Next Topic:Pre-requisites for multi-edit(pressing F2) feature to work for the text cell editors
Goto Forum:
  


Current Time: Mon Jul 07 08:29:57 EDT 2025

Powered by FUDForum. Page generated in 0.03149 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top