use of org.python.pydev.navigator.InterpreterInfoTreeNodeRoot in project Pydev by fabioz.
the class PythonLinkHelper method findExternalFileSelectionGivenTreeSelection.
private IStructuredSelection findExternalFileSelectionGivenTreeSelection(File f, CommonViewer commonViewer, ITreeContentProvider treeContentProvider, Set<IInterpreterInfo> infosSearched, final Object next) {
if (next instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) next;
IResource resource = (IResource) adaptable.getAdapter(IResource.class);
if (resource != null) {
IProject project = resource.getProject();
if (project != null) {
Object[] children = treeContentProvider.getChildren(project);
for (Object object : children) {
if (object instanceof InterpreterInfoTreeNodeRoot) {
IStructuredSelection sel = findMatchInTreeNodeRoot(f, commonViewer, (InterpreterInfoTreeNodeRoot) object, infosSearched);
if (sel != null) {
return sel;
}
}
}
return null;
}
}
// Keep on going to try to find a parent that'll adapt to IResource...
}
if (next instanceof TreeNode) {
TreeNode treeNode = (TreeNode) next;
while (true) {
if (treeNode instanceof InterpreterInfoTreeNodeRoot) {
IStructuredSelection sel = findMatchInTreeNodeRoot(f, commonViewer, (InterpreterInfoTreeNodeRoot) treeNode, infosSearched);
if (sel != null) {
return sel;
}
return null;
}
if (treeNode instanceof PythonpathTreeNode) {
PythonpathTreeNode pythonpathTreeNode = (PythonpathTreeNode) treeNode;
if (f.equals(pythonpathTreeNode.file)) {
return new StructuredSelection(treeNode);
}
}
Object parent = treeNode.getParent();
if (parent instanceof TreeNode) {
treeNode = (TreeNode) parent;
} else {
break;
}
}
// Couldn't find a proper InterpreterInfoTreeNodeRoot already having a TreeNode? Let's log it, as a TreeNode
// should always map to an InterpreterInfoTreeNodeRoot.
Log.log("Couldn't find a proper InterpreterInfoTreeNodeRoot already having TreeNode: " + next);
return null;
}
// Some unexpected type... let's get its parent until we find one expected (or just end up trying if we get to the root).
Object parent = next;
int i = 200;
// so, this is likely a problem in the content provider).
while (i > 0) {
i--;
if (i == 0) {
Log.log("Found a recursion for the element: " + next + " when searching parents. Please report this a a bug!");
}
if (parent == null || parent instanceof IWorkspaceRoot || parent instanceof IWorkingSet) {
break;
}
if (parent instanceof TreeNode && parent != next) {
return findExternalFileSelectionGivenTreeSelection(f, commonViewer, treeContentProvider, infosSearched, parent);
} else if (parent instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) parent;
IResource resource = (IResource) adaptable.getAdapter(IResource.class);
if (resource != null) {
IProject project = resource.getProject();
if (project != null && project != next) {
return findExternalFileSelectionGivenTreeSelection(f, commonViewer, treeContentProvider, infosSearched, project);
}
}
}
parent = treeContentProvider.getParent(parent);
}
return null;
}
Aggregations