com.sciapp.filter
Class FilterHeaderModel

java.lang.Object
  extended by com.sciapp.filter.FilterHeaderModel
All Implemented Interfaces:
FilterHeaderCallback
Direct Known Subclasses:
PopupFilterHeaderModel

public abstract class FilterHeaderModel
extends Object
implements FilterHeaderCallback

FilterHeaderModel is used to provide real-time row filtering via a component that is installed on the table header.

The methods that need to be implemented deal with the component that is added on each filtering column.


Field Summary
static int ALL_VALUES_MODE
          Defines the filter mode for showing all objects under a certain column
protected  boolean autoCreateAllFilters
          A flag that if true will automatically install a filter for each column added to the table.
protected  int columnShowing
          the column of the header that is currently showing available filter expressions.
protected  HashMap defaultFiltersByColumnClass
          A table that contains filters indexed by class.
protected  FilterTableHeader filterHeader
          The header that is installed on the table.
protected  int filterMode
          The mode that is being employed to populate the available filter expressions.
protected  FilterModel filterModel
          The filtermodel that will be used to propagate the filter events.
static int ORDERED_MODE
          Defines the filter mode for showing objects depending on the order the filters were installed.
static int PROGRESSIVE_MODE
          Defines the filter mode for showing objects depending on all the filters currently installed.
protected  FilterTableModel tableModel
          The filtertablemodel that will be used to process the filter events.
 
Constructor Summary
FilterHeaderModel()
          Constructs a FilterHeaderModel.
 
Method Summary
 void addFilterInColumn(TableColumn aColumn)
          Installs a filter on the supplied column.
 void addFilterInColumns()
          Installs filters on all columns.
 void attachToTable(JTable table)
          Installs this FilterHeaderModel instance to a table.
 void attachToTable(JTable table, FilterTableModel ftm)
          Installs this FilterHeaderModel instance to a table, by explicitly specifying the FilterTableModel object that will process filter events.
protected  void createDefaultFilters()
          Creates default filters for objects, strings, numbers and boolean values.
protected  FilterTableHeader createTableHeader()
          Returns a new instance of the header that will be installed on the table.
 boolean getAutoCreateAllFilters()
          Returns the autoCreateAllFilters property value.
 int getColumnShowing()
          Returns the column that is currently showing available filter expressions.
 Filter getDefaultFilter(Class columnClass)
          Returns the filter to use for the class defined by columnClass.
protected  Filter getFilter(int index)
          Returns a filter object for the column with model index index.
 int getFilterMode()
          Returns the mode that is being employed to populate the available filter expressions.
 int getFilterOrder(int c)
          Returns the order in which the filter expression was selected.
 Object getFilterValue(int c)
          Returns the object that is used as the filter expression for the column at c.
 Collection getFilterValues(int c, Collection list)
          Returns a collection filled with the objects that will be available to be selected as filter expressions for the specified column and the current filter mode.
 Collection getFilterValues(int c, Collection list, int mode)
          Returns a collection filled with the objects that will be available to be selected as filter expressions for the specified column and mode.
 Object getListValue(int c)
          Returns the object that is used as a label to identify the filter that is installed on the column at c.
 TableFilter getTableFilter(int c)
          Returns the TableFilter object that is installed on the column at c and that is responsible for filtering that column.
 TableFilter getTableFilterForObject(Object o, int c)
          Returns an appropriate table filter object for the supplied object and column index.
 FilterTableHeader getTableHeader()
          Returns the header that will be used for displaying a visual representation of a filter on columns.
 boolean hasFilter(int c)
          Determines whether a column has a filter installed.
 Class inferColumnClass(int c)
          A utility method to retrieve the class for the objects under the column at c In most cases, this is similar to calling getColumnClass on the table.
 void installFilter(Object listValue, int c)
          Assigns a new table filter to the column c.
 void installFilter(Object listValue, Object filterValue, int c)
          Assigns a new table filter to the column c.
 void installFilter(TableFilter tableFilter, Object listValue, Object filterValue, int c)
          Assigns a new table filter to the column c.
 void removeFilter(int c)
          Removes the filter value from the supplied column.
 void removeFilterFromColumn(TableColumn aColumn)
          Removes a filter previously installed on a column.
 void removeFilterInColumns()
          Removes the filters from all the columns.
 void removeFromTable()
          Removes this FilterHeaderModel instance from the table to which it was previously assigned.
protected abstract  void removeRenderer(TableColumn aColumn)
          Remove the renderer for aColumn.
 void sendFilterEvent()
          Sends a filter event to the associated FilterTableModel.
 void setAutoCreateAllFilters(boolean newAutoCreateAllFilters)
          Assigns a new value for the autoCreateAllFilters property.
 void setColumnShowing(int c)
          Sets the column for which the user requested a filter to appear.
 void setDefaultFilter(Class columnClass, Filter filter)
          Sets the default filter for columnClass.
 void setFilterMode(int mode)
          Assigns a mode that is being employed to populate the available filter expressions.
 void setModel(FilterTableModel ftm)
          Assigns the filtertable model that will be used to process the filter events.
 void setModel(TableModel tm)
          Assigns the filtertable model that will be used to process the filter events.
