Yes I've done filtering before.  I think the major issue with your
approach is that you're trying to combine the filtering with the
TableModel.  I've always seen the TableModel as the output from
the filtering of a set of data.  I may or may not choose to implement
this in the same class as the TableModel is implemented depending
on the merits of an individual case.

The main reason I'd steer clear of combining it directly into the
TableModel functions are related to the row count and index. I assume
from what you've said that every call to getRowCount would pass the
whole data set to see what's visible.  Also how do you then determine
the row for a row index?  By counting from the beginning each time?
(JTable definitely expects row indexes to go 0..n-1 - though that's
not documented in TableModel either.)  I would suggest such an
approach would only work well for tables with relatively few rows
of data.

Most, if not all, of the filtering I've done is tailored to the
particular data being represented.  When a filter condition is
changed I'd update the TableModel and fire the appropriate result.

If you want to define something more generic I'd suggest defining
a filtering mechanism to operate on a TableModel and output another
TableModel (could just be an adapter of row index mappings onto the
original) as a result.  If you insist on still using non-0..n-1
indexes for the columns you would have to define a method in your
interface to demand the extra information.  Alternatively, referring
back to your original interface definition, if you documented a
restriction that only filters established through setFilterForColumn
would be actioned then any implementation could know the set of
indexes as the set of index values passed to that method.

Dave Wathen
Canzonet Limited
Phone: +44 (0)20 8660 5171
Mobile: +44 (0)7968 167934
Fax: +44 (0)870 051 7664
http://www.canzonet.com
mailto:[EMAIL PROTECTED]

-----Original Message-----
From: Ralph Kar [mailto:[EMAIL PROTECTED]]
Sent: 11 September 2002 14:26
To: Dave Wathen
Cc: [EMAIL PROTECTED]
Subject: RE: Problems with row filtering in JTable


Hi Dave,

I agree with you that setAutoCreateColumnsFromModel() and
createDefaultColumnsFromModel() do not really belong into this discussion.

You are also right that the internal consistency of the TableModel is the
issue here. The thing is that a TableModel alone is good for nothing. The
whole JTable MVC depends on different data structures working together.
This also means that the model index as it is referenced in TableModel can
actually be stored in TableColumn (via setModelIndex()). I am well aware
of the different indices used in the TableColumnModel and the TableModel.
Fact is that the model index provides an excellent way to customize your
data access. As long as the mapping between the view index and the model
index is consistent you're well off.

The problem occurs with the row exclusion filtering, because this is when
the TableModel needs to call its own method getValueAt(), which
unfortunately is not possible without knowing the exact indices. Yes, you
could get those from the JTable itself, but this would break the MVC. In
our specific case that wouldn't be a problem, but I don't want to break
the initial design.

>From your website I can see that you are also doing a lot of UI
development for customers. Did no one ever ask for row exclusion
filtering? Do you know any good leads?

I already sent an email to Philip. But I haven't talked to any of the
Swing folks for a while so I am not aware if Philip still works for Sun or
whether he is still responsible for the JTable or not. If I get an answer,
I will definetely post it here.

Greetings,
Ralph

-----------------------------------------------------
 Ralph Kar               |
 Software Developer      | mailto:[EMAIL PROTECTED]
 RTS Realtime Systems AG | http://www.rtsgroup.net
-----------------------------------------------------


On Wed, 11 Sep 2002, Dave Wathen wrote:

> JTable.setAutoCreateColumnsFromModel(false) is a performance
> feature to prevent the JTable doing unnecessary work when you're
> going to supply your own column model anyway.
>
> TableColumn.setModelIndex() has nothing to do with this discussion.
> As Evan already pointed out the ordering of a TableColumnModel does
> not have to match the TableModel.  The value set here determines
> which column in the TableModel a particular column in a table relates
> to.  Your issue concerned the relationship between getColumnCount
> and getValueAt in TableModel.  The fact that another data structure
> allows random access into the columns of a TableModel bears no
> relevance to the internal consistency of TableModel.
>
> You say you guess you'll have to ask Philip.  If you mean Philip
> Milne, and you have access to him, why don't you just do that and
> ask him to post an answer and enlighten us all.
>
> Dave Wathen
> Canzonet Limited
> Phone: +44 (0)20 8660 5171
> Mobile: +44 (0)7968 167934
> Fax: +44 (0)870 051 7664
> http://www.canzonet.com
> mailto:[EMAIL PROTECTED]
>
> -----Original Message-----
> From: Ralph Kar [mailto:[EMAIL PROTECTED]]
> Sent: 11 September 2002 13:23
> To: Dave Wathen
> Cc: [EMAIL PROTECTED]
> Subject: RE: Problems with row filtering in JTable
>
>
> Well, arguing this way I could also say the opposite. When the column
> index is supposed to be 0..n-1 (considering your argument), then why do
> the following methods exist?
>
>    JTable.setAutoCreateColumnsFromModel(false);
>    TableColumn.setModelIndex();
>
> Ralph
>
> -----------------------------------------------------
>  Ralph Kar               |
>  Software Developer      | mailto:[EMAIL PROTECTED]
>  RTS Realtime Systems AG | http://www.rtsgroup.net
> -----------------------------------------------------
>
> On Wed, 11 Sep 2002, Dave Wathen wrote:
>
> > It's not documented as such but I suspect that 0..n-1 was the intention.
> > Looking at the source of JTable the method createDefaultColumnsFromModel
> > relies on this being so.
> >
> > Dave Wathen
> > Canzonet Limited
> > Phone: +44 (0)20 8660 5171
> > Mobile: +44 (0)7968 167934
> > Fax: +44 (0)870 051 7664
> > http://www.canzonet.com
> > mailto:[EMAIL PROTECTED]
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> > Behalf Of Ralph Kar
> > Sent: 11 September 2002 08:52
> > To: [EMAIL PROTECTED]
> > Cc: [EMAIL PROTECTED]
> > Subject: Re: Problems with row filtering in JTable
> >
> >
> > Hi Evan,
> >
> > I am afraid, I have to tell you that the model index of the columns does
> > not necessarly have to be from 0..n-1. The view index of the columns is
> > 0..n-1, but the model index can be anything.
> >
> > For example, we use the model index to reference field ids that
represent
> > the data displayed in the column. The field id can be any positive
> > integer.
> >
> > The implementation of the DefaultTableModel uses 0..n-1 as column index,
> > but it does not have to be that way. I am also not aware that the
> > specification of the TableModel interface requires the index to be that
> > way. I guess I have to ask Philip about it.
> >
> > Ralph
> >
> > -----------------------------------------------------
> >  Ralph Kar               |
> >  Software Developer      | mailto:[EMAIL PROTECTED]
> >  RTS Realtime Systems AG | http://www.rtsgroup.net
> > -----------------------------------------------------
> >
> >
> > On Tue, 10 Sep 2002, [EMAIL PROTECTED] wrote:
> >
> > > Ralph Kar wrote:
> > > > Hi all,
> > > [...]
> > > > The problem arises when I want to
> > > > implement isRowVisible() (which itself needs to be called by
> > > > TableModel.getRowCount()). This method needs to go over all columns
> that
> > > > have filters attached to them, get their cell values and apply the
> > filter.
> > > > This means I need to call TableModel.getValueAt() from that method.
> > > > TableModel.getValueAt() requires the columnIndex as parameter. I am
> > unable
> > > > to determine this parameter. TableModel.getColumnCount() only
returns
> > the
> > > > number of columns but not the actual indices. Those do not
necessarily
> > be
> > > > sequential from 0..n.
> > >
> > > Ralph,
> > >
> > > If a TableModel has a columnCount of n, the indices are always 0..n-1.
> > >
> > > The headings displayed in the table may be something totally
different.
> > That
> > > information is in the columnIdentifiers in the TableColumnModel.
> > >
> > > Also, the JTable itself (the view) keeps a separate set of indices
> because
> > the
> > > user is allowed to move the columns around.  It provides two methods
for
> > > converting back and forth between view indices and model indices:
> > >
> > > public int convertColumnIndexToModel(int viewColumnIndex)
> > > - Maps the index of the column in the view at viewColumnIndex to the
> index
> > of
> > > the column in the table model.
> > > public int convertColumnIndexToView(int modelColumnIndex)
> > > - Maps the index of the column in the table model at modelColumnIndex
to
> > the
> > > index of the column in the view.
> > >
> > > In the common case, the view indices and model indices are the same.
> > >
> > > Evan McLain
> > > junquemale -at- yahoo.com
> > >
> > >
> > >
> > >
> >
> > _______________________________________________
> > Advanced-swing mailing list
> > [EMAIL PROTECTED]
> > http://eos.dk/mailman/listinfo/advanced-swing
> >
> >
>
>
>


_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to