Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.filter
Class PopupFilterHeaderModel

java.lang.Object
  extended by com.sciapp.filter.FilterHeaderModel
      extended by com.sciapp.filter.PopupFilterHeaderModel
All Implemented Interfaces:
FilterHeaderCallback, Serializable
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);

See Also:
Serialized Form

Field Summary
protected  String allString
          The string to display for the "ALL" option
protected  ArrowButton arrow
          Deprecated.  
protected  String BLANK_STRING
          a string for the 'blanks' filter selection
protected  JComboBox box
          The combo box whose popup menu is displayed.
protected  Cursor defaultHeaderCursor
          the header's default cursor
protected  FilterRenderer filterRenderer
          the filter renderer displaying the filterable header component
protected  boolean hidePopupOnSelection
          flag indicating whether the popup menu will be hidden after a filter value is selected
protected  String NON_BLANK_STRING
          a string for the 'non blanks' filter selection
 
Fields inherited from class com.sciapp.filter.FilterHeaderModel
ALL_VALUES_MODE, autoCreateAllFilters, columnShowing, defaultFiltersByColumnClass, filterHeader, filterMode, filterModel, ORDERED_MODE, PROGRESSIVE_MODE, removeOnInvisible, tableModel
 
Constructor Summary
PopupFilterHeaderModel()
          Constructs a PopupFilterHeaderModel.
 
Method Summary
 void attachToTable(JTable table, FilterListModel ftm)
          Installs this FilterHeaderModel instance to a table, by explicitly specifying the FilterListModel object that will process filter events.
protected  boolean checkForFilter(MouseEvent e)
          Deprecated.  
protected  FilterRenderer createDefaultFilterRenderer()
          Creates and returns the default filter renderer that will be used to display the filterable header component.
protected  void filterSelected(JList list, int c)
          Called as soon as the user has selected a value from the popup menu.
 String getALL_String()
          Returns the string used for the 'ALL' filter selection.
 ArrowButton getArrowButton()
          Deprecated.  
 String getBLANKS_String()
          Returns the string used for the 'BLANKS' filter selection.
protected  Collection getCollectionForClass(Class columnClass)
          Returns an empty collection that will be used to fill with available filter expression values.
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.
 Cursor getDefaultHeaderCursor()
          Retrieves the default header's cursor.
 FilterRenderer getFilterRenderer()
          Retrieves the filter renderer that will be used to display the filterable header component.
 boolean getHidePopupOnSelection()
          Determines whether the popup menu will be hidden after a selection is made.
 String getNON_BLANKS_String()
          Returns the string used for the 'NON BLANKS' filter selection.
 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.
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)
          Deprecated.  
 void removeFromTable()
          Removes this FilterHeaderModel instance from the table to which it was previously assigned.
 void removeRenderer(TableColumn column)
          Remove the renderer for aColumn.
 void setDefaultHeaderCursor(Cursor cursor)
          Assigns the default headers' cursor.
 void setFilterRenderer(FilterRenderer filterRenderer)
          Assigns the filter renderer that will be used to display the filterable header component.
 void setHidePopupOnSelection(boolean hidePopupOnSelection)
          Determines whether the popup menu will be hidden after a selection is made.
 void setRenderer(TableColumn column)
          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.
 boolean shouldProcessEvent(MouseEvent e)
          Determines whether the mouse event generated on the table's header should be propagated.
 void showPopup(Point p, int column, int width)
          Shows the filter popup for column at the specified location.
 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, createDefaultFilters, createTableHeader, filterIterator, getAutoCreateAllFilters, getColumnShowing, getDefaultFilter, getFilter, getFilterMode, getFilterModel, getFilterOrder, getFilterValue, getFilterValues, getFilterValues, getFilterValuesFromModel, getFilterValuesFromModel, getListValue, getRemoveOnInvisible, getTableFilter, getTableFilterForModel, getTableFilterForObject, getTableFilterForObjectToModel, getTableHeader, hasFilter, inferColumnClass, inferColumnClassModel, installFilter, installFilterToModel, installFilterToModel, installFilterToModel, loadFilterState, removeFilter, removeFilterFromColumn, removeFilterFromModel, removeFilterInColumns, saveFilterState, sendFilterEvent, setAutoCreateAllFilters, setColumnShowing, setDefaultFilter, setFilterMode, setFilterModel, setModel, setModel, setRemoveOnInvisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hidePopupOnSelection

protected boolean hidePopupOnSelection
flag indicating whether the popup menu will be hidden after a filter value is selected


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


allString

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


box

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


arrow

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

NOTE: this variable is now deprecated and will be removed in future versions It exists for backward compatibility.

See Also:
getArrowButton

defaultHeaderCursor

protected Cursor defaultHeaderCursor
the header's default cursor


filterRenderer

protected transient FilterRenderer filterRenderer
the filter renderer displaying the filterable header component

Constructor Detail

PopupFilterHeaderModel

public PopupFilterHeaderModel()
Constructs a PopupFilterHeaderModel.

Method Detail

attachToTable

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

Overrides:
attachToTable in class FilterHeaderModel
Parameters:
table - the table on which the FilterHeaderModel is installed.
ftm - the FilterListModel that will be used to process filter events on behalf of the table.

checkForFilter

protected boolean checkForFilter(MouseEvent e)
Deprecated. 

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.

NOTE: This method is now deprecated and will be removed in future versions.
This method has moved to DefaultFilterRenderer, which you can get by calling getFilterRenderer and casting appropriately.

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

createDefaultFilterRenderer

protected FilterRenderer createDefaultFilterRenderer()
Creates and returns the default filter renderer that will be used to display the filterable header component.

Returns:
the default filter renderer

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.

getALL_String

public String getALL_String()
Returns the string used for the 'ALL' filter selection.

Returns:
the 'ALL' string.

getArrowButton

public ArrowButton getArrowButton()
Deprecated. 

Returns the arrow button that is showing when a filter is installed on the column.

NOTE: This method is now deprecated and will be removed in future versions.
This method has moved to DefaultFilterRenderer, which you can get by calling getFilterRenderer and casting appropriately.

Returns:
the arrow button

getBLANKS_String

public String getBLANKS_String()
Returns the string used for the 'BLANKS' filter selection.

Returns:
the 'BLANKS' string.

getCollectionForClass

protected Collection getCollectionForClass(Class columnClass)
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:
columnClass - the class
Returns:
the collection

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 view index of 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.

getDefaultHeaderCursor

public Cursor getDefaultHeaderCursor()
Retrieves the default header's cursor.

Returns:
the default header's cursor

getFilterRenderer

public FilterRenderer getFilterRenderer()
Retrieves the filter renderer that will be used to display the filterable header component.

Returns:
filterRenderer the assigned filter renderer

getHidePopupOnSelection

public boolean getHidePopupOnSelection()
Determines whether the popup menu will be hidden after a selection is made. The default value is true.

Returns:
true if the popup menu is hidden after a selection, false otherwise

getNON_BLANKS_String

public String getNON_BLANKS_String()
Returns the string used for the 'NON BLANKS' filter selection.

Returns:
the 'NON BLANKS' string.

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.

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).

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

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 the filtered or unfiltered color, depending whether a filter expression is present on the column.

NOTE: This method is now deprecated and will be removed in future versions.
It does not nothing, and it is still there for backward compatibility.

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

public 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.

setDefaultHeaderCursor

public void setDefaultHeaderCursor(Cursor cursor)
Assigns the default headers' cursor.

Parameters:
cursor - the default header cursor to assign

setFilterRenderer

public void setFilterRenderer(FilterRenderer filterRenderer)
Assigns the filter renderer that will be used to display the filterable header component.

Parameters:
filterRenderer - the filter renderer to assign

setHidePopupOnSelection

public void setHidePopupOnSelection(boolean hidePopupOnSelection)
Determines whether the popup menu will be hidden after a selection is made. The default value is true.

Parameters:
hidePopupOnSelection - true if the popup menu is hidden after a selection, false otherwise

setRenderer

public 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.

setTableHeader

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

Overrides:
setTableHeader in class FilterHeaderModel
Parameters:
header - the new header 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.

showPopup

public void showPopup(Point p,
                      int column,
                      int width)
Shows the filter popup for column at the specified location.

Parameters:
p - the location at which the filter popup is shown
column - the column to show the filter for
width - the width of the filter popup

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

Copyright © 2005 Scientific Applications. All Rights Reserved.