Mylyn Notifications: Sort newest first in popup notification [message #1726175] |
Thu, 10 March 2016 10:31 |
Andreas Sewe Messages: 111 Registered: June 2013 |
Senior Member |
|
|
Hi,
I am currently writing a plugin that wants to display notifications. As such, reusing Mylyn Notifications is quietly appealing. So far, most of it works great.
Alas, there's one issue: If there are multiple notifications, they should be displayed "newest first" in the popup window. But as far as I can see AbstractNotification.compareTo fixes the sort order to "oldest first". And using a different implementation of compareTo in a subclass won't work IMHO, even though ServiceMessage does does just that:
public int compareTo(ServiceMessage o) {
return -getId().compareTo(o.getId());
}
But AFAICT a sink may display notification's of different AbstractNotification subclasses at the same time. At least, PopupNotificationSink's currentlyNotifying list seems to alow this, which IMHO is buggy, as Collections.sort will potentially see AbstractNotifications with inconsistent notions of what compareTo means: ServiceMessage.compareTo(AbstractNofication) is not the inverse of AbstractNofication.compareTo(ServiceMessage).
Is this a bug? If so, how to work around it (ideally without implementing my own sink & popup)?
Best wishes,
Andreas
|
|
|
|
Re: Mylyn Notifications: Sort newest first in popup notification [message #1726302 is a reply to message #1726256] |
Fri, 11 March 2016 08:32 |
Andreas Sewe Messages: 111 Registered: June 2013 |
Senior Member |
|
|
Quote:It looks like a bug that ServiceMessage.compareTo does not override the method in the super class, because the type of the paramter is ServiceMessage instead of AbstractNotification. As long as you correctly override that method in your subclass I don't see why it wouldn't work.
Good catch, ServiceMessage.compareTo doesn't even override AbstractNotification.compareTo. But [i]BuildsServiceNotification.compareTo[i] does...
Quote:
I think that you are right that if you have different types of notifications with different implementations of compareTo in the same sink, you will get inconsistent behaviour.
...so I think that this might become an problem in practice, as I have seen Collections.sort throw an IllegalArgumentException when the compareTo contract is violated (see ComparableTimSort's implementation).
I think there's two way's around this:
- Require that all notifications are sorted by date, earliest first (effectively making AbstractNotification final.
- Mandate that notifications from multiple NotificationSinkEvents are not
"blended together" by a NotificationSink.
To me, option 1 is clearly undesirable, as sorting is highly notification-specific. On the other hand, option 2 may even positively affect the UX, as a popup displaying both build results and new issues together might be confusing.
Anyway, should I move this conversation over to Bugzilla?
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04086 seconds