Bug 484248 - [Common Navigator] CommonSorterDescriptor doesn't support ViewerComparator
Summary: [Common Navigator] CommonSorterDescriptor doesn't support ViewerComparator
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.7 M7   Edit
Assignee: Andrey Loskutov CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 482137
  Show dependency tree
 
Reported: 2015-12-11 13:47 EST by Patrick Tasse CLA
Modified: 2017-03-28 10:39 EDT (History)
5 users (show)

See Also:
akurtakov: pmc_approved+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Tasse CLA 2015-12-11 13:47:37 EST
ViewerSorter was deprecated in Bug 402464.

In our project we replaced all use of ViewerSorter with ViewerComparator.

But we have one class which is now an instance of ViewerComparator that is used in the org.eclipse.ui.navigator.navigatorContent extension point in the navigatorContent/commonSorter element.

That class is instantiated by the platform and it triggers a ClassCastException:

java.lang.ClassCastException: org.eclipse.myproject.ui.MyViewerComparator cannot be cast to org.eclipse.jface.viewers.ViewerSorter
	at org.eclipse.ui.internal.navigator.sorters.CommonSorterDescriptor$1.run(CommonSorterDescriptor.java:97)

Should that extension point be deprecated? Or should it accept both ViewerComparator and ViewerSorter? Can it be fixed in both Neon and Mars.2?
Comment 1 Daniel Wille CLA 2017-02-03 13:33:09 EST
I just got bit by this. I saw that ViewerSorter had been deprecated, and I took the time to go find all my instances of it and change them to ViewerComparators. Then I got hit with the ClassCastException mentioned by Patrick.

I looked into what's required to implement a fix for this, but it doesn't look pretty. The extension point could be altered to accept ViewerComparator since it's a parent class, but then you run into the fact that the navigator API uses ViewerSorter all over the place:

* CommonSorterDescriptor.createSorter() --> ViewerSorter
* INavigatorSorterService.findSorterForParent(Object) --> ViewerSorter
* INavigatorSorterService.findSorter(INavigatorContentDescriptor, Object, Object, Object) --> ViewerSorter
* INavigatorSorterService.findAvailableSorters(INavigatorContentDescriptor) --> Map<String, ViewerSorter>

So new API would need to be added, and the old API would have to wrap ViewerComparator's so they could be returned as ViewerSorter's by the deprecated API.

Has anyone else had thoughts about how the work for this ticket might be implemented?
Comment 2 Andrey Loskutov CLA 2017-03-21 08:49:45 EDT
I'm putting 4.8 on this, this is really ugly issue, EGit also was hit by it (see bug 513876). We should check what can we do to fix this in 4.8 time frame.
Comment 3 Andrey Loskutov CLA 2017-03-21 12:14:12 EDT
(In reply to Daniel Wille from comment #1)
> I just got bit by this. I saw that ViewerSorter had been deprecated, and I
> took the time to go find all my instances of it and change them to
> ViewerComparators. Then I got hit with the ClassCastException mentioned by
> Patrick.
> 
> I looked into what's required to implement a fix for this, but it doesn't
> look pretty. 

Yep.

> The extension point could be altered to accept ViewerComparator
> since it's a parent class, but then you run into the fact that the navigator
> API uses ViewerSorter all over the place:
> 
> * CommonSorterDescriptor.createSorter() --> ViewerSorter
> * INavigatorSorterService.findSorterForParent(Object) --> ViewerSorter
> * INavigatorSorterService.findSorter(INavigatorContentDescriptor, Object,
> Object, Object) --> ViewerSorter
> * INavigatorSorterService.findAvailableSorters(INavigatorContentDescriptor)
> --> Map<String, ViewerSorter>
> 
> So new API would need to be added, and the old API would have to wrap
> ViewerComparator's so they could be returned as ViewerSorter's by the
> deprecated API.

Yep.

> Has anyone else had thoughts about how the work for this ticket might be
> implemented?

I agree with your conclusions above and I also don't think we can remove the ViewerSorter from common navigator framework yet, because this would be a breaking change.

So we can mark all the methods as deprecated in 4.8, at same time provide the new API and in two years from that release we could try to perform a major (breaking) version change. See https://wiki.eclipse.org/Eclipse/API_Central/Deprecation_Policy for details.

@Daniel: if you would do the major work, I would offer the review :-).
Comment 4 Thomas Wolf CLA 2017-03-22 05:42:53 EDT
As a stop-gap measure, couldn't one accept a ViewerComparator in CommonSorterDescriptor.createSorter() and wrap it always? (Unless the created object already _is_ a ViewerSorter, of course.)
Comment 5 Eclipse Genie CLA 2017-03-22 09:20:45 EDT
New Gerrit change created: https://git.eclipse.org/r/93613
Comment 6 Andrey Loskutov CLA 2017-03-22 09:24:11 EDT
(In reply to Thomas Wolf from comment #4)
> As a stop-gap measure, couldn't one accept a ViewerComparator in
> CommonSorterDescriptor.createSorter() and wrap it always? (Unless the
> created object already _is_ a ViewerSorter, of course.)

Good idea. This way clients using only declarative contributions to navigator can move to the new API.

(In reply to Eclipse Genie from comment #5)
> New Gerrit change created: https://git.eclipse.org/r/93613

I think this can be accepted for M7, but I have to ask for approval because the behavior of the extension point changes (relaxes the type bound for the navigatorContent/commonSorter extension).
Comment 7 Andrey Loskutov CLA 2017-03-22 09:36:13 EDT
I think we can split this bug into two: one for CommonSorterDescriptor (which can be changed in 4.7 once (and if) we get PMC approval) and another one for the rest of the API. I will file another one soon.
Comment 9 Andrey Loskutov CLA 2017-03-23 03:55:01 EDT
The follow up bug on the required API changes is bug 514063.
Comment 10 Thomas Wolf CLA 2017-03-23 04:06:00 EDT
(In reply to Andrey Loskutov from comment #9)
> The follow up bug on the required API changes is bug 514063.

Cool. Thanks, Andrey! (And thanks Alexander for the quick approval.)
Comment 11 Eclipse Genie CLA 2017-03-28 07:20:06 EDT
New Gerrit change created: https://git.eclipse.org/r/93969