Bug 123295

Summary: [Viewers] DeferredContentProvider should use a stable sort algorithm
Product: [Eclipse Project] Platform Reporter: Mario Winterer <mario.winterer>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P4 CC: bjorn.arnelid, loskutov
Version: 3.8.2Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 509006    

Description Mario Winterer CLA 2006-01-10 14:09:31 EST
At the moment, the DeferredContentProvider does not use a stable sort algorithm for sorting elements.
As an effect, each invocation of "DeferredContentProvider.setSortOrder(Comparator)" completely resorts the entire element list without preserving previous sort orders (for elements that are concerned to be equal according to the newly set sort order comparator).

So e.g. it is not possible to first sort a contact list by name and then sort it by zip code preserving the (previous) sort order for all contacts with equal zip codes.
Comment 1 Boris Bokowski CLA 2006-01-13 09:11:41 EST
Currently, we don't have the resources to address this. Patches (including JUnit test cases) would be welcome!
Comment 2 Boris Bokowski CLA 2009-11-26 09:53:25 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 3 Mario Winterer CLA 2017-09-03 06:16:05 EDT
Bug still exists in Eclipse Neon.3 (4.6.3).
Comment 4 Andrey Loskutov CLA 2017-09-03 09:26:57 EDT
(In reply to Mario Winterer from comment #3)
> Bug still exists in Eclipse Neon.3 (4.6.3).

And we still accept patches...
Comment 5 Björn Arnelid CLA 2017-12-14 09:52:56 EST
I started to look at this defect, but im not so sure this is something that should be implemented. 

Since the responsibility of sorting lies on the Comparator i think the reasonable  thing would be if the Comparator remembers previous sort orders instead of making the content provider care about sorting.

In java 8 you could use the thenCompare method to add previous Comparators.
Comment 6 Mario Winterer CLA 2017-12-14 12:23:14 EST
No, that's not true. Stability is usually a property of the sort algorithm itself and has nothing to do with the comparison operator. E.g. Merge Sort is stable, while Quick Sort isn't. The question is if equal elements might switch their (relative) positions during sorting or not.

I'm not sure if common partial sorting algorithms are usually stable or not. Possibly solving this issue might require a total new implementation of the sorting strategy.

By the way - this issue is so old, I don't really care any more.
Comment 7 Mario Winterer CLA 2017-12-14 12:30:55 EST
But there is a easy workaround for this issue:

We use a meta-comparator that delegates to a list of comparators for comparison. This list holds the current sort order comparator in its first place as well as all previously used comparators. Whenever a "current" comparator is set on the meta-comparator, it is inserted at the first position or, if already in the list, moved to the first position in the list.