Skip to content

Commit b268531

Browse files
committed
Add support for nested problems display for hierarchical projects
Currently if one select in Project Explorer to display projects not only flat but hierarchical and choose the "Problems on selected Project" filtering (but other filters are affected as well) the following happens: - We have Project P with nested projects X, Y, Z - Y has a compile problem and X has warnings - Now P shows a red icon because it has problems of type error inherited - I select P but Problems View remains empty - One has to first expand P, then locate Y and select it - To see the warning I have to locate X and select it so there is an inconsistency (P shows problems icon but problems view is empty) and an inconvenience (I need to select individual childs to see all problems/warnings). This now enhances the ExtendedMarkersView by a method isProjectNestingActive (returns false by default) to allow view extensions to decide if they want to enable discovery of nested projects or not. The ProblemsView is further enhanced to detect the situation and returns true for this particular case.
1 parent 3ee82a4 commit b268531

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
import java.util.Collection;
2525
import java.util.HashSet;
2626
import java.util.Iterator;
27+
import java.util.LinkedHashSet;
2728
import java.util.List;
29+
import java.util.Set;
2830

2931
import org.eclipse.core.commands.operations.IUndoContext;
3032
import org.eclipse.core.resources.IFile;
3133
import org.eclipse.core.resources.IMarker;
34+
import org.eclipse.core.resources.IProject;
3235
import org.eclipse.core.resources.ResourcesPlugin;
3336
import org.eclipse.core.runtime.Adapters;
3437
import org.eclipse.core.runtime.Assert;
@@ -1642,16 +1645,35 @@ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
16421645
}
16431646
// try to adapt them in resources and add it to the
16441647
// selectedElements
1645-
List<Object> selectedElements = new ArrayList<>();
1648+
Set<Object> selectedElements = new LinkedHashSet<>();
16461649
for (Object object : objectsToAdapt) {
16471650
Object resElement = MarkerResourceUtil.adapt2ResourceElement(object);
16481651
if (resElement != null) {
16491652
selectedElements.add(resElement);
16501653
}
16511654
}
1655+
if (isProjectNestingActive(part)) {
1656+
List<IProject> selectedProjects = selectedElements.stream().filter(IProject.class::isInstance)
1657+
.map(IProject.class::cast).toList();
1658+
if (!selectedProjects.isEmpty()) {
1659+
selectedElements.addAll(MarkerResourceUtil.getNestedChildProjects(selectedProjects));
1660+
}
1661+
}
16521662
MarkerContentGenerator gen = view.getGenerator();
16531663
gen.updateSelectedResource(selectedElements.toArray(), part == null);
16541664
}
1665+
1666+
}
1667+
1668+
/**
1669+
* Check if project nesting is active for this marker view
1670+
*
1671+
* @param part the currently selected part
1672+
* @return <code>true</code> if nesting should be performed, <code>false</code>
1673+
* otherwise
1674+
*/
1675+
protected boolean isProjectNestingActive(IWorkbenchPart part) {
1676+
return false;
16551677
}
16561678

16571679
/**

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerResourceUtil.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.eclipse.core.runtime.Adapters;
3232
import org.eclipse.core.runtime.CoreException;
3333
import org.eclipse.core.runtime.IAdaptable;
34+
import org.eclipse.core.runtime.IPath;
3435
import org.eclipse.core.runtime.NullProgressMonitor;
3536
import org.eclipse.ui.internal.ide.Policy;
3637
import org.eclipse.ui.internal.util.Util;
@@ -286,6 +287,45 @@ static Collection<IProject> getProjectsAsCollection(Object[] elements) {
286287
return projects;
287288
}
288289

290+
/**
291+
* Returns all nested child projects of the given projects. A project is
292+
* considered a nested child if its location is a descendant of the parent
293+
* project's location. This supports the hierarchical project display feature.
294+
*
295+
* @param parentProjects
296+
* the projects to find nested children for
297+
* @return collection of all nested child projects (does not include the parent
298+
* projects themselves)
299+
*/
300+
static Collection<IProject> getNestedChildProjects(Collection<IProject> parentProjects) {
301+
if (parentProjects == null || parentProjects.isEmpty()) {
302+
return Set.of();
303+
}
304+
Set<IProject> nestedChildren = new HashSet<>();
305+
306+
for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
307+
if (!project.exists() || !project.isAccessible()) {
308+
continue;
309+
}
310+
IPath projectLocation = project.getLocation();
311+
if (projectLocation == null) {
312+
continue;
313+
}
314+
// Check if this project is nested under any of the parent projects
315+
for (IProject parentProject : parentProjects) {
316+
if (parentProject.equals(project)) {
317+
continue; // Skip the project itself
318+
}
319+
IPath parentLocation = parentProject.getLocation();
320+
if (parentLocation != null && parentLocation.isPrefixOf(projectLocation)) {
321+
nestedChildren.add(project);
322+
break;
323+
}
324+
}
325+
}
326+
return nestedChildren;
327+
}
328+
289329
/**
290330
* Add the resources in resourceMapping to the resourceCollection
291331
*/

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ProblemsView.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
import org.eclipse.core.resources.IMarker;
1818
import org.eclipse.core.runtime.Assert;
1919
import org.eclipse.swt.graphics.Image;
20+
import org.eclipse.ui.IWorkbenchPart;
2021
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
2122
import org.eclipse.ui.internal.WorkbenchPlugin;
2223
import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages;
24+
import org.eclipse.ui.navigator.CommonNavigator;
2325
import org.eclipse.ui.views.markers.MarkerSupportView;
2426
import org.eclipse.ui.views.markers.internal.MarkerMessages;
2527
import org.eclipse.ui.views.markers.internal.MarkerSupportRegistry;
@@ -64,4 +66,14 @@ protected String getDeleteOperationName(IMarker[] markers) {
6466
return markers.length == 1 ? MarkerMessages.deleteProblemMarker_operationName : MarkerMessages.deleteProblemMarkers_operationName;
6567
}
6668

69+
@Override
70+
protected boolean isProjectNestingActive(IWorkbenchPart part) {
71+
if (part instanceof CommonNavigator navigator) {
72+
return navigator.getNavigatorContentService().getActivationService().isNavigatorExtensionActive(
73+
"org.eclipse.ui.navigator.resources.nested.nestedProjectContentProvider"); //$NON-NLS-1$
74+
75+
}
76+
return false;
77+
}
78+
6779
}

0 commit comments

Comments
 (0)