|
Usage |
Top Previous Next |
TreeFilterHeaderModel bears some similarities to FilterHeaderModel. In order to install it to a TreeTable, you should call:
public void attachToTable(TreeTable treetable) OR
public void attachToTable(TreeTable treetable, FilterTreeTableModel ftm);
You can add and remove 'filterable' columns respectively with:
public void setFilterControlInColumn(TableColumn aColumn);
public void removeFilterControlFromColumn(TableColumn aColumn);
By default, all columns are 'filterable'. This can be controlled with:
public void setAutoCreateAllFilters(boolean newAutoCreateAllFilters);
public boolean getAutoCreateAllFilters();
The Filter that will be used to filter the values of a column is retrieved with the method:
public Filter getFilter(int viewIndex);
The method above will call:
public Filter getDefaultFilter(Class columnClass);
You can set the default filters for a Class with:
public void setDefaultFilter(Class columnClass, Filter filter);
By default, Filters for all the common objects (Strings, Dates, Booleans etc) are installed at construction time with:
protected void createDefaultFilters();
The default implementation, PopupTreeFilterHeaderModel, creates a DefaultColumnFilterMapper that allows each column to be associated to either a LevelFilterMapper or a NodeFilterMapper. Therefore, you can have some columns in which the filtered node children are specifically identified and others, which filter tree nodes based on their tree level.
Example: Use a PopupTreeFilterHeaderModel to filter the values of a TreeTableModel. All columns should show every node in the data model, except for the first column.
//create a (unfiltered) treetablemodel:
DefaultMutableTreeTableModel dataModel = new DefaultMutableTreeTableModel();
...fill dataModel with some values and columns
//create the FilterTreeTableModel and the tree-table
DefaultFilterTreeTableModel ftm = new DefaultFilterTreeTableModel(dataModel);
TreeTable treeTable = new TreeTable(ftm);
//create the PopupTreeFilterHeaderModel and install it to the tree-table
PopupTreeFilterHeaderModel popup = new PopupTreeFilterHeaderModel();
popup.setTableHeader((FilterTableHeader) treeTable.getTableHeader());
popup.attachToTable(treeTable);
//get the DefaultColumnFilterMapper instance
DefaultColumnFilterMapper mapper = (DefaultColumnFilterMapper) popup.getFilterMapper();
//change the default mapping mode to NODE
mapper.setDefaultMode(DefaultColumnFilterMapper.NODE_MODE);
//make the first column show filter expressions per level
mapper.setLevel(0);