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();
}
}
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;
}
};
}
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);
}
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;
}
}
}
}
}
Aggregations