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