Group-wise filter rows in table [message #1782396] |
Thu, 22 February 2018 11:40  |
Eclipse User |
|
|
|
Hi,
I was wondering whether it is possible to build custom filters in order to filter rows in a table by criteria other than already given by the pre-defined ColumnUserFilterState implementations.
In my case, I would like to be ablet to filter rows only inside groups.
As an example consider a table containing a string column, a date column and possibly other columns.
Also consider the rows in the table being grouped by the entries in the string column. Now I want to group-wise filter rows by the most recent date in the corresponding group.
As far as I can see filtering works via ColumnUserFilterState which are added to the TableUserFilterManager. However, it seems that each existing implementation of ColumnUserFilterState has a pendant as JsonColumnUserFilter which leaves a trail into further Json related classes.
Is there an easy way out of this? If yes, what is the correct way to do this?
Best,
Leander
|
|
|
|
|
Re: Group-wise filter rows in table [message #1782926 is a reply to message #1782707] |
Mon, 05 March 2018 04:28  |
Eclipse User |
|
|
|
So I finally found a solution to my problem. As Claudio already said, the way to go is via implementing ITableRowFilter and adding it to the table in question.
Since grouping is essentially sorting plus an additional marker in the header cell this allows to filter rows inside groups.
In case somebody finds it useful, here is how I solved it:
public class FirstInSortOrderFilter implements ITableRowFilter {
List<ITableRow> m_acceptedRows;
public FirstInSortOrderFilter(IColumn<?> referenceColumn) {
int[] indices;
boolean isSortColumn;
ITable table;
if (referenceColumn != null) {
// check if column is selected for sorting
table = referenceColumn.getTable();
isSortColumn = table.getColumnSet().isSortColumn(referenceColumn);
m_acceptedRows = table.getRows();
if (isSortColumn && !referenceColumn.isEmpty() && table.isSortEnabled()) {
// only do something if there are duplicate values in the reference column
if (referenceColumn.containsDuplicateValues()) {
List<Object> values = new ArrayList<Object>(referenceColumn.getValues());
Set<Object> uniqueValues = new HashSet<Object>(values);
indices = new int[uniqueValues.size()];
int i = 0;
for (Object value : uniqueValues) {
indices[i] = Collections.indexOfSubList(values, Collections.singletonList(value));
i++;
}
m_acceptedRows = table.getRows(indices);
}
}
}
}
@Override
public boolean accept(ITableRow row) {
return m_acceptedRows.contains(row);
}
}
I'm open for optimisations and remarks :)
Best,
Leander
|
|
|
Powered by
FUDForum. Page generated in 0.27619 seconds