Bug 223318 - [package explorer] Allow sorting in "Referenced libraries" node
Summary: [package explorer] Allow sorting in "Referenced libraries" node
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement with 21 votes (vote)
Target Milestone: 4.8 M6   Edit
Assignee: Karsten Thoms CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
: 213739 361236 396589 428767 440964 518531 531604 548563 551076 (view as bug list)
Depends on:
Blocks: 539048
  Show dependency tree
 
Reported: 2008-03-20 04:50 EDT by Thierry Monney CLA
Modified: 2019-09-15 07:15 EDT (History)
30 users (show)

See Also:


Attachments
JavaElementComparator with a "QuickFix" (11.80 KB, text/plain)
2008-04-10 16:17 EDT, Anthony Guselnikov CLA
no flags Details
Screenshot: Preference Page (361.75 KB, image/png)
2017-09-24 19:09 EDT, Karsten Thoms CLA
no flags Details
Screenshot: sorting enabled (466.73 KB, image/png)
2017-09-24 19:12 EDT, Karsten Thoms CLA
no flags Details
Screenshot (252.35 KB, image/png)
2018-03-02 16:10 EST, Karsten Thoms CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thierry Monney CLA 2008-03-20 04:50:55 EDT
Build ID: I20070625-1500

T entries in the Referenced libraries node in the package explorer are displayed in the order they are defined in the .classpath file. While this may be OK in some cases, I often have a hard time finding something in the lists of depencencies. It would be much easier to have them sorted alphabetically.
Comment 1 Anthony Guselnikov CLA 2008-04-10 16:17:13 EDT
Created attachment 95585 [details]
JavaElementComparator with a "QuickFix"

The sorting seems to be broken.

JavaElementComparator seems to not make no distinction for JarPackageFragmentRoot (which compromise Referenced Libraries), hence it handles them in the same way it handles other PackageFragmentRoot(s) which require different sorting algorithm. Attached is a "QuickFix" for compare method. Hopefully someone can implement a proper fix:

if(e1 instanceof JarPackageFragmentRoot && e2 instanceof JarPackageFragmentRoot){
                    return ((JarPackageFragmentRoot)e1).getElementName().compareTo( ((JarPackageFragmentRoot)e2).getElementName());
                }
Comment 2 Martin Aeschlimann CLA 2008-04-11 05:32:06 EDT
We need to add this as an option (for example in the view menu). There are users that want to see the classpath order, we can't break them.
Comment 3 Thierry Monney CLA 2008-04-11 15:25:14 EDT
Of course making it configurable would be even better! As soon as I can find a free time slot (those are definitely too rare...) I will try to come with a patch.
Comment 4 Dani Megert CLA 2008-08-14 05:32:40 EDT
*** Bug 213739 has been marked as a duplicate of this bug. ***
Comment 5 Dani Megert CLA 2011-10-18 11:13:04 EDT
*** Bug 361236 has been marked as a duplicate of this bug. ***
Comment 6 Steve Cohen CLA 2011-12-01 15:05:58 EST
This is necessary in the following situation.  Let's say you are using Maven and m2e and have included your server runtime as a "Provided Dependency".   this creates a Maven Dependencies pseudo-folder in Eclipse.  Oftentimes you may wish to look inside one of these jars.  Perhaps to look at some xml configuration file that is stored there as part of the runtime, or perhaps to take avantage of Maven's handy source code retrieval features.

But this happy scenario is less happy when you have to scan through three or four pages of unsorted jar files just to find the one you want.
Comment 7 Igor Fedorenko CLA 2012-12-14 07:29:06 EST
*** Bug 396589 has been marked as a duplicate of this bug. ***
Comment 8 deleted-account deleted-account CLA 2013-08-31 14:30:40 EDT
For the time being, the "dependency hierarchy" tab of the POM editor (of m2e) allows sorting alphabetically.
Comment 9 Igor Fedorenko CLA 2014-02-21 11:24:53 EST
*** Bug 428767 has been marked as a duplicate of this bug. ***
Comment 10 Igor Fedorenko CLA 2014-08-01 06:48:20 EDT
*** Bug 440964 has been marked as a duplicate of this bug. ***
Comment 11 Angus Mezick CLA 2015-06-30 16:18:46 EDT
Any chance of this being fixed.  It is one of the biggest reasons I avoid fulling integrating with Maven.  The library list is completely useless to a human.
Comment 12 Jens Meiss CLA 2016-09-26 07:39:02 EDT
c'mon guys is nobody out there who can fix this? i can't be that much work that nobody in more than 8 years couldn't fix it
Comment 13 Dmitry Katsubo CLA 2016-11-11 05:07:08 EST
Making dependency list sorted is very reasonable, at least much better than leaving it unsorted. Waiting for this improvement for years...
Comment 14 Dani Megert CLA 2017-06-21 05:19:28 EDT
*** Bug 518531 has been marked as a duplicate of this bug. ***
Comment 15 Karsten Thoms CLA 2017-09-24 19:09:09 EDT
Created attachment 270333 [details]
Screenshot: Preference Page

New Gerrit change created: https://git.eclipse.org/r/105666

This will add a preference to the "Java / Appearance" page which toggles the behavior.
Comment 16 Karsten Thoms CLA 2017-09-24 19:12:21 EDT
Created attachment 270334 [details]
Screenshot: sorting enabled

This screenshot shows the effect after enabling the option. The effect becomes already visible when pressing "Apply" on the preference page.
Comment 17 Noopur Gupta CLA 2018-01-09 07:44:06 EST
Thanks for the patch, Karsten. Please find below the review comments:

- The patch sorts the roots also which should not be done as it mixes up the library roots and source folder roots after sorting. Only the entries within the library roots should be sorted.

- The preference should specify the places where it is applicable if it is not reflected everywhere in the UI (e.g. it isn't reflected in the Java Build Path dialog > Libraries tab). In that case, the preference option should be "Sort library entries &alphabetically in Package Explorer".

- Found one issue: If we open the Project Explorer view when the preference is enabled, the entries in Project Explorer are also sorted. But changing the preference when the Project Explorer view is already open doesn't reflect anything in Project Explorer. Please check this inconsistency for Project Explorer and other such locations where this comparator will be used. The preference should be named accordingly.

- Update the Javadoc of JavaElementComparator.

- Update the F1 help documentation with the new preference option describing where it is applicable and what is actually sorted or not sorted.
Comment 18 Karsten Thoms CLA 2018-01-09 08:35:07 EST
Thanks for the detailed review. I'll try to address your findings when having some time.
Comment 19 Fred Bricon CLA 2018-02-23 08:49:37 EST
*** Bug 531604 has been marked as a duplicate of this bug. ***
Comment 20 Karsten Thoms CLA 2018-02-26 04:19:38 EST
> - Found one issue: If we open the Project Explorer view when the preference
> is enabled, the entries in Project Explorer are also sorted. But changing
> the preference when the Project Explorer view is already open doesn't
> reflect anything in Project Explorer. Please check this inconsistency for
> Project Explorer and other such locations where this comparator will be
> used. The preference should be named accordingly.

Had a look at this one and did not find a solution. The problem is that the sorting is done here by JavaElementSorter, and it is not aware of preference changes. While we could add itself as a listener, it could not remove itself again. This again could be worked around by an executable extension factory, making this heavier. Even worse, after a change the common navigator tree would have to refresh, and the JavaElementSorter has no access to the tree.

Therefore I tend to restrict this feature to the Package Explorer for now. If someone has an idea how to extend this to a commonSorter of the navigator, please leave a note here.
Comment 21 Sarika Sinha CLA 2018-02-27 06:27:59 EST
Does this involve any API change ?
Noopur is on vacation and can look at it in M7.
Comment 22 Karsten Thoms CLA 2018-02-27 06:37:18 EST
I have just pushed my current state. In that version it involves a new constructor for JavaElementComparator.

Could you please give me a hint where the sources for F1 help docs are? I assume it has to be added for the Appearance page, but where do I find the docs?

The other issues should not be addressed.
Comment 23 Sarika Sinha CLA 2018-02-27 06:43:11 EST
F1 docs are in the repo  eclipse.platform.common

/org.eclipse.jdt.doc.isv
/org.eclipse.jdt.doc.user
Comment 24 Eclipse Genie CLA 2018-02-28 04:47:26 EST
New Gerrit change created: https://git.eclipse.org/r/118333
Comment 26 Sarika Sinha CLA 2018-03-02 08:24:49 EST
Please add N&N entry.
Comment 27 Karsten Thoms CLA 2018-03-02 08:25:47 EST
Thanks a lot! Will provide an entry.
Comment 28 Eclipse Genie CLA 2018-03-02 08:38:41 EST
New Gerrit change created: https://git.eclipse.org/r/118526
Comment 29 Karsten Thoms CLA 2018-03-02 08:38:59 EST
I just tried this and found that the functionality did not work when working sets are top-level. I just submitted a patch for that.
Comment 30 Sarika Sinha CLA 2018-03-02 08:45:30 EST
(In reply to Karsten Thoms from comment #29)
> I just tried this and found that the functionality did not work when working
> sets are top-level. I just submitted a patch for that.

What do you mean by Working sets are top-level? Steps or screenshot will help to understand.
Comment 31 Karsten Thoms CLA 2018-03-02 16:10:50 EST
Created attachment 272982 [details]
Screenshot

The WorkingSetAwareJavaElementSorter is used when the Package Explorer is configured to show Working Sets as root elememts from the view menu.
Comment 33 Eclipse Genie CLA 2018-03-05 04:11:38 EST
New Gerrit change created: https://git.eclipse.org/r/118644
Comment 35 Sarika Sinha CLA 2018-03-05 04:46:48 EST
Thanks Karsten!!
Comment 36 Karsten Thoms CLA 2018-03-05 04:51:06 EST
Thanks for your review!
Comment 37 Sarika Sinha CLA 2018-03-05 22:02:21 EST
We need an entry in N&N for this item.
Comment 39 Karsten Thoms CLA 2018-03-06 03:45:28 EST
There was already one prepared: https://git.eclipse.org/r/#/c/118644/
Merged that now.
Comment 40 Sarika Sinha CLA 2018-03-06 06:27:27 EST
(In reply to Karsten Thoms from comment #39)
> There was already one prepared: https://git.eclipse.org/r/#/c/118644/
> Merged that now.

N&N should mention that default is off.
Comment 41 Eclipse Genie CLA 2018-03-06 07:56:45 EST
New Gerrit change created: https://git.eclipse.org/r/118784
Comment 43 Karsten Thoms CLA 2018-03-06 08:52:40 EST
Updated N&N
Comment 44 Stephan Herrmann CLA 2018-03-06 11:52:57 EST
Thanks Karsten, this has been long awaited :)

Regarding N&N entry: apparently you didn't see the part of the instructions that links to the XHTML validation service - I removed a spurious <p> to make the document well-formed again ... (part of http://git.eclipse.org/c/www.eclipse.org/eclipse/news.git/commit/?id=798aa3c1974a1e177b3fc5048808abd7f485628a ).
Comment 45 Fred Bricon CLA 2018-04-11 09:33:20 EDT
Any reason why this feature is limited to the package explorer? I personally use the Project explorer intensively and I think the setting should also apply there too (maybe other places?)
Comment 46 Karsten Thoms CLA 2018-04-11 10:27:43 EDT
Yes, there were technical limitations. I think I have commented on this in the change.
Comment 47 Stephan Herrmann CLA 2019-06-24 13:34:36 EDT
*** Bug 548563 has been marked as a duplicate of this bug. ***
Comment 48 Stephan Herrmann CLA 2019-09-15 07:15:41 EDT
*** Bug 551076 has been marked as a duplicate of this bug. ***