Search in sources :

Example 1 with AdditionalInfoAndIInfo

use of com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo in project Pydev by fabioz.

the class GlobalsTwoPanelElementSelector2 method fillContentProvider.

/**
 * This is the place where we put all the info in the content provider. Note that here we must add
 * ALL the info -- later, we'll filter it based on the active working set.
 */
@Override
protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException {
    if (itemsFilter instanceof InfoFilter) {
        if (progressMonitor != null) {
            progressMonitor.beginTask("Searching...", this.additionalInfo.size());
        }
        for (AbstractAdditionalTokensInfo additionalInfo : this.additionalInfo) {
            if (progressMonitor != null) {
                if (progressMonitor.isCanceled()) {
                    return;
                } else {
                    progressMonitor.worked(1);
                }
            }
            // no duplicates
            Collection<IInfo> allTokens = new HashSet<IInfo>(additionalInfo.getAllTokens());
            for (IInfo iInfo : allTokens) {
                contentProvider.add(new AdditionalInfoAndIInfo(additionalInfo, iInfo), itemsFilter);
            }
            // Also show to the user the modules available as globals (2.2.3)
            IModulesManager modulesManager = null;
            try {
                if (additionalInfo instanceof AdditionalProjectInterpreterInfo) {
                    AdditionalProjectInterpreterInfo projectInterpreterInfo = (AdditionalProjectInterpreterInfo) additionalInfo;
                    IProject project = projectInterpreterInfo.getProject();
                    PythonNature nature = PythonNature.getPythonNature(project);
                    if (nature != null) {
                        ICodeCompletionASTManager astManager = nature.getAstManager();
                        if (astManager != null) {
                            modulesManager = astManager.getModulesManager();
                        }
                    }
                } else if (additionalInfo instanceof AdditionalSystemInterpreterInfo) {
                    AdditionalSystemInterpreterInfo systemInterpreterInfo = (AdditionalSystemInterpreterInfo) additionalInfo;
                    IInterpreterInfo defaultInterpreterInfo = systemInterpreterInfo.getManager().getDefaultInterpreterInfo(false);
                    modulesManager = defaultInterpreterInfo.getModulesManager();
                }
            } catch (Throwable e) {
                Log.log(e);
            }
            if (modulesManager != null) {
                SortedMap<ModulesKey, ModulesKey> allDirectModulesStartingWith = modulesManager.getAllDirectModulesStartingWith("");
                Collection<ModulesKey> values = allDirectModulesStartingWith.values();
                for (ModulesKey modulesKey : values) {
                    contentProvider.add(new AdditionalInfoAndIInfo(additionalInfo, new ModInfo(modulesKey.name, modulesManager.getNature(), modulesKey.file != null ? modulesKey.file.toString() : null, 1, 1)), itemsFilter);
                }
            }
        }
    }
    if (progressMonitor != null) {
        progressMonitor.done();
    }
}
Also used : IPythonNature(org.python.pydev.core.IPythonNature) PythonNature(org.python.pydev.plugin.nature.PythonNature) IModulesManager(org.python.pydev.core.IModulesManager) IProject(org.eclipse.core.resources.IProject) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) IInfo(org.python.pydev.core.IInfo) AdditionalProjectInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo) ICodeCompletionASTManager(org.python.pydev.core.ICodeCompletionASTManager) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) ModulesKey(org.python.pydev.core.ModulesKey) AbstractAdditionalTokensInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo) ModInfo(com.python.pydev.analysis.additionalinfo.ModInfo) HashSet(java.util.HashSet)

Example 2 with AdditionalInfoAndIInfo

use of com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo in project Pydev by fabioz.

the class GlobalsTwoPanelElementSelector2 method getItemsComparator.

@Override
protected Comparator<AdditionalInfoAndIInfo> getItemsComparator() {
    return new Comparator<AdditionalInfoAndIInfo>() {

        /*
             * (non-Javadoc)
             *
             * @see java.util.Comparator#compare(java.lang.Object,
             *      java.lang.Object)
             */
        @Override
        public int compare(AdditionalInfoAndIInfo resource1, AdditionalInfoAndIInfo resource2) {
            Collator collator = Collator.getInstance();
            String s1 = resource1.info.getName();
            String s2 = resource2.info.getName();
            int comparability = collator.compare(s1, s2);
            // same name
            if (comparability == 0) {
                String p1 = resource1.info.getDeclaringModuleName();
                String p2 = resource2.info.getDeclaringModuleName();
                if (p1 == null && p2 == null) {
                    return 0;
                }
                if (p1 != null && p2 == null) {
                    return -1;
                }
                if (p1 == null && p2 != null) {
                    return 1;
                }
                return p1.compareTo(p2);
            }
            return comparability;
        }
    };
}
Also used : AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) Comparator(java.util.Comparator) Collator(java.text.Collator)

Example 3 with AdditionalInfoAndIInfo

use of com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo in project Pydev by fabioz.

the class ModuleIInfoLabelProvider method getText.

@Override
public String getText(Object element) {
    if (element instanceof AdditionalInfoAndIInfo) {
        AdditionalInfoAndIInfo additional = (AdditionalInfoAndIInfo) element;
        element = additional.info;
        String suffix = null;
        try {
            if (additional.additionalInfo instanceof AdditionalProjectInterpreterInfo) {
                AdditionalProjectInterpreterInfo projectInterpreterInfo = (AdditionalProjectInterpreterInfo) additional.additionalInfo;
                suffix = projectInterpreterInfo.getProject().getName();
            } else if (additional.additionalInfo instanceof AdditionalSystemInterpreterInfo) {
                AdditionalSystemInterpreterInfo systemInterpreterInfo = (AdditionalSystemInterpreterInfo) additional.additionalInfo;
                suffix = systemInterpreterInfo.getManager().getDefaultInterpreterInfo(false).getName();
            }
        } catch (Throwable e) {
            Log.log(e);
        }
        String iInfoText = getIInfoText((IInfo) element, suffix);
        return iInfoText;
    }
    if (element instanceof String) {
        return (String) element;
    }
    return getIInfoText((IInfo) element, null);
}
Also used : AdditionalProjectInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo) AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)

Example 4 with AdditionalInfoAndIInfo

use of com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo in project Pydev by fabioz.

the class PyGlobalsBrowser method doSelect.

/**
 * @param pythonNatures the natures from were we can get info
 * @param additionalInfo the additional informations
 * @param selectedText the text that should be initially set as a filter
 */
public static void doSelect(List<IPythonNature> pythonNatures, List<AbstractAdditionalTokensInfo> additionalInfo, String selectedText) {
    SelectionDialog dialog = GlobalsDialogFactory.create(EditorUtils.getShell(), additionalInfo, selectedText);
    dialog.open();
    Object[] result = dialog.getResult();
    if (result != null && result.length > 0) {
        for (Object obj : result) {
            IInfo entry;
            if (obj instanceof AdditionalInfoAndIInfo) {
                AdditionalInfoAndIInfo additional = (AdditionalInfoAndIInfo) obj;
                try {
                    // all of the input natures).
                    if (additional.additionalInfo instanceof AdditionalProjectInterpreterInfo) {
                        AdditionalProjectInterpreterInfo projectInterpreterInfo = (AdditionalProjectInterpreterInfo) additional.additionalInfo;
                        IProject project = projectInterpreterInfo.getProject();
                        PythonNature pythonNature = PythonNature.getPythonNature(project);
                        if (pythonNature != null) {
                            pythonNatures = new ArrayList<IPythonNature>();
                            pythonNatures.add(pythonNature);
                        }
                    } else if (additional.additionalInfo instanceof AdditionalSystemInterpreterInfo) {
                        AdditionalSystemInterpreterInfo systemInterpreterInfo = (AdditionalSystemInterpreterInfo) additional.additionalInfo;
                        SystemPythonNature pythonNature = new SystemPythonNature(systemInterpreterInfo.getManager());
                        pythonNatures = new ArrayList<IPythonNature>();
                        pythonNatures.add(pythonNature);
                    }
                } catch (Throwable e) {
                    Log.log(e);
                }
                entry = additional.info;
            } else {
                entry = (IInfo) obj;
            }
            List<ItemPointer> pointers = new ArrayList<ItemPointer>();
            ICompletionState completionCache = new CompletionState();
            for (IPythonNature pythonNature : pythonNatures) {
                // try to find in one of the natures...
                ICodeCompletionASTManager astManager = pythonNature.getAstManager();
                if (astManager == null) {
                    continue;
                }
                AnalysisPlugin.getDefinitionFromIInfo(pointers, astManager, pythonNature, entry, completionCache, false, true);
                if (pointers.size() > 0) {
                    new PyOpenAction().run(pointers.get(0));
                    // don't check the other natures
                    break;
                }
            }
        }
    }
}
Also used : IPythonNature(org.python.pydev.core.IPythonNature) PythonNature(org.python.pydev.plugin.nature.PythonNature) SystemPythonNature(org.python.pydev.plugin.nature.SystemPythonNature) PyOpenAction(org.python.pydev.editor.actions.PyOpenAction) IPythonNature(org.python.pydev.core.IPythonNature) ArrayList(java.util.ArrayList) SystemPythonNature(org.python.pydev.plugin.nature.SystemPythonNature) ICompletionState(org.python.pydev.core.ICompletionState) CompletionState(org.python.pydev.ast.codecompletion.revisited.CompletionState) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) IProject(org.eclipse.core.resources.IProject) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInfo(org.python.pydev.core.IInfo) AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) AdditionalProjectInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo) ICodeCompletionASTManager(org.python.pydev.core.ICodeCompletionASTManager) AdditionalInfoAndIInfo(com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo) ICompletionState(org.python.pydev.core.ICompletionState) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer)

Aggregations

AdditionalInfoAndIInfo (com.python.pydev.analysis.additionalinfo.AdditionalInfoAndIInfo)4 AdditionalProjectInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo)3 AdditionalSystemInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)3 IProject (org.eclipse.core.resources.IProject)2 ICodeCompletionASTManager (org.python.pydev.core.ICodeCompletionASTManager)2 IInfo (org.python.pydev.core.IInfo)2 IPythonNature (org.python.pydev.core.IPythonNature)2 PythonNature (org.python.pydev.plugin.nature.PythonNature)2 AbstractAdditionalTokensInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo)1 ModInfo (com.python.pydev.analysis.additionalinfo.ModInfo)1 Collator (java.text.Collator)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 SelectionDialog (org.eclipse.ui.dialogs.SelectionDialog)1 CompletionState (org.python.pydev.ast.codecompletion.revisited.CompletionState)1 ItemPointer (org.python.pydev.ast.item_pointer.ItemPointer)1 ICompletionState (org.python.pydev.core.ICompletionState)1 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)1 IModulesManager (org.python.pydev.core.IModulesManager)1