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