« 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

Benoit,

   My first thought of approaching this problem is to use a CompositeList like so:

EventList myNormalData = ....
CompositeList c = new CompositeList(myNormalData.getPublisher(), myNormalData.getReadWriteLock());

EventList myTotalsRecord = c.createMemberList();
myTotalsRecord.add(<an object representing your totals>);

EventTableModel tm = new EventTableModel(c, new MyTableFormat());
EventSelectionModel sm = new EventSelectionModel(c);

In this way, c is composed of your normal data, and a singleton list containing only a single object that reports your totals. It backs both the data model and selection model, so they both agree on the number of rows.

If you want to make the totals row unselectable, you could do that with simple ListSelectionListeners...

Does this work for you?

James


On Wed, May 6, 2009 at 12:15 PM, Benoitx <benoitx@...> wrote:

Sorry to 're-use' this but this is exactly what we have done and it worked
ok.

We have recently introduced the use of the EventSelectionModel and
GlazedLists.replaceAll method.

This is causing a lot of exception when one clicks on the last row of the
JTable (the extra row).

The EventSelectionModel calls
           listSelection.setSelection(index0, index1);

which in turns checks the size of the list... and of course, the list
contains one less element than rows...

Unfortunately, EventSelectionModel is final and there is no way to give it a
special implementation of ListSelection since it is created in the
EventSelectionModel constructor....

HELP!!!

Any suggestion?

Thanks!

Benoit


James Lemieux wrote:
>
> Override getRowCount() to return 1 more than super.getRowCount();
>
> On Wed, Mar 26, 2008 at 11:34 AM, Dan MacLeod <dan.macleod@...> wrote:
>
>>
>> I'm currently using an EventTableModel. If I create a class that extends
>> the
>> EventTableModel how would I tell it to report an extra line?
>>
>>
>>
>> James Lemieux wrote:
>> >
>> > 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@...
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Add-a-%27Total%27s%27-row-to-a-FunctionList-tp16258704p16314279.html
>> Sent from the GlazedLists - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>>
>
>


-----
Thanks & Regards,

Benoit

http://www.Appendium.com   http://objectlab.blogspot.com

--
View this message in context: http://www.nabble.com/Add-a-%27Total%27s%27-row-to-a-FunctionList-tp16258704p23413543.html
Sent from the GlazedLists - User mailing list archive at Nabble.com.


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


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