protected abstract  void setRenderer(TableColumn aColumn)
          Assigns a renderer for aColumn.
 void setTableHeader(FilterTableHeader header)
          Associates a header that will be used for displaying a visual representation of a filter on columns.
abstract  void updateUI()
          Calls to this method should update all components that are used to display the filter on the header.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sciapp.filter.FilterHeaderCallback
shouldProcessEvent
 

Field Detail

tableModel

protected FilterTableModel tableModel
The filtertablemodel that will be used to process the filter events.


filterModel

protected FilterModel filterModel
The filtermodel that will be used to propagate the filter events.


filterHeader

protected FilterTableHeader filterHeader
The header that is installed on the table.


autoCreateAllFilters

protected boolean autoCreateAllFilters
A flag that if true will automatically install a filter for each column added to the table.


defaultFiltersByColumnClass

protected HashMap defaultFiltersByColumnClass
A table that contains filters indexed by class.


columnShowing

protected int columnShowing
the column of the header that is currently showing available filter expressions.


ALL_VALUES_MODE

public static final int ALL_VALUES_MODE
Defines the filter mode for showing all objects under a certain column

See Also:
Constant Field Values

PROGRESSIVE_MODE

public static final int PROGRESSIVE_MODE
Defines the filter mode for showing objects depending on all the filters currently installed.

See Also:
Constant Field Values

ORDERED_MODE

public static final int ORDERED_MODE
Defines the filter mode for showing objects depending on the order the filters were installed.

See Also:
Constant Field Values

filterMode

protected int filterMode
The mode that is being employed to populate the available filter expressions.

Constructor Detail

FilterHeaderModel

public FilterHeaderModel()
Constructs a FilterHeaderModel.

Method Detail

addFilterInColumn

public void addFilterInColumn(TableColumn aColumn)
Installs a filter on the supplied column.

Parameters:
aColumn - the column for which a filter we want to add.

addFilterInColumns

public void addFilterInColumns()
Installs filters on all columns.


attachToTable

public void attachToTable(JTable table)
Installs this FilterHeaderModel instance to a table. The supplied table must have a FilterTableModel as its dataModel, or, if the dataModel is a ListTableMap, contain one in the chain of ListTableMaps. This FilterTableModel will be used to process filter events.

Parameters:
table - the table on which the FilterHeaderModel is installed.

attachToTable

public void attachToTable(JTable table,
                          FilterTableModel ftm)
Installs this FilterHeaderModel instance to a table, by explicitly specifying the FilterTableModel object that will process filter events.

Parameters:
table - the table on which the FilterHeaderModel is installed.
ftm - the FilterTableModel that will be used to process filter events on behalf of the table.

createDefaultFilters

protected void createDefaultFilters()
Creates default filters for objects, strings, numbers and boolean values. The default filter for strings and objects is the same.


createTableHeader

protected FilterTableHeader createTableHeader()
Returns a new instance of the header that will be installed on the table.

Returns:
a new instance of the filter header.

getAutoCreateAllFilters

public boolean getAutoCreateAllFilters()
Returns the autoCreateAllFilters property value.

Returns:
a flag that if true, filters will be automatically installed for each column added to the table.

getColumnShowing

public int getColumnShowing()
Returns the column that is currently showing available filter expressions. If no filter is showing, -1 is returned.

Returns:
the column showing filter expressions.

getDefaultFilter

public Filter getDefaultFilter(Class columnClass)
Returns the filter to use for the class defined by columnClass.

Parameters:
columnClass - the class to which a filter is associated.
Returns:
the filter that corresponds to columnClass.

getFilter

protected Filter getFilter(int index)
Returns a filter object for the column with model index index. This method returns null by default.

Parameters:
index - the model index of the column
Returns:
a filter

getFilterMode

public int getFilterMode()
Returns the mode that is being employed to populate the available filter expressions.

Returns:
the current filter mode.

getFilterOrder

public int getFilterOrder(int c)
Returns the order in which the filter expression was selected. A value of -1 returned implies the column is not filtered.

Parameters:
c - the view index of the column.
Returns:
the order the column was filtered.

getFilterValue

public Object getFilterValue(int c)
Returns the object that is used as the filter expression for the column at c.

Parameters:
c - the view index of the column.
Returns:
an object used as the filter expression.

getFilterValues

public Collection getFilterValues(int c,
                                  Collection list)
Returns a collection filled with the objects that will be available to be selected as filter expressions for the specified column and the current filter mode.

Parameters:
c - the view index of the column
list - the collection to be populated with values
Returns:
a collection of objects.

getFilterValues

public Collection getFilterValues(int c,
                                  Collection list,
                                  int mode)
Returns a collection filled with the objects that will be available to be selected as filter expressions for the specified column and mode.

Parameters:
c - the view index of the column
list - the collection to be populated with values
mode - the mode to be used when populating the list
Returns:
a collection of objects.

getListValue

public Object getListValue(int c)
Returns the object that is used as a label to identify the filter that is installed on the column at c.

Parameters:
c - the view index of the column.
Returns:
the label object - usually an object inside a JList

getTableFilter

public TableFilter getTableFilter(int c)
Returns the TableFilter object that is installed on the column at c and that is responsible for filtering that column.

Parameters:
c - the view index of the column.
Returns:
the table filter object associated with that column.

getTableFilterForObject

public TableFilter getTableFilterForObject(Object o,
                                           int c)
Returns an appropriate table filter object for the supplied object and column index. This method will use the filter value returned by calling getFilter or getDefaultFilter(o.getClass()), should the former return a null value.

Parameters:
c - the view index of the column.
Returns:
an appropriate table filter that will preferrable be installed on the table's header.

getTableHeader

public FilterTableHeader getTableHeader()
Returns the header that will be used for displaying a visual representation of a filter on columns.

Returns:
the filter header that is assigned.

hasFilter

public boolean hasFilter(int c)
Determines whether a column has a filter installed.

Parameters:
c - the view index of the column.
Returns:
true if the column at c has a filter installed, false otherwise.

inferColumnClass

public Class inferColumnClass(int c)
A utility method to retrieve the class for the objects under the column at c In most cases, this is similar to calling getColumnClass on the table.

Parameters:
c - the view index of the column.
Returns:
the class of the objects under the supplied column.

installFilter

public void installFilter(TableFilter tableFilter,
                          Object listValue,
                          Object filterValue,
                          int c)
Assigns a new table filter to the column c.

Parameters:
tableFilter - the new table filter to assign.
listValue - the label of the filter.
filterValue - the value of the filter.
c - the view index of the column.

installFilter

public void installFilter(Object listValue,
                          int c)
Assigns a new table filter to the column c. The table filter will be retrieved by calling getTableFilterForObject(filterValue, c), whereas the filter value will be the same as the supplied list value.

Parameters:
listValue - the label of the filter.
c - the view index of the column.

installFilter

public void installFilter(Object listValue,
                          Object filterValue,
                          int c)
Assigns a new table filter to the column c. The table filter will be retrieved by calling getTableFilterForObject(filterValue, c).

Parameters:
listValue - the label of the filter.
filterValue - the value of the filter.
c - the view index of the column.

removeFilter

public void removeFilter(int c)
Removes the filter value from the supplied column.

Parameters:
c - the view index of the column

removeFilterFromColumn

public void removeFilterFromColumn(TableColumn aColumn)
Removes a filter previously installed on a column. If the column did not have a filter, this method will do nothing.

Parameters:
aColumn - the column from which a filter we want to remove.

removeFilterInColumns

public void removeFilterInColumns()
Removes the filters from all the columns.


removeFromTable

public void removeFromTable()
Removes this FilterHeaderModel instance from the table to which it was previously assigned. The FilterHeaderModel can then become free for garbage collection.


removeRenderer

protected abstract void removeRenderer(TableColumn aColumn)
Remove the renderer for aColumn.

Parameters:
aColumn - the column which renderer we want to remove.

sendFilterEvent

public void sendFilterEvent()
Sends a filter event to the associated FilterTableModel. The event sent depends upon the filter expressions currently selected.


setAutoCreateAllFilters

public void setAutoCreateAllFilters(boolean newAutoCreateAllFilters)
Assigns a new value for the autoCreateAllFilters property.

Parameters:
newAutoCreateAllFilters - boolean the new value to assign

setColumnShowing

public void setColumnShowing(int c)
Sets the column for which the user requested a filter to appear.

Parameters:
c - the view index of the column

setDefaultFilter

public void setDefaultFilter(Class columnClass,
                             Filter filter)
Sets the default filter for columnClass.

Parameters:
columnClass - the Class with which a filter we want to associate
filter - the filter to set

setFilterMode

public void setFilterMode(int mode)
Assigns a mode that is being employed to populate the available filter expressions.

Parameters:
mode - the new current filter mode to assign.

setModel

public void setModel(FilterTableModel ftm)
Assigns the filtertable model that will be used to process the filter events.

Parameters:
ftm - the new filtertable model to assign.

setModel

public void setModel(TableModel tm)
Assigns the filtertable model that will be used to process the filter events. tm must be an instance of FilterTableModel, or, if it is a ListTableMap, it should contain one FilterTableModel in its chain of ListTableMaps. The first FilterTableModel found will be used to process filter events.

Parameters:
tm - the new filtertable model to assign.

setRenderer

protected abstract void setRenderer(TableColumn aColumn)
Assigns a renderer for aColumn.

Parameters:
aColumn - the column to which a renderer we want to assign.

setTableHeader

public void setTableHeader(FilterTableHeader header)
Associates a header that will be used for displaying a visual representation of a filter on columns.

Parameters:
header - the new header to assign

updateUI

public abstract void updateUI()
Calls to this method should update all components that are used to display the filter on the header.