use of org.python.pydev.navigator.PythonpathTreeNode in project Pydev by fabioz.
the class PyOpenResourceAction method openFiles.
@Override
protected void openFiles(PythonpathTreeNode[] pythonPathFilesSelected) {
for (PythonpathTreeNode n : pythonPathFilesSelected) {
try {
if (PythonPathHelper.isValidSourceFile(n.file.getName())) {
new PyOpenAction().run(new ItemPointer(n.file));
} else {
final IFileStore fileStore = EFS.getLocalFileSystem().getStore(n.file.toURI());
IDE.openEditorOnFileStore(page, fileStore);
}
} catch (PartInitException e) {
Log.log(e);
}
}
}
use of org.python.pydev.navigator.PythonpathTreeNode in project Pydev by fabioz.
the class PyOpenPythonFileAction method fillSelections.
/**
* This method will get the given selection and fill the related attributes to match the selection correctly
* (files, nodes and containers).
*/
protected synchronized void fillSelections() {
filesSelected.clear();
nodesSelected.clear();
containersSelected.clear();
pythonPathFilesSelected.clear();
pythonPathZipFilesSelected.clear();
ISelection selection = provider.getSelection();
if (!selection.isEmpty()) {
IStructuredSelection sSelection = (IStructuredSelection) selection;
Iterator iterator = sSelection.iterator();
while (iterator.hasNext()) {
Object element = iterator.next();
if (element instanceof PythonNode) {
nodesSelected.add((PythonNode) element);
} else if (element instanceof PythonpathZipChildTreeNode) {
PythonpathZipChildTreeNode node = (PythonpathZipChildTreeNode) element;
if (node.isDir) {
containersSelected.add(node);
} else {
pythonPathZipFilesSelected.add(node);
}
} else if (element instanceof PythonpathTreeNode) {
PythonpathTreeNode node = (PythonpathTreeNode) element;
if (node.file.isFile()) {
pythonPathFilesSelected.add(node);
} else {
containersSelected.add(node);
}
} else if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
IFile file = adaptable.getAdapter(IFile.class);
if (file != null) {
filesSelected.add(file);
} else {
IContainer container = adaptable.getAdapter(IContainer.class);
if (container != null) {
containersSelected.add(element);
}
}
}
}
}
}
use of org.python.pydev.navigator.PythonpathTreeNode in project Pydev by fabioz.
the class PythonLinkHelper method findMatchInTreeNodeRoot.
/**
* Tries to find a match for the element in the given root passed. If found returns true.
*
* @param infosSearched: a memo to know which infos were already searched to prevent searching many times in
* the same place.
*/
private IStructuredSelection findMatchInTreeNodeRoot(File element, CommonViewer commonViewer, InterpreterInfoTreeNodeRoot treeNodeRoot, Set<IInterpreterInfo> infosSearched) {
if (infosSearched.contains(treeNodeRoot.interpreterInfo)) {
return null;
}
infosSearched.add(treeNodeRoot.interpreterInfo);
List<TreeNode> nodesOrderedForFileSearch = treeNodeRoot.getNodesOrderedForFileSearch();
for (TreeNode node : nodesOrderedForFileSearch) {
PythonpathTreeNode match = findMatch(node, element);
if (match != null) {
return new StructuredSelection(match);
}
}
return null;
}
use of org.python.pydev.navigator.PythonpathTreeNode 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