Search in sources :

Example 1 with PythonpathTreeNode

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);
        }
    }
}
Also used : PyOpenAction(org.python.pydev.editor.actions.PyOpenAction) IFileStore(org.eclipse.core.filesystem.IFileStore) PartInitException(org.eclipse.ui.PartInitException) PythonpathTreeNode(org.python.pydev.navigator.PythonpathTreeNode) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer)

Example 2 with PythonpathTreeNode

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);
                    }
                }
            }
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) PythonpathZipChildTreeNode(org.python.pydev.navigator.PythonpathZipChildTreeNode) PythonNode(org.python.pydev.navigator.elements.PythonNode) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IContainer(org.eclipse.core.resources.IContainer) PythonpathTreeNode(org.python.pydev.navigator.PythonpathTreeNode)

Example 3 with PythonpathTreeNode

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;
}
Also used : PythonpathTreeNode(org.python.pydev.navigator.PythonpathTreeNode) TreeNode(org.python.pydev.shared_core.structure.TreeNode) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PythonpathTreeNode(org.python.pydev.navigator.PythonpathTreeNode)

Example 4 with PythonpathTreeNode

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;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) InterpreterInfoTreeNodeRoot(org.python.pydev.navigator.InterpreterInfoTreeNodeRoot) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) PythonpathTreeNode(org.python.pydev.navigator.PythonpathTreeNode) TreeNode(org.python.pydev.shared_core.structure.TreeNode) IResource(org.eclipse.core.resources.IResource) IWorkingSet(org.eclipse.ui.IWorkingSet) PythonpathTreeNode(org.python.pydev.navigator.PythonpathTreeNode)

Aggregations

PythonpathTreeNode (org.python.pydev.navigator.PythonpathTreeNode)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 TreeNode (org.python.pydev.shared_core.structure.TreeNode)2 Iterator (java.util.Iterator)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IContainer (org.eclipse.core.resources.IContainer)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IWorkingSet (org.eclipse.ui.IWorkingSet)1 PartInitException (org.eclipse.ui.PartInitException)1 ItemPointer (org.python.pydev.ast.item_pointer.ItemPointer)1 PyOpenAction (org.python.pydev.editor.actions.PyOpenAction)1 InterpreterInfoTreeNodeRoot (org.python.pydev.navigator.InterpreterInfoTreeNodeRoot)1 PythonpathZipChildTreeNode (org.python.pydev.navigator.PythonpathZipChildTreeNode)1 PythonNode (org.python.pydev.navigator.elements.PythonNode)1