views:

458

answers:

1

I looked up how to use multiple filters on here with a regular table and the answers all pointed to GlazedLists. However, the answers didn't specify how to use it. I was able to get one filter to work but do not know how to get more than one. For one filter I used:

  // nameE is a BasicEventList containing classes (name) which 
  // contain the table values
  TextFilterList filtered = new TextFilterList(nameE);
  JTextField filterEdit = filtered.getFilterEdit();

  // Inside the table value class (name) there is a filter for myName
  public void getFilterStrings(List baseList) {
      baseList.add(myName);
  }

Duplicating the code and creating another JTextField does not work. I looked this problem up and it appears CompositeMatcherEditor may work. The problem is I do not know how to implement this.

Also, I am using Eclipse. I downloaded GlazedLists 1.8.0 and dropped it into Eclipse. However, I can't use it. I have red squares all over (except for the source folder)! I even added the jar file.

I hope I have explained myself correctly. Please let me know if I need to expand.

My Pastebin: Name, Browser, TableFormat, TableModel

+2  A: 

TextFilterList is deprecated - see the javadocs - but that's a side issue.

There are several approaches you can use here - if you want really simple, then just wrap your filter list in another filter list:

EventList filtered = new FilterList(new FilterList(nameE, myFirstMatcherEditor), mySecondMatcherEditor);

A better way is to use multiple matcher editors to create a CompositeMatcherEditor:

EventList filtered = new FilterList(nameE, new CompositeMatcherEditor(myFirstMatcherEditor, mySecondMatcherEditor));

you can use setMode to control whether your editors are combined using AND or OR behavior.

Here's Must Read info on using filter lists.

The screencasts available here are also worth the few minutes investment.

Kevin Day
The first option worked wonderfully. To make a third you would use: `EventList filtered = new FilterList(new FilterList(new FilterList(new FilterList(nameE, myFirstMatcherEditor), mySecondMatcherEditor), myLastMatcherEditor);` Is that correct? The second option gave me an error. `CompositeMatcherEditor is not defined`
twodayslate
Here's the API docs: http://publicobject.com/glazedlists/glazedlists-1.8.0/api/ - without question, CompositeMatcherEditor is the correct way to do this - stacking filter lists like you've done will work, but it's inefficient.
Kevin Day
PS - your error message indicates that you just don't have the right package imports. If you aren't sure about how to import the necessary package (ca.odell.glazedlists.matchers), let me know. I *really* recommend that you look at the must read info I posted above - there is very good sample code in both that and the screencasts.
Kevin Day
I had `ca.odell.glazedlists.*;` imported. The screenshots seem to be dead in the *Must Read Info*. Is the site broken on just my end or yours as well?
twodayslate
Right - you don't have the correct import. You have to also import co.odell.glazedlists.matchers.*The must read info link I posted doesn't have screen shots at all - just lots of insanely useful text. If you are asking about the Screen*casts* (the second link I posted), those work just fine for me.
Kevin Day
The packages were working I just had bad coding. http://pastebin.org/50808Thanks a bunch! You were a huge help!
twodayslate