eppleton commented on code in PR #9821:
URL: https://github.com/apache/netbeans/pull/9821#discussion_r4657621539


##########
ide/projectui/src/org/netbeans/modules/project/ui/groups/DirectoryGroup.java:
##########
@@ -112,34 +114,44 @@ public GroupEditPanel createPropertiesPanel() {
     }
 
     private void processFolderChildren(FileObject fo, Set<Project> projects, 
ProgressHandle h, Counter counter, boolean checkShare) throws 
IllegalArgumentException {
-        Enumeration<? extends FileObject> e = fo.getFolders(false);
-        while (e.hasMoreElements()) {
-            try {
-                FileObject em = e.nextElement();
-                SharabilityQuery.Sharability share = 
SharabilityQuery.Sharability.UNKNOWN;
-                if (checkShare) {
-                    share = SharabilityQuery.getSharability(fo);
+        Enumeration<? extends Project> rootProjects = 
Enumerations.queue(Enumerations.array(fo.getChildren()), (dir, toAdd) -> {
+            if (!dir.isFolder()) {
+                return null;
+            }
+            if (checkShare) {

Review Comment:
   `findProject` is now inside the `if (checkShare)` block, so with `checkShare 
== false` no project would ever be found. The only caller passes `true`, so it 
works today, but it looks unintended. Also, the old code skipped further 
sharability queries below a folder that was SHARABLE; that optimization is 
gone. On the plus side, the new code queries `dir`, while the old one queried 
the parent `fo` by mistake.



##########
ide/projectui/src/org/netbeans/modules/project/ui/groups/SubprojectsGroup.java:
##########
@@ -80,33 +77,7 @@ protected String getNameOrNull() {
     protected void findProjects(Set<Project> projects, ProgressHandle h, int 
start, int end) {
         assert !SwingUtilities.isEventDispatchThread();
         Project p = projectForPath(prefs().get(KEY_PATH, null));
-        if (p != null) {
-            visitSubprojects(p, projects, true, h, new int[] {start, end});
-        }
-    }
-
-    private static void visitSubprojects(Project p, Set<Project> projects, 
boolean main, ProgressHandle h, int[] startEnd) {
-        if ((main || !ProjectConvertors.isConvertorProject(p)) && 
projects.add(p)) {
-            if (h != null) {
-                h.progress(progressMessage(p), Math.min(++startEnd[0], 
startEnd[1]));
-            }
-            ProjectContainerProvider pcp = 
p.getLookup().lookup(ProjectContainerProvider.class);
-            if (pcp != null) {
-                ProjectContainerProvider.Result res = 
pcp.getContainedProjects();
-                projects.addAll(res.getProjects());
-                if (!res.isRecursive()) {
-                    visitSubprojects(p, projects, false, h, startEnd);
-                }
-            } else {
-                //fallback to semi-deprecated subprojectprovider
-                SubprojectProvider spp = 
p.getLookup().lookup(SubprojectProvider.class);
-                if (spp != null) {
-                    for (Project p2 : spp.getSubprojects()) {
-                        visitSubprojects(p2, projects, false, h, startEnd);
-                    }
-                }
-            }
-        }
+        projects.add(p);

Review Comment:
   The old code had `if (p != null)` here. `projectForPath` returns `null` when 
the master project folder was deleted or moved, so `null` now ends up in the 
set. With assertions enabled that trips `assert !projects.contains(null)` in 
`Group.getProjects`; without them, the `null` is passed on to `opl.open`.



##########
ide/projectui/src/org/netbeans/modules/project/ui/groups/Group.java:
##########
@@ -591,12 +594,14 @@ static void open(final Group g, String oldGroupName, 
boolean isNewGroup, Prefere
             IndexingBridge.Lock lock = 
IndexingBridge.getDefault().protectedMode();
             try {
                 h.progress(Group_progress_closing(toClose.size()), 110);
+                Project[] arrClose = toClose.toArray(new Project[0]);
                 //close and remember the last opened files in the old group
-                opl.close(toClose.toArray(new Project[0]), false, 
oldGroupName);
+                opl.close(arrClose, false, oldGroupName);
                 h.switchToIndeterminate();
                 h.progress(Group_progress_opening(toOpen.size()));
                 //open the projects with current group
-                opl.open(toOpen.toArray(new Project[0]), false, false, h, 
null);
+                Project[] arrOpen = toOpen.toArray(new Project[0]);
+                opl.open(arrOpen, false, g != null && g.isSubprojects(), h, 
null);

Review Comment:
   Since `newOpen` now contains only the root projects, subprojects can get 
closed without being reopened. Example: group A is a `SubprojectsGroup` of X, 
so X and its subprojects are open. Switching to group B, a `DirectoryGroup` 
that also contains X, gives `toClose = oldOpen - newOpen` = the subprojects of 
X. X itself stays open, so it is not in `toOpen`, and `openSubprojects` never 
runs for it, so the subprojects stay closed. For the same reason the 
subprojects drop out of `stayOpened`, so their open documents are no longer 
persisted or restored per group.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to