« Return to Thread: Add a 'Total's' row to a FunctionList

Re: Add a 'Total's' row to a FunctionList

by James Lemieux :: Rate this Message:

Reply to Author | View in Thread

GL has architecture for computing "calculations" based on List elements. It's new as of about 2 months ago. You can find it in the latest builds, though no screencasts exist for it yet.

This would be the equivalent of Gerrit's Totalizer, though it is intended to assume almost nothing about the value that it is computing (i.e. it might not be a sum... in fact it might not even be numeric).

As for how to add these totals into your table, I'd say a custom TableModel is your best bet. It would extend or delegate to an EventTableModel for all data rows, but would report an extra row reserved just for the total information. Since using the GL calculations as the last row in a JTable is a very common usage, this may be code that should be present in the GL core...

James

On Wed, Mar 26, 2008 at 6:13 AM, Gerrit Cap <Gerrit.Cap@...> wrote:
I don't think there is a generic solution for this. But I've created in
the past a TotalizingList which is very similar to the FunctionList.

In short this TotalizingList
   1) maintains a copy of the original source list as an extension of
TransformingList
   2) creates an extra object "the total"
   3) size() == source.size() +1, and also adjust get(int) ...
   4) defines an interface Totalizer which defines an addToTotal method
and removeFromTotal method called when objects are inserted or deleted
(update == delete of old + insert of new)
   5) on listChanges -> delegate to the totalizer function and
broadcast list changes as source list changes + last row also updated.


Gerrit

Dan MacLeod wrote:
> I have a FunctionList that creates new Objects based on a GroupingList, and a
> JTable that displays the results. I'd like to add a 'Total' row at the
> bottom of the table that adds up the values in each column, is there a way
> to do this?
>

--
-------------------- Marble Consulting ----------------------
Gerrit Cap                      http://www.marble.be/
OO Solutions Engineer           mailto:Gerrit.Cap@...
Marble Consulting               gsm : +32 475 72.94.36
Vinkenbosstraat 13              tel : +32 16 89.50.55
B-3001 Heverlee                 fax : +32 16 89.50.58



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


 « Return to Thread: Add a 'Total's' row to a FunctionList