Skip to content

Consistently sort projects by path - #9629

Open
jtulach wants to merge 1 commit into
apache:masterfrom
jtulach:jtulach/ConsistentlySortByPath
Open

jtulach wants to merge 1 commit into
apache:masterfrom
jtulach:jtulach/ConsistentlySortByPath

Conversation

@jtulach

@jtulach jtulach commented Sep 21, 2026

Copy link
Copy Markdown
Contributor
  • Michael suggested "adding sorting options is definitely a good thing" in Show nested projects co-located and indented #9602 review comment
  • it may be, but we shall ask: Who's the user of such a sorting option? I can imagine few categories:
    • basic NetBeans IDE users
    • advanced NetBeans IDE users
    • NetBeans Platform users
  • depending on the answer we can design the right way to flip the sorting switch
  • for the beginning (as PR needs some code changes) I am offering simple b1f3e7d
    • e.g. consistently using sorting by projects path
  • let the discussion start...

@jtulach jtulach self-assigned this Sep 21, 2026
@jtulach

jtulach commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Sorting by Display Name was a UI Bug

First and foremost let me state that the sorting by display name never really worked at scale. It might have worked for few opened projects at the beginning. While user sees them all (at least in collapsed state) then the ordering doesn't really matter.

However sorting projects of bigger sizes like Glassfish, Helidon or Maven always felt random to me. This randomness was even multiplied by the fact that display name was used for sorting, not a real folder name on disk. As such the order of projects in ls or in OS file explorer was different than the order in the IDE.

Sorting by display name might have worked well for demos in 2004 when two or three independent Ant projects were open, but it never helped anyone working on large, nested project structures of real Maven or Gradle projects that have become standard later. With such amount of projects the sorting felt like chaos.

Haven't you felt the same when using the NetBeans IDE with such large projects?

@jtulach

jtulach commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Sorting by Display Name as an API

Is the change of the sorting order of Project instances (in the Projects and Files views) an API change? If we accept that API is everything someone else code can depend on (e.g. the definition I like the most), then the answer is: Yes, it is an API change.

There might be someone building an application on top of NetBeans Platform using the ide cluster extensions. Such a developer might give the projects alphabetically sorted project names and yes, then the carefully crafted project order would have changed after #9602

I don't think such a scenario is likely, but if we wanted to support the old sorting in NetBeans Platform based applications, then a "branding API" (e.g. a key in Bundle.properties) would be an appropriate API, I guess.

@jtulach

jtulach commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Sorting by Name for Advanced Users

Just like in the "Sorting by Display Name as an API" case, it is possible that some of advanced NetBeans IDE users, might structure their projects and give them alphabetically sorted display names. Something like P1: Xyz, P2: Uvq, P3: Abc. That would sort by P1, P2, P3 prefixes consistently.

I find such scenario unlikely (I would never rename a project to sort well in my IDE myself), but if it was to be supported and there should be a way to turn such a display name sorting order on again, then these users would probably be fine with a -Dproperty to opt-out of the more reasonable projects by paths sorting order.

"LBL_NoneMainProject_Name=&None"
})
private void createSubMenu(Project[] projects) {
Arrays.sort(projects, OpenProjectList.projectByDisplayName());

@jtulach jtulach Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • while implementing b1f3e7d
  • I realized there are three places when ordering of projects is used
  • my expectation is: at all places the sorting order should be the same
  • e.g. whatever configuration option is offered, applies to all those places at once

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, let me show an annecdoctical evidence of the randomness of the sorting by display name. Sometimes I am mixing projects from multiple repositories. Today I had projects from NetBeans own code base, as well as projects from GraalVM repository open. This is how it looks like in NetBeans 31:

Randomness in old NetBeans

It is easy to recognize what projects are coming from which repository as they have different icons. But the order! Because the projects are sorted by display name, those two independent sets of projects are intermixed with each other. The ordering is random, basically.

Today I decided to switch to the latest development version and voilá:

ordering by path

The ordering by path makes sense! First of all there is a group of projects from the GraalVM repository, then there is the group of projects from the NetBeans repository. There is no nesting in the hierarchy of those groups (that'd be subject of #9624 for example), but even the grouping by path is a tremendous step forward.

PS: I've been so shocked realizing how better the ordering is! I've just had to install the (already deleted) old NetBeans again to take the picture. As it speaks for thousand of words.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, let me show an annecdoctical evidence of the randomness of the sorting by display name

I believe seeing somewhere lazy/non-blocking init mechanisms where display names were used only when available. If its there it is used, if not it falls back to something else. I an imagine - if used for sorting - it can be placed at the wrong spot initially - until the full list is refreshed.

the group-by-project dropdown of the file list behaves similarly. If it can't list all projects fast enough it will display a simple list on very first open. Once the cached, it will properly group. NB has a lot of caching behind the scenes.

image

The ordering by path makes sense!

yes I agree. I thought about this and tested that already back when I looked at #9602 (comment)

Since it sorts by String path, it should produce pretty good results. (Path.compareTo() would have been slightly more dangerous - I remember the showstopper #6361 which was hard to debug since the cause was completely removed from the symptom (that one was about weird File instances - Path may be backed by different file systems))

@Chris2011

Copy link
Copy Markdown
Contributor

My 2 cents: somtimes I like to sort by project type so that I can see if I have a lot of open projects, what is PHP, Java, HTML etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants