Copyright © 2011 Citra Technologies. All Rights Reserved.

com.citra.filter
Class PopupFilterHeaderModel

java.lang.Object
  extended by com.citra.filter.FilterHeaderModel
      extended by com.citra.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  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  boolean multipleSelection
          a variable that determines whether the popup filter will allow the selection of multiple filter values
protected  Map multipleSelectionMap
          a map of columns's indices in the table's model against boolean variables that determine whether the popup filter will allow the selection of multiple filter values for a specific column
protected  String NON_BLANK_STRING
          a string for the 'non blanks' filter selection
 
Fields inherited from class com.citra.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  FilterRenderer createDefaultFilterRenderer()
          Creates and returns the default filter renderer that will be used to display the filterable header component.
protected  TableCellRendererWrapper createFilterWrapper()
          Creates and returns the renderer wrapper that will be installed on the header.
 String getALL_String()
          Returns the string used for the 'ALL' filter selection.
 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.
 boolean getMultipleSelection()
          Determines whether the popup filter allows the selection of multiple filter values.
 boolean getMultipleSelection(int modelIndex)
          Determines whether the popup filter allows the selection of multiple filter values for a specific column.
 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.
 void removeFromTable()
          Removes this FilterHeaderModel instance from the table to which it was previously assigned.
 void removeRenderer(TableColumn column)
          Remove the renderer for aColumn.
protected  boolean retrieveMultipleSelection(int modelIndex)
          This method is called just before showing the popup filter, in order to determine whether the popup will allow the selection of multiple filter values for a specific column.
 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 setMultipleSelection(boolean multipleSelection)
          Determines whether the popup filter allows the selection of multiple filter values.
 void setMultipleSelection(int modelIndex, boolean multipleSelection)
          Determines whether the popup filter allows the selection of multiple filter values for a specific column.
 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.citra.filter.FilterHeaderModel
addFilterInColumn, addFilterInColumns, attachToTable, convertFilterState, convertFilterState, createDefaultFilters, createTableHeader, filterIterator, getAutoCreateAllFilters, getColumnShowing, getDefaultFilter, getFilter, getFilterMode, getFilterModel, getFilterOrder, getFilterValue, getFilterValues, getFilterValues, getFilterValuesFromModel, getFilterValuesFromModel, getListValue, getRemoveOnInvisible, getTableFilter, getTableFilterForModel, getTableFilterForObject, getTableFilterForObjectToModel, getTableFilters, getTableHeader, hasFilter, inferColumnClass, inferColumnClassModel, installFilter, installFilterToModel, installFilterToModel, installFilterToModel, loadFilterState, removeFilter, removeFilterFromColumn, removeFilterFromModel, removeFilterInColumns, saveFilterState, sendFilterEvent, setAutoCreateAllFilters, setColumnShowing, setDefaultFilter, setFilterMode, setFilterModel, setModel, setModel, setRemoveOnInvisible, setTableFilters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

multipleSelection

protected boolean multipleSelection
a variable that determines whether the popup filter will allow the selection of multiple filter values


multipleSelectionMap

protected Map multipleSelectionMap
a map of columns's indices in the table's model against boolean variables that determine whether the popup filter will allow the selection of multiple filter values for a specific column


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.


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.

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

createFilterWrapper

protected TableCellRendererWrapper createFilterWrapper()
Creates and returns the renderer wrapper that will be installed on the header.

Specified by:
createFilterWrapper in class FilterHeaderModel
Returns:
a new instance of a cell renderer wrapper

getALL_String

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

Returns:
the 'ALL' string.

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

getMultipleSelection

public boolean getMultipleSelection()
Determines whether the popup filter allows the selection of multiple filter values.

Returns:
true if multiple filter values are allowed, false otherwise

getMultipleSelection

public boolean getMultipleSelection(int modelIndex)
Determines whether the popup filter allows the selection of multiple filter values for a specific column. This is stored in a map, which is empty by default. If a column is not found in the map, this method returns false.

Parameters:
modelIndex - the column's index in the table's model
Returns:
true if multiple filter values are allowed, 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 and Date column classes.

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

removeFromTable

public void removeFromTable()
Removes this FilterHeaderModel instance from the table to which it was previously assigned. This method should be called for Java versions prior to 1.4, so that the FilterHeaderModel can 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

retrieveMultipleSelection

protected boolean retrieveMultipleSelection(int modelIndex)
This method is called just before showing the popup filter, in order to determine whether the popup will allow the selection of multiple filter values for a specific column. It takes into account the values assigned with the setMultipleSelection methods. Developers can override it, so that to provide a custom behaviour.

Parameters:
modelIndex - the column's index in the table's model
Returns:
true if multiple filter values are allowed, false otherwise

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

setMultipleSelection

public void setMultipleSelection(int modelIndex,
                                 boolean multipleSelection)
Determines whether the popup filter allows the selection of multiple filter values for a specific column. This is stored in a map, which is empty by default.

Parameters:
modelIndex - the column's index in the table's model
multipleSelection - true, if multiple filter values are allowed, false otherwise

setMultipleSelection

public void setMultipleSelection(boolean multipleSelection)
Determines whether the popup filter allows the selection of multiple filter values.

Parameters:
multipleSelection - true, if multiple filter values are allowed, 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 © 2011 Citra Technologies. All Rights Reserved.