net.coderazzi.filters
Class TableFilter

java.lang.Object
  extended by javax.swing.RowFilter
      extended by net.coderazzi.filters.BaseFilter
          extended by net.coderazzi.filters.ComposedFilter
              extended by net.coderazzi.filters.AndFilter
                  extended by net.coderazzi.filters.TableFilter
All Implemented Interfaces:
IFilter, IFilterObserver

public class TableFilter
extends AndFilter

TableFilter represents a RowFilter instance that can be attached to a JTable to compose dynamically the outcome of one or more filter editors. As such, it is a dynamic filter, which updates the table when there are changes in any of the composed sub filters.

Users require instancing TableFilter instances only when managing their own filter editors. Note that the TableFilterHeader already handles its own TableFilter, and keeps track of any table changes, updating automatically the editors.

When users instanciate directly TableFilter objects, care must be taken to update the associated editors when the table model changes.

In Java 6, a filter is automatically associated to a RowSorter, so JTable instances with a TableFilter must define their own RowSorter. Being this not the case, the TableFilter will automatically set the default RowSorter in that table. That is, tables with a TableFilter will always have sorting enabled.

The RowSorter interface does not support filtering capabilities, which are only enabled via the DefaultRowSorter class. If the registered table uses any sorter that does not subclass the DefaultRowSorter class, the TableFilter will perform no filtering at all.

Author:
Luis M Pena - lu@coderazzi.net

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.RowFilter
RowFilter.ComparisonType, RowFilter.Entry<M,I>
 
Field Summary
 
Fields inherited from class net.coderazzi.filters.ComposedFilter
filters
 
Fields inherited from class net.coderazzi.filters.BaseFilter
filterObservers
 
Constructor Summary
TableFilter()
          Default constructor
TableFilter(JTable table)
          Basic constructor, setting directly the controlled table
 
Method Summary
 boolean enableNotifications(boolean enable)
          Temporarily enable/disable notifications to the observers, including the registered JTable.
 JTable getTable()
          Returns the associated table
 boolean isAutoSelection()
          Returns the autoselection mode
 void sendPendingNotifications()
          Method to force the sending of notifications, even if they are currently temporarily disabled.
 void setAutoSelection(boolean enable)
          Sets the autoselection mode
 void setTable(JTable table)
          Method to set the associated table.
 
Methods inherited from class net.coderazzi.filters.AndFilter
include
 
Methods inherited from class net.coderazzi.filters.ComposedFilter
addFilter, detach, filterUpdated, getFilterObservables, removeFilter
 
Methods inherited from class net.coderazzi.filters.BaseFilter
addFilterObserver, getFilterObservers, removeFilterObserver, reportFilterUpdatedToObservers
 
Methods inherited from class javax.swing.RowFilter
andFilter, dateFilter, notFilter, numberFilter, orFilter, regexFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableFilter

public TableFilter()
Default constructor


TableFilter

public TableFilter(JTable table)
Basic constructor, setting directly the controlled table

Method Detail

setTable

public void setTable(JTable table)
Method to set the associated table. If the table had not defined its own RowSorter, the default one is automatically created.


getTable

public JTable getTable()
Returns the associated table


enableNotifications

public boolean enableNotifications(boolean enable)

Temporarily enable/disable notifications to the observers, including the registered JTable.

Multiple calls to this method can be issued, but the caller must ensure that there are as many calls with true parameter as with false parameter, as the notifications are only re-enabled when the zero balance is reached.


sendPendingNotifications

public void sendPendingNotifications()

Method to force the sending of notifications, even if they are currently temporarily disabled.

Note that, in any case, the update notification is only sent if there is any pending notifications.


setAutoSelection

public void setAutoSelection(boolean enable)
Sets the autoselection mode

if autoSelection is true, if there is only one possible row to select on the table, it will be selected.


isAutoSelection

public boolean isAutoSelection()
Returns the autoselection mode

See Also:
setAutoSelection(boolean)