*/
public IStructuredSelection findExternalFileSelection(File f) {
if (this.commonViewer == null) {
return null;
}
CommonViewer commonViewer = this.commonViewer.get();
if (commonViewer == null) {
return null;
}
ISelection treeSelection = commonViewer.getSelection();
Set<IInterpreterInfo> infosSearched = new HashSet<IInterpreterInfo>();
IContentProvider contentProvider = commonViewer.getContentProvider();
ITreeContentProvider treeContentProvider;
if (contentProvider instanceof ITreeContentProvider) {
treeContentProvider = (ITreeContentProvider) contentProvider;
} else {
Log.log("On tryToRevealExternalFile, the common viewer content provider is not an ITreeContentProvider. Found: "
+ contentProvider);
return null;
}
//Step 1: look into a selection
if (treeSelection instanceof IStructuredSelection && !treeSelection.isEmpty()) {
IStructuredSelection structuredSelection = (IStructuredSelection) treeSelection;
Iterator it = structuredSelection.iterator();
while (it.hasNext()) {
Object next = it.next();
IStructuredSelection sel = findExternalFileSelectionGivenTreeSelection(f, commonViewer,
treeContentProvider, infosSearched, next);
if (sel != null && !sel.isEmpty()) {
return sel;
}
}
}
//Step 2: look into what's expanded in the package explorer
Object[] expandedElements = commonViewer.getVisibleExpandedElements();
for (Object expandedElement : expandedElements) {
IStructuredSelection sel = findExternalFileSelectionGivenTreeSelection(f, commonViewer,
treeContentProvider, infosSearched, expandedElement);
if (sel != null && !sel.isEmpty()) {
return sel;
}
}
//Step 3: look into existing editors
Set<IFile> openFiles = PyAction.getOpenFiles();
for (IFile iFile : openFiles) {
IStructuredSelection sel = findExternalFileSelectionGivenTreeSelection(f, commonViewer,
treeContentProvider, infosSearched, iFile);
if (sel != null && !sel.isEmpty()) {
return sel;
}
}
//Step 4: look into what's available in the package explorer
Object input = commonViewer.getInput();
for (Object child : treeContentProvider.getChildren(input)) {
IStructuredSelection sel = findExternalFileSelectionGivenTreeSelection(f, commonViewer,
treeContentProvider, infosSearched, child);
if (sel != null && !sel.isEmpty()) {
return sel;