use of org.python.pydev.shared_core.structure.DataAndImageTreeNode in project Pydev by fabioz.
the class SyncSystemModulesManager method computeChanges.
/**
* Given the tree structure we created initially with all the changes (root) and the elements
* that the user selected in the tree (selectElements), return a list of infos updated with the
* proper pythonpath.
*/
private List<IInterpreterInfo> computeChanges(final DataAndImageTreeNode root, List<TreeNode> selectElements) {
List<IInterpreterInfo> changedInfos = new ArrayList<>();
HashSet<TreeNode> set = new HashSet<TreeNode>(selectElements.size());
set.addAll(selectElements);
for (Object n : root.getChildren()) {
DataAndImageTreeNode interpreterNode = (DataAndImageTreeNode) n;
if (set.contains(interpreterNode)) {
IInterpreterInfo info = (IInterpreterInfo) interpreterNode.getData();
List<String> pythonPath = info.getPythonPath();
boolean changed = false;
OrderedSet<String> newPythonPath = new OrderedSet<String>(pythonPath);
for (Object entryNode : interpreterNode.getChildren()) {
DataAndImageTreeNode pythonpathNode = (DataAndImageTreeNode) entryNode;
if (set.contains(pythonpathNode)) {
PythonpathChange change = (PythonpathChange) pythonpathNode.data;
change.apply(newPythonPath);
changed = true;
}
}
if (changed) {
InterpreterInfo copy = (InterpreterInfo) info.makeCopy();
copy.libs.clear();
copy.libs.addAll(newPythonPath);
changedInfos.add(copy);
}
}
}
return changedInfos;
}
use of org.python.pydev.shared_core.structure.DataAndImageTreeNode in project Pydev by fabioz.
the class SyncSystemModulesManager method saveUnselected.
/**
* When the user selects changes in selectElementsInDialog, it's possible that he doesn't check some of the
* proposed changes, thus, in this case, we should save the unselected items in the preferences and the next
* time such a change is proposed, it should appear unchecked (and if all changes are unchecked, we shouldn't
* present the user with a dialog).
*
* @param root this is the initial structure, containing all the proposed changes.
* @param selectedElements this is a structure which will hold only the selected changes.
* @param iPreferenceStore this is the store where we'll keep the selected changes.
*/
public void saveUnselected(DataAndImageTreeNode root, List<TreeNode> selectedElements, IEclipsePreferences iPreferenceStore) {
// root has null data, level 1 has IInterpreterInfo and level 2 has PythonpathChange.
HashSet<TreeNode> selectionSet = new HashSet<>();
if (selectedElements != null && selectedElements.size() > 0) {
selectionSet.addAll(selectedElements);
}
boolean changed = false;
for (DataAndImageTreeNode<IInterpreterInfo> interpreterNode : (List<DataAndImageTreeNode<IInterpreterInfo>>) root.getChildren()) {
Set<TreeNode> addToIgnore = new HashSet<>();
if (!selectionSet.contains(interpreterNode)) {
// ignore all the entries below this interpreter.
addToIgnore.addAll(interpreterNode.getChildren());
} else {
// check each entry and only add the ones not selected.
for (TreeNode<PythonpathChange> pathNode : interpreterNode.getChildren()) {
if (!selectionSet.contains(pathNode)) {
addToIgnore.add(pathNode);
}
}
}
if (addToIgnore.size() > 0) {
IInterpreterInfo info = interpreterNode.getData();
String key = createKeyForInfo(info);
ArrayList<String> addToIgnorePaths = new ArrayList<String>(addToIgnore.size());
for (TreeNode<PythonpathChange> node : addToIgnore) {
PythonpathChange data = node.getData();
addToIgnorePaths.add(data.path);
}
if (DEBUG) {
System.out.println("Setting key: " + key);
System.out.println("Paths ignored: " + addToIgnorePaths);
}
changed = true;
iPreferenceStore.put(key, StringUtils.join("|||", addToIgnorePaths));
}
}
if (changed) {
try {
iPreferenceStore.flush();
} catch (BackingStoreException e) {
Log.log(e);
}
}
}
use of org.python.pydev.shared_core.structure.DataAndImageTreeNode in project Pydev by fabioz.
the class SyncSystemModulesManager method updateStructures.
/**
* Here we'll update the tree structure to be shown to the user with the changes (root).
* The managerToNameToInfo structure has the information on the interpreter manager and related
* interpreter infos for which the changes should be checked.
*/
public void updateStructures(IProgressMonitor monitor, final DataAndImageTreeNode root, ManagerInfoToUpdate managerToNameToInfo, CreateInterpreterInfoCallback callback) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
IImageCache imageCache = SharedCorePlugin.getImageCache();
if (imageCache == null) {
imageCache = new IImageCache() {
@Override
public IImageHandle getStringDecorated(String key, String stringToAddToDecoration) {
return null;
}
@Override
public IImageHandle getImageDecorated(String key, String decoration, int decorationLocation, String secondDecoration, int secondDecorationLocation) {
return null;
}
@Override
public IImageHandle getImageDecorated(String key, String decoration, int decorationLocation) {
return null;
}
@Override
public IImageHandle getImageDecorated(String key, String decoration) {
return null;
}
@Override
public IImageDescriptor getDescriptor(String projectIcon) {
return null;
}
@Override
public IImageHandle get(String key) {
return null;
}
};
}
for (Tuple<IInterpreterManager, IInterpreterInfo> infos : managerToNameToInfo.getManagerAndInfos()) {
IInterpreterManager manager = infos.o1;
IInterpreterInfo internalInfo = infos.o2;
String executable = internalInfo.getExecutableOrJar();
IInterpreterInfo newInterpreterInfo = callback.createInterpreterInfo(manager, executable, monitor);
if (newInterpreterInfo == null) {
continue;
}
DefaultPathsForInterpreterInfo defaultPaths = new DefaultPathsForInterpreterInfo();
OrderedSet<String> newEntries = new OrderedSet<String>(newInterpreterInfo.getPythonPath());
newEntries.removeAll(internalInfo.getPythonPath());
// Iterate over the new entries to suggest what should be added (we already have only what's not there).
for (Iterator<String> it = newEntries.iterator(); it.hasNext(); ) {
String entryInPythonpath = it.next();
if (!defaultPaths.selectByDefault(entryInPythonpath) || !defaultPaths.exists(entryInPythonpath)) {
// Don't suggest the addition of entries in the workspace or entries which do not exist.
it.remove();
}
}
// Iterate over existing entries to suggest what should be removed.
OrderedSet<String> removedEntries = new OrderedSet<String>();
List<String> pythonPath = internalInfo.getPythonPath();
for (String string : pythonPath) {
if (!new File(string).exists()) {
// Only suggest a removal if it was removed from the filesystem.
removedEntries.add(string);
}
}
if (newEntries.size() > 0 || removedEntries.size() > 0) {
DataAndImageTreeNode<IInterpreterInfo> interpreterNode = new DataAndImageTreeNode<IInterpreterInfo>(root, internalInfo, imageCache.get(UIConstants.PY_INTERPRETER_ICON));
for (String s : newEntries) {
new DataAndImageTreeNode(interpreterNode, new PythonpathChange(s, true), imageCache.get(UIConstants.LIB_SYSTEM));
}
for (String s : removedEntries) {
new DataAndImageTreeNode(interpreterNode, new PythonpathChange(s, false), imageCache.get(UIConstants.REMOVE_LIB_SYSTEM));
}
}
}
}
use of org.python.pydev.shared_core.structure.DataAndImageTreeNode in project Pydev by fabioz.
the class PyOutlineSelectionDialog method addMethods.
private void addMethods(DataAndImageTreeNode<Object> nextEntry, HierarchyNodeModel model) {
if (model == null || model.parents == null) {
return;
}
for (HierarchyNodeModel parent : model.parents) {
DefinitionsASTIteratorVisitor visitor = DefinitionsASTIteratorVisitor.createForChildren(parent.ast);
if (visitor == null) {
continue;
}
Iterator<ASTEntry> outline = visitor.getOutline();
while (outline.hasNext()) {
ASTEntry entry = outline.next();
if (entry.parent == null) {
// only direct children...
new DataAndImageTreeNode<Object>(nextEntry, new OutlineEntry(entry, parent), null);
}
}
addMethods(nextEntry, parent);
}
}
use of org.python.pydev.shared_core.structure.DataAndImageTreeNode in project Pydev by fabioz.
the class PyOutlineSelectionDialog method gatherClasses.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void gatherClasses(DataAndImageTreeNode<Object> entry, IProgressMonitor monitor, List<Tuple<ClassDef, DataAndImageTreeNode<Object>>> gathered) {
List children = entry.getChildren();
if (children.size() == 0) {
return;
}
// Iterate in a copy, since we may change the original...
for (Object o : children) {
DataAndImageTreeNode<Object> nextEntry = (DataAndImageTreeNode<Object>) o;
if (((OutlineEntry) nextEntry.data).node instanceof ClassDef) {
ClassDef classDef = (ClassDef) ((OutlineEntry) nextEntry.data).node;
gathered.add(new Tuple<ClassDef, DataAndImageTreeNode<Object>>(classDef, nextEntry));
}
// Enter the leaf to fill it too.
gatherClasses(nextEntry, monitor, gathered);
}
}
Aggregations