com.sciapp.filter
Class PopupFilterHeaderModel

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

public class PopupFilterHeaderModel
extends FilterHeaderModel

PopupFilterHeaderModel uses an arrow button in order to provide real-time row filtering. The arrow appears on the right of the column's normal header and, once pressed, a popup is shown that contains available filter expression values regarding the column.

PopupFilterHeaderModel is easily installed on a JTable:

PopupFilterHeaderModel popup = new PopupFilterHeaderModel();

popup.attachToTable(table);

NOTE: If your table is an AdvancedJTable (or TreeTable), you need to add the following line:

popup.setTableHeader((FilterTableHeader) table.getTableHeader());

,so that the table will take into account the presence of the last column (see getShowDummyColumn).


Field Summary
protected  String allString
          The string to display for the "ALL" option
protected  ArrowButton arrow
          The button that is showing on the header.
protected  String BLANK_STRING
          a string for the 'blanks' filter selection
protected  JComboBox box
          The combo box whose popup menu is displayed.
protected  String NON_BLANK_STRING
          a string for the 'non blanks' filter selection
protected  PopupRenderer renderer
          The renderer of the popup menu.
 
Fields inherited from class com.sciapp.filter.FilterHeaderModel
ALL_VALUES_MODE, autoCreateAllFilters, columnShowing, defaultFiltersByColumnClass, filterHeader, filterMode, filterModel, ORDERED_MODE, PROGRESSIVE_MODE, tableModel
 
Constructor Summary
PopupFilterHeaderModel()
          Constructs a PopupFilterHeaderModel.
 
Method Summary
protected  boolean checkForFilter(MouseEvent e)
          Determines if the user clicked on any of the arrow buttons on the table's header.
protected  void filterSelected(JList list, int c)
          Called as soon as the user has selected a value from the popup menu.
 ArrowButton getArrowButton()
          Returns the arrow button that is showing when a filter is installed on the column.
protected  Collection getCollectionForColumn(int c)
          Returns an empty collection that will be used to fill with available filter expression values.
 JComboBox getComboBox()
          Returns the combo box whose popup menu is displayed when the arrow button is pressed.
 void installFilter(TableFilter tableFilter, Object listValue, Object filterValue, int c)
          Assigns a new table filter to the column c.
protected  void populatePopup(int c)
          Populates the popup menu with values that will be used as filter expressions.
protected  void popupWillShow(int c)
          This method is called just before the popup is shown on screen.
protected  void preparePopup(int c)
          Makes final preparations before the popup is shown on screen.
protected  void prepareRenderer(int c)
          This method is called just before the renderer paints the column at c for columns that have a filter installed.
 void removeFromTable()
          Removes this FilterHeaderModel instance from the table to which it was previously assigned.
protected  void removeRenderer(TableColumn column)
          Remove the renderer for aColumn.
protected  void setRenderer(TableColumn column)
          Assigns a renderer for aColumn.
 boolean shouldProcessEvent(MouseEvent e)
          Determines whether the mouse event generated on the table's header should be propagated.
 void updateUI()
          Calls to this method should update all components that are used to display the filter on the header.
 
Methods inherited from class com.sciapp.filter.FilterHeaderModel
addFilterInColumn, addFilterInColumns, attachToTable, attachToTable, createDefaultFilters, createTableHeader, getAutoCreateAllFilters, getColumnShowing, getDefaultFilter, getFilter, getFilterMode, getFilterOrder, getFilterValue, getFilterValues, getFilterValues, getListValue, getTableFilter, getTableFilterForObject, getTableHeader, hasFilter, inferColumnClass, installFilter, installFilter, removeFilter, removeFilterFromColumn, removeFilterInColumns, sendFilterEvent, setAutoCreateAllFilters, setColumnShowing, setDefaultFilter, setFilterMode, setModel, setModel, setTableHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLANK_STRING

protected String BLANK_STRING
a string for the 'blanks' filter selection


NON_BLANK_STRING

protected String NON_BLANK_STRING
a string for the 'non blanks' filter selection


box

protected JComboBox box
The combo box whose popup menu is displayed.


arrow

protected ArrowButton arrow
The button that is showing on the header.


renderer

protected PopupRenderer renderer
The renderer of the popup menu.


allString

protected String allString
The string to display for the "ALL" option

Constructor Detail

PopupFilterHeaderModel

public PopupFilterHeaderModel()
Constructs a PopupFilterHeaderModel.

Method Detail

checkForFilter

protected boolean checkForFilter(MouseEvent e)
Determines if the user clicked on any of the arrow buttons on the table's header. If so, a popup menu containing available filter expression values is displayed for the column pressed.

Parameters:
e - the mouse event generated on the table's header.
Returns:
true if the arrow button was pressed.

filterSelected

protected void filterSelected(JList list,
                              int c)
Called as soon as the user has selected a value from the popup menu. The list can be inquired in order to get the selected value.

e.g. Object selectedValue = list.getSelectedValue();

Parameters:
list - the list of the popup menu.

getArrowButton

public ArrowButton getArrowButton()
Returns the arrow button that is showing when a filter is installed on the column.

Returns:
the arrow button.

getCollectionForColumn

protected Collection getCollectionForColumn(int c)
Returns an empty collection that will be used to fill with available filter expression values. The collection is a TreeSet, which will not allow duplicate values. A TreeSet assumes that the objects added implement the Comparable interface. Therefore, for objects that do not implement that interface, a comparator is used that compares the string value of the objects via the toString() method.

Parameters:
c - the column
Returns:
the collection

getComboBox

public JComboBox getComboBox()
Returns the combo box whose popup menu is displayed when the arrow button is pressed.

Returns:
the combo box.

installFilter

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

Overrides:
installFilter in class FilterHeaderModel
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.

populatePopup

protected void populatePopup(int c)
Populates the popup menu with values that will be used as filter expressions. The values are retrieved by calling getCollectionForColumn(c).

Parameters:
c - the column that contains the values.

popupWillShow

protected void popupWillShow(int c)
This method is called just before the popup is shown on screen. PreparePopup is called in order to make some final preparations on the combobox and it's popup before displaying, such as adding extra items to the popup. Then, the popup is populated with the values that are going to be available, by calling populatePopup.

The location and size of the popup can be specified at this point. For example:

Rectangle rec = filterHeader.getHeaderRect(c);

Point p = new Point(rec.x-50, rec.y + filterHeader.getHeight());

box.setLocation(p);

box.setSize(rec.width+50, 0);

Parameters:
c - the column for which a popup filter will be displayed.

preparePopup

protected void preparePopup(int c)
Makes final preparations before the popup is shown on screen. This implementation will add an "ALL" filter option to the popup at the top for all columns, and a "Blanks" and "Non Blanks" for String column classes.

Parameters:
c - the column for which the popup filter will be displayed.

prepareRenderer

protected void prepareRenderer(int c)
This method is called just before the renderer paints the column at c for columns that have a filter installed. This implementation pushes the arrow button down and paints it with a blue color if a filter expression is present on the column.

Parameters:
c - the column the renderer is painting.

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.

Overrides:
removeFromTable in class FilterHeaderModel

removeRenderer

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

Specified by:
removeRenderer in class FilterHeaderModel
Parameters:
column - the column which renderer we want to remove.

setRenderer

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

Specified by:
setRenderer in class FilterHeaderModel
Parameters:
column - the column to which a renderer we want to assign.

shouldProcessEvent

public boolean shouldProcessEvent(MouseEvent e)
Determines whether the mouse event generated on the table's header should be propagated.

Parameters:
e - the mouse event.
Returns:
true if the event is to be processed, false otherwise.

updateUI

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

Specified by:
updateUI in class FilterHeaderModel