Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Group-wise filter rows in table
Group-wise filter rows in table [message #1782396] Thu, 22 February 2018 16:40 Go to next message
Leander Fiedler is currently offline Leander FiedlerFriend
Messages: 3
Registered: February 2018
Junior Member
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 #1782403 is a reply to message #1782396] Thu, 22 February 2018 17:29 Go to previous messageGo to next message
Claudio Guglielmo is currently offline Claudio GuglielmoFriend
Messages: 170
Registered: March 2010
Senior Member
Hi Leander

You can add custom filters by implementing ITableRowFilter and adding it using table.addRowFilter().

You probably don't have to deal with ColumnUserFilterState, see also this answer: https://www.eclipse.org/forums/index.php?t=msg&th=1086176&goto=1763693&#msg_1763693

Best regards
Claudio
Re: Group-wise filter rows in table [message #1782707 is a reply to message #1782403] Wed, 28 February 2018 07:48 Go to previous messageGo to next message
Leander Fiedler is currently offline Leander FiedlerFriend
Messages: 3
Registered: February 2018
Junior Member
Hi Claudio,

Thank you for your quick reply and sorry for the late one from my side.
I already found the post you linked to in a previous search but was not sure, whether it can be used in the scenario I have here. I will have another look and try a few things out :)

Best,
Leander
Re: Group-wise filter rows in table [message #1782926 is a reply to message #1782707] Mon, 05 March 2018 09:28 Go to previous message
Leander Fiedler is currently offline Leander FiedlerFriend
Messages: 3
Registered: February 2018
Junior Member
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
Previous Topic:Guide line to migrate from Kepler to Oxygen
Next Topic:After deploying - where to put the database?
Goto Forum:
  


Current Time: Thu Nov 15 11:03:55 GMT 2018

Powered by FUDForum. Page generated in 0.02221 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top