Search in sources :

Example 1 with DataAndImageTreeNode

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

the class PyOutlineSelectionDialog method calculateHierarchy.

@Override
protected void calculateHierarchy() {
    if (root != null) {
        return;
    }
    if (this.ast == null && pyEdit != null) {
        this.ast = pyEdit.getAST();
    }
    if (ast == null) {
        return;
    }
    DefinitionsASTIteratorVisitor visitor = DefinitionsASTIteratorVisitor.create(ast);
    if (visitor == null) {
        return;
    }
    Map<ASTEntry, DataAndImageTreeNode<Object>> entryToTreeNode = new HashMap<ASTEntry, DataAndImageTreeNode<Object>>();
    // Step 1: create 'regular' tree structure from the nodes.
    DataAndImageTreeNode<Object> root = new DataAndImageTreeNode<Object>(null, null, null);
    for (Iterator<ASTEntry> it = visitor.getOutline(); it.hasNext(); ) {
        ASTEntry next = it.next();
        DataAndImageTreeNode<Object> n;
        if (next.parent != null) {
            DataAndImageTreeNode<Object> parent = entryToTreeNode.get(next.parent);
            if (parent == null) {
                Log.log("Unexpected condition: child found before parent!");
                parent = root;
            }
            n = new DataAndImageTreeNode<Object>(parent, new OutlineEntry(next), null);
        } else {
            n = new DataAndImageTreeNode<Object>(root, new OutlineEntry(next), null);
        }
        if (((OutlineEntry) n.data).node.beginLine <= startLineIndex) {
            initialSelection = n;
        }
        entryToTreeNode.put(next, n);
    }
    this.root = root;
}
Also used : HashMap(java.util.HashMap) ASTEntry(org.python.pydev.parser.visitors.scope.ASTEntry) DefinitionsASTIteratorVisitor(org.python.pydev.parser.visitors.scope.DefinitionsASTIteratorVisitor) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode)

Example 2 with DataAndImageTreeNode

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

the class ShowOutlineLabelProvider method getStyledText.

@Override
public StyledString getStyledText(Object element) {
    if (element instanceof DataAndImageTreeNode) {
        @SuppressWarnings("rawtypes") DataAndImageTreeNode treeNode = (DataAndImageTreeNode) element;
        element = treeNode.data;
    }
    if (element instanceof OutlineEntry) {
        OutlineEntry entry = (OutlineEntry) element;
        String start = NodeUtils.getFullRepresentationString(entry.node);
        if (entry.model != null) {
            FastStringBuffer suffix = new FastStringBuffer("    (", entry.model.name.length() + 50).append(entry.model.name);
            if (entry.model.moduleName != null && entry.model.moduleName.length() > 0) {
                suffix.append(" - ").append(entry.model.moduleName);
            }
            suffix.append(')');
            return new StyledString(start).append(suffix.toString(), StyledString.QUALIFIER_STYLER);
        } else if (entry.parentClass != null) {
            FastStringBuffer suffix = new FastStringBuffer("    (", entry.parentClass.length() + 4).append(entry.parentClass).append(')');
            return new StyledString(start).append(suffix.toString(), StyledString.QUALIFIER_STYLER);
        }
        return new StyledString(start);
    }
    if (element instanceof ASTEntry) {
        return new StyledString(NodeUtils.getFullRepresentationString(((ASTEntry) element).node));
    }
    return new StyledString(element.toString());
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) ASTEntry(org.python.pydev.parser.visitors.scope.ASTEntry) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode)

Example 3 with DataAndImageTreeNode

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

the class SyncSystemModulesManagerTest method testUpdateAndApply.

public void testUpdateAndApply() throws Exception {
    setupEnv();
    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);
    // Ok, the interpreter should be synchronized with the pythonpath which is currently set.
    // Now, check a different scenario: create a new path and add it to the interpreter pythonpath.
    // In this situation, the sync manager should ask the user if that path should actually be added
    // to this interpreter.
    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(libDir2.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(5, interpreterInfo.getModulesManager().getSize(false));
    }
}
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) 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 4 with DataAndImageTreeNode

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

the class SyncSystemModulesManagerTest method testSaveUserChoicesAfterSelection.

public void testSaveUserChoicesAfterSelection() throws Exception {
    setupEnv(false);
    IEclipsePreferences preferences = createPreferenceStore();
    SyncSystemModulesManager synchManager = new SyncSystemModulesManager();
    final DataAndImageTreeNode root = new DataAndImageTreeNode(null, null, null);
    Map<IInterpreterManager, Map<String, IInterpreterInfo>> managerToNameToInfo = InterpreterManagersAPI.getInterpreterManagerToInterpreterNameToInfo();
    synchManager.updateStructures(null, root, new ManagerInfoToUpdate(managerToNameToInfo), new SyncSystemModulesManager.CreateInterpreterInfoCallback() {

        @Override
        public IInterpreterInfo createInterpreterInfo(IInterpreterManager manager, String executable, IProgressMonitor monitor) {
            Collection<String> pythonpath = new ArrayList<>();
            pythonpath.add(libDir.toString());
            pythonpath.add(libDir2.toString());
            pythonpath.add(libDir3.toString());
            pythonpath.add(libZipFile.toString());
            final InterpreterInfo info = new InterpreterInfo("2.6", TestDependent.PYTHON2_EXE, pythonpath);
            return info;
        }
    });
    assertTrue(root.hasChildren());
    List<TreeNode> selectedElements = new ArrayList<>();
    TreeNode interpreterNode = (TreeNode) root.getChildren().get(0);
    selectedElements.add(interpreterNode);
    List<TreeNode> children = interpreterNode.getChildren();
    for (TreeNode<PythonpathChange> treeNode : children) {
        if (treeNode.getData().path.equals(libDir2.toString())) {
            selectedElements.add(treeNode);
        }
    }
    synchManager.saveUnselected(root, selectedElements, preferences);
    // Check that we ignored libDir3 and libZipFile
    String key = SyncSystemModulesManager.createKeyForInfo((IInterpreterInfo) ((TreeNode) root.getChildren().get(0)).getData());
    String entry = preferences.get(key, "");
    List<String> entries = StringUtils.split(entry, "|||");
    assertEquals(2, entries.size());
    HashSet<String> entriesSet = new HashSet<>(entries);
    assertEquals(new HashSet(entries), new HashSet(Arrays.asList(libDir3.toString(), libZipFile.toString())));
    // Check that only libDir2 is initially selected.
    List<TreeNode> initialSelection = synchManager.createInitialSelectionForDialogConsideringPreviouslyIgnored(root, preferences);
    assertEquals(2, initialSelection.size());
    TreeNode treeNode = initialSelection.get(0);
    TreeNode treeNode1 = initialSelection.get(1);
    TreeNode interpreterInfoNode;
    TreeNode pythonpathNode;
    if (treeNode.getData() instanceof IInterpreterInfo) {
        interpreterNode = treeNode;
        pythonpathNode = treeNode1;
    } else {
        interpreterNode = treeNode1;
        pythonpathNode = treeNode;
    }
    assertEquals(((PythonpathChange) pythonpathNode.getData()).path, libDir2.toString());
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) 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) 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) PythonpathChange(org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager.PythonpathChange) ManagerInfoToUpdate(org.python.pydev.ast.codecompletion.revisited.ManagerInfoToUpdate) HashSet(java.util.HashSet)

Example 5 with DataAndImageTreeNode

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

the class SyncSystemModulesManager method createInitialSelectionForDialogConsideringPreviouslyIgnored.

public List<TreeNode> createInitialSelectionForDialogConsideringPreviouslyIgnored(DataAndImageTreeNode root, IEclipsePreferences iPreferenceStore) {
    List<TreeNode> initialSelection = new ArrayList<>();
    for (DataAndImageTreeNode<IInterpreterInfo> interpreterNode : (List<DataAndImageTreeNode<IInterpreterInfo>>) root.getChildren()) {
        IInterpreterInfo info = interpreterNode.getData();
        String key = createKeyForInfo(info);
        String ignoredValue = iPreferenceStore.get(key, "");
        if (ignoredValue != null && ignoredValue.length() > 0) {
            Set<String> previouslyIgnored = new HashSet(StringUtils.split(ignoredValue, "|||"));
            boolean added = false;
            for (TreeNode<PythonpathChange> pathNode : interpreterNode.getChildren()) {
                if (!previouslyIgnored.contains(pathNode.data.path)) {
                    initialSelection.add(pathNode);
                    added = true;
                } else {
                    if (SyncSystemModulesManager.DEBUG) {
                        System.out.println("Removed from initial selection: " + pathNode);
                    }
                }
            }
            if (added) {
                initialSelection.add(interpreterNode);
            }
        } else {
            // Node and children all selected initially (nothing ignored).
            initialSelection.add(interpreterNode);
            initialSelection.addAll(interpreterNode.getChildren());
        }
    }
    if (SyncSystemModulesManager.DEBUG) {
        for (TreeNode treeNode : initialSelection) {
            System.out.println("Initial selection: " + treeNode.getData());
        }
    }
    return initialSelection;
}
Also used : IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) TreeNode(org.python.pydev.shared_core.structure.TreeNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

DataAndImageTreeNode (org.python.pydev.shared_core.structure.DataAndImageTreeNode)22 ArrayList (java.util.ArrayList)9 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)8 HierarchyNodeModel (org.python.pydev.ast.refactoring.HierarchyNodeModel)7 TreeNode (org.python.pydev.shared_core.structure.TreeNode)7 HashSet (java.util.HashSet)5 InterpreterInfo (org.python.pydev.ast.interpreter_managers.InterpreterInfo)5 ASTEntry (org.python.pydev.parser.visitors.scope.ASTEntry)5 HashMap (java.util.HashMap)4 List (java.util.List)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 StyledString (org.eclipse.jface.viewers.StyledString)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 File (java.io.File)3 Collection (java.util.Collection)3 Map (java.util.Map)3 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)2 BackingStoreException (org.osgi.service.prefs.BackingStoreException)2