Search in sources :

Example 1 with LineElement

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;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) LineElement(org.eclipse.search.internal.ui.text.LineElement) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) IWorkingSet(org.eclipse.ui.IWorkingSet)

Aggregations

ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 LineElement (org.eclipse.search.internal.ui.text.LineElement)1 IWorkingSet (org.eclipse.ui.IWorkingSet)1