Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2004

Tip: Looking for answers? Try searching our database.

recommended approach when filtering List or TableModels?

Thread view: 
Rogan Dawes - 02 Apr 2004 09:47 GMT
Hi folks,

I am writing a program that presents results in a table. The model
updates a ListModel, which the user interface then wraps with a
ListFilter (custom class that accepts a Filter returning true or false
for each object in the ListModel).

I then convert the ListModel to a TableModel, by specifying an "object
to columns" mapping, and finally wrap the whole lot in a Tablesorter
(from Sun's recently updated example).

So the structure looks like:

Model exports ListModel wrapped in ListFilter, wrapped in
ListTableModelAdaptor, wrapped in TableSorter.

Maybe this is entirely the wrong way to go about it, but it has worked
so far ;-)

However, my problem now is that I would like the GUI to be able to get
the original object based on the selected row in the table, regardless
of the degree of filtering or sorting.

Currently my approach is to include an "ID" column in the table, which
can be used to query the underlying model to get back to the object in
question. This seems clumsy, and I was wondering if anyone had a better
suggestion on how to do this?

One thought that I just had was to pass the actual object to the table
in one column (e.g. the ID column), and either override the toString()
method to return the ID, or implement a custom Renderer to display the
Object's ID field.

This sounds OK at first blush, but it detracts from the configurability
of the "ListTableModelAdaptor and RowModel" approach that converts from
the ListModel to a TableModel to require a custom Renderer :-(

Better ideas? As you can probably tell, I am a bit of a novice at
programming GUI's (and fairly new to OOP as well ;-)

All the code in question (and no, it is not a SSCCE) is available from
the OWASP sourceforge CVS page (http://sourceforge.net/projects/owasp ->
CVS -> Browse CVS Repository -> WebScarab)

Regards,

Rogan
Signature

Rogan Dawes
nntp_AT*dawes-DOT*za_DOT-net

Karsten Lentzsch - 02 Apr 2004 14:38 GMT
> Model exports ListModel wrapped in ListFilter, wrapped in
> ListTableModelAdaptor, wrapped in TableSorter.

I'd say the adapter chain is fine. You may consider
replacing or extending the TableSorter, so that it
can map indice sets as needed by the SelectionModel.

Karsten


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.