Search in sources :

Example 21 with TreeNode

use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.

the class SyncSystemModulesManagerTest method testUpdateWhenEggIsAdded.

public void testUpdateWhenEggIsAdded() throws Exception {
    setupEnv(true);
    SyncSystemModulesManager synchManager = new SyncSystemModulesManager();
    final DataAndImageTreeNode root = new DataAndImageTreeNode(null, null, null);
    Map<IInterpreterManager, Map<String, IInterpreterInfo>> managerToNameToInfoMap = InterpreterManagersAPI.getInterpreterManagerToInterpreterNameToInfo();
    ManagerInfoToUpdate managerToNameToInfo = new ManagerInfoToUpdate(managerToNameToInfoMap);
    checkUpdateStructures(synchManager, root, managerToNameToInfo);
    checkSynchronize(synchManager, root, managerToNameToInfo);
    root.clear();
    managerToNameToInfo = new ManagerInfoToUpdate(InterpreterManagersAPI.getInterpreterManagerToInterpreterNameToInfo());
    synchManager.updateStructures(null, root, managerToNameToInfo, new SyncSystemModulesManager.CreateInterpreterInfoCallback() {

        @Override
        public IInterpreterInfo createInterpreterInfo(IInterpreterManager manager, String executable, IProgressMonitor monitor) {
            Collection<String> pythonpath = new ArrayList<String>();
            pythonpath.add(libDir.toString());
            pythonpath.add(libZipFile.toString());
            final InterpreterInfo info = new InterpreterInfo("2.6", TestDependent.PYTHON2_EXE, pythonpath);
            return info;
        }
    });
    assertTrue(root.hasChildren());
    List<TreeNode> selectElements = new ArrayList<>();
    selectElements.addAll(root.flattenChildren());
    synchManager.applySelectedChangesToInterpreterInfosPythonpath(root, selectElements, null);
    List<IInterpreterInfo> allInterpreterInfos = InterpreterManagersAPI.getAllInterpreterInfos();
    for (IInterpreterInfo interpreterInfo : allInterpreterInfos) {
        assertEquals(4, interpreterInfo.getModulesManager().getSize(false));
        AdditionalSystemInterpreterInfo additionalInfo = (AdditionalSystemInterpreterInfo) AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(interpreterInfo.getModulesManager().getInterpreterManager(), interpreterInfo.getExecutableOrJar());
        Collection<IInfo> allTokens = additionalInfo.getAllTokens();
        assertEquals(4, additionalInfo.getAllTokens().size());
    }
}
Also used : ArrayList(java.util.ArrayList) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) IInterpreterManager(org.python.pydev.core.IInterpreterManager) SyncSystemModulesManager(org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInfo(org.python.pydev.core.IInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) TreeNode(org.python.pydev.shared_core.structure.TreeNode) Collection(java.util.Collection) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) HashMap(java.util.HashMap) Map(java.util.Map) ManagerInfoToUpdate(org.python.pydev.ast.codecompletion.revisited.ManagerInfoToUpdate)

Example 22 with TreeNode

use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.

the class PydevPackageExplorer method tryToReveal.

/**
 * This is the method that actually tries to reveal some item in the tree.
 *
 * It will go through the pipeline to see if the actual object to reveal has been replaced in the replace pipeline.
 */
public boolean tryToReveal(Object element) {
    element = getPythonModelElement(element);
    if (element instanceof PydevZipFileStorage) {
        pythonLinkHelper.setCommonViewer(this.getCommonViewer());
        PydevZipFileStorage pydevZipFileStorage = (PydevZipFileStorage) element;
        IStructuredSelection externalFileSelectionInTree = pythonLinkHelper.findExternalFileSelection(pydevZipFileStorage.zipFile);
        if (externalFileSelectionInTree != null && !externalFileSelectionInTree.isEmpty()) {
            Object firstElement = externalFileSelectionInTree.getFirstElement();
            if (firstElement instanceof TreeNode) {
                TreeNode treeNode = (TreeNode) firstElement;
                // Ok, got to the zip file, let's try to find the path below it...
                String zipPath = pydevZipFileStorage.zipPath;
                List<String> split = StringUtils.split(zipPath, '/');
                for (String string : split) {
                    List<TreeNode> children = treeNode.getChildren();
                    for (TreeNode<LabelAndImage> child : children) {
                        if (string.equals(child.getData().label)) {
                            treeNode = child;
                            // Goes on to the next substring...
                            break;
                        }
                    }
                }
                if (revealAndVerify(new StructuredSelection(treeNode))) {
                    return true;
                }
            } else {
                Log.log("Expected a TreeNode. Found: " + firstElement);
                // Just go on to show the zip, not the internal contents...
                if (revealAndVerify(externalFileSelectionInTree)) {
                    return true;
                }
            }
        }
    } else if (element instanceof File) {
        pythonLinkHelper.setCommonViewer(this.getCommonViewer());
        IStructuredSelection externalFileSelectionInTree = pythonLinkHelper.findExternalFileSelection((File) element);
        if (externalFileSelectionInTree != null && !externalFileSelectionInTree.isEmpty()) {
            if (revealAndVerify(externalFileSelectionInTree)) {
                return true;
            }
        }
    }
    // null is checked in the revealAndVerify function
    if (revealAndVerify(element)) {
        return true;
    }
    // if it is a wrapped resource that we couldn't show, try to reveal as a resource...
    if (element instanceof IAdaptable && !(element instanceof IResource)) {
        IAdaptable adaptable = (IAdaptable) element;
        IResource resource = adaptable.getAdapter(IResource.class);
        if (resource != null) {
            if (revealAndVerify(resource)) {
                return true;
            }
        }
    }
    return false;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) LabelAndImage(org.python.pydev.navigator.LabelAndImage) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TreeNode(org.python.pydev.shared_core.structure.TreeNode) PydevZipFileStorage(org.python.pydev.shared_ui.editor_input.PydevZipFileStorage) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 23 with TreeNode

use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.

the class AbstractFilter method getName.

protected String getName(Object element) {
    if (element instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) element;
        Object adapted = adaptable.getAdapter(IResource.class);
        if (adapted instanceof IResource) {
            IResource resource = (IResource) adapted;
            return resource.getName();
        }
    } else if (element instanceof TreeNode) {
        TreeNode treeNode = (TreeNode) element;
        Object data = treeNode.getData();
        if (data instanceof LabelAndImage) {
            return ((LabelAndImage) data).label;
        }
    }
    return null;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) TreeNode(org.python.pydev.shared_core.structure.TreeNode) LabelAndImage(org.python.pydev.navigator.LabelAndImage) IResource(org.eclipse.core.resources.IResource)

Aggregations

TreeNode (org.python.pydev.shared_core.structure.TreeNode)23 ArrayList (java.util.ArrayList)9 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)8 DataAndImageTreeNode (org.python.pydev.shared_core.structure.DataAndImageTreeNode)7 HashSet (java.util.HashSet)6 IResource (org.eclipse.core.resources.IResource)5 IAdaptable (org.eclipse.core.runtime.IAdaptable)5 InterpreterInfo (org.python.pydev.ast.interpreter_managers.InterpreterInfo)5 HashMap (java.util.HashMap)4 List (java.util.List)4 IProject (org.eclipse.core.resources.IProject)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 SyncSystemModulesManager (org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager)4 IInterpreterManager (org.python.pydev.core.IInterpreterManager)4 AdditionalSystemInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)3 Collection (java.util.Collection)3 Map (java.util.Map)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 IWrappedResource (org.python.pydev.navigator.elements.IWrappedResource)3