Filtering JTables with multiply filters
Hello Java Forum members,
I want to create 2 filters, 1 filter that does a "or filtering" in column x and a "and filtering" over all rows.
I have a combobox that can handle 2 values or more. Each combobox controles a column.
http://img26.imageshack.us/img26/7061/tablecx.png
So if u see my table example i want to filter on "Daniel" & "Gerrit" and on "Today".
So the result should be:
http://img717.imageshack.us/img717/1660/table2a.png
My problem is to join the andFilter and the orFilter.
Code:
public void setFilter( JTable tabel ){
ArrayList filterNames = new ArrayList();
ArrayList filterInhoud = null;
final ArrayList totalList = new ArrayList();
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tabel.getModel());
List<RowFilter<Object,Object>> filters = null;
Iterator<String> itr = tableFilters.keySet().iterator();
while(itr.hasNext()){
filterNames.add(itr.next());
}
totalList.clear();
for(int i = 0; i < filterNames.size(); i++ ){
filterInhoud = (ArrayList) tableFilters.get(filterNames.get(i));
totalList.addAll(filterInhoud);
}
filters = new ArrayList<RowFilter<Object,Object>>(totalList.size());
for( int i=0; i < totalList.size(); i++ ){
filters.add( RowFilter.regexFilter( "^"+((Filter)totalList.get(i)).getWaarde().toString()+"$" , ((Filter)totalList.get(i)).getKolomnr() ) );
}
sorter.setRowFilter(RowFilter.andFilter(filters));
tabel.setRowSorter(sorter);
}
The code above helps me with the combination of "Daniel" and "Today" but not when i try "Daniel" or "Gerrit" and "Today".
I know i need to use the orFilter also, but i cant find a way to use it. So i was thinking of overriding the methode "include"
Code:
RowFilter<Object, Object> filter = new RowFilter<Object, Object>() {
@Override
public boolean include(Entry<? extends Object, ? extends Object> entry) {
return true;
}
};
What u guys think i should do? Please help me here, im totaly stuck :D: