Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.Assert;
Expand Down Expand Up @@ -1642,16 +1645,35 @@ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
}
// try to adapt them in resources and add it to the
// selectedElements
List<Object> selectedElements = new ArrayList<>();
Set<Object> selectedElements = new LinkedHashSet<>();
for (Object object : objectsToAdapt) {
Object resElement = MarkerResourceUtil.adapt2ResourceElement(object);
if (resElement != null) {
selectedElements.add(resElement);
}
}
if (isProjectNestingActive(part)) {
List<IProject> selectedProjects = selectedElements.stream().filter(IProject.class::isInstance)
.map(IProject.class::cast).toList();
if (!selectedProjects.isEmpty()) {
selectedElements.addAll(MarkerResourceUtil.getNestedChildProjects(selectedProjects));
}
}
MarkerContentGenerator gen = view.getGenerator();
gen.updateSelectedResource(selectedElements.toArray(), part == null);
}

}

/**
* Check if project nesting is active for this marker view
*
* @param part the currently selected part
* @return <code>true</code> if nesting should be performed, <code>false</code>
* otherwise
*/
protected boolean isProjectNestingActive(IWorkbenchPart part) {
return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.ui.internal.ide.Policy;
import org.eclipse.ui.internal.util.Util;
Expand Down Expand Up @@ -286,6 +287,45 @@ static Collection<IProject> getProjectsAsCollection(Object[] elements) {
return projects;
}

/**
* Returns all nested child projects of the given projects. A project is
* considered a nested child if its location is a descendant of the parent
* project's location. This supports the hierarchical project display feature.
*
* @param parentProjects
* the projects to find nested children for
* @return collection of all nested child projects (does not include the parent
* projects themselves)
*/
static Collection<IProject> getNestedChildProjects(Collection<IProject> parentProjects) {
if (parentProjects == null || parentProjects.isEmpty()) {
return Set.of();
}
Set<IProject> nestedChildren = new HashSet<>();

for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
if (!project.exists() || !project.isAccessible()) {
continue;
}
IPath projectLocation = project.getLocation();
if (projectLocation == null) {
continue;
}
// Check if this project is nested under any of the parent projects
for (IProject parentProject : parentProjects) {
if (parentProject.equals(project)) {
continue; // Skip the project itself
}
IPath parentLocation = parentProject.getLocation();
if (parentLocation != null && parentLocation.isPrefixOf(projectLocation)) {
nestedChildren.add(project);
break;
}
}
}
return nestedChildren;
}

/**
* Add the resources in resourceMapping to the resourceCollection
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.Assert;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages;
import org.eclipse.ui.navigator.CommonNavigator;
import org.eclipse.ui.views.markers.MarkerSupportView;
import org.eclipse.ui.views.markers.internal.MarkerMessages;
import org.eclipse.ui.views.markers.internal.MarkerSupportRegistry;
Expand Down Expand Up @@ -64,4 +66,14 @@ protected String getDeleteOperationName(IMarker[] markers) {
return markers.length == 1 ? MarkerMessages.deleteProblemMarker_operationName : MarkerMessages.deleteProblemMarkers_operationName;
}

@Override
protected boolean isProjectNestingActive(IWorkbenchPart part) {
if (part instanceof CommonNavigator navigator) {
return navigator.getNavigatorContentService().getActivationService().isNavigatorExtensionActive(
"org.eclipse.ui.navigator.resources.nested.nestedProjectContentProvider"); //$NON-NLS-1$

}
return false;
}

}
Loading