use of org.eclipse.search.internal.ui.text.LineElement in project eclipse.platform.text by eclipse.
the class ScopePart method selectedResourcesFromContainer.
public static List<IResource> selectedResourcesFromContainer(ISearchPageContainer container) {
if (container == null)
return Collections.emptyList();
ISelection selection = container.getSelection();
List<IResource> resources = new ArrayList<>();
if (!(selection instanceof IStructuredSelection) || selection.isEmpty()) {
if (container.getActiveEditorInput() != null) {
resources.add(container.getActiveEditorInput().getAdapter(IFile.class));
}
return resources;
}
Iterator<?> iter = ((IStructuredSelection) selection).iterator();
while (iter.hasNext()) {
Object curr = iter.next();
if (curr instanceof IWorkingSet) {
IWorkingSet workingSet = (IWorkingSet) curr;
if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) {
continue;
}
IAdaptable[] elements = workingSet.getElements();
for (IAdaptable element : elements) {
IResource resource = element.getAdapter(IResource.class);
if (resource != null && resource.isAccessible()) {
resources.add(resource);
}
}
} else if (curr instanceof LineElement) {
IResource resource = ((LineElement) curr).getParent();
if (resource != null && resource.isAccessible())
resources.add(resource);
} else if (curr instanceof IAdaptable) {
IResource resource = ((IAdaptable) curr).getAdapter(IResource.class);
if (resource != null && resource.isAccessible()) {
resources.add(resource);
}
}
}
return resources;
}
Aggregations