use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class PythonLabelProvider method getImage.
/**
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
*/
@Override
public Image getImage(Object element) {
if (element instanceof PythonProjectSourceFolder) {
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.PROJECT_SOURCE_FOLDER_ICON));
}
if (element instanceof PythonSourceFolder) {
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.SOURCE_FOLDER_ICON));
}
if (element instanceof PythonFolder) {
PythonFolder folder = (PythonFolder) element;
IFolder actualObject = folder.getActualObject();
if (actualObject != null) {
if (checkIfValidPackageFolder(folder)) {
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.FOLDER_PACKAGE_ICON));
}
}
return provider.getImage(actualObject);
}
if (element instanceof PythonNode) {
PythonNode node = (PythonNode) element;
return node.entry.getImage();
}
if (element instanceof IWrappedResource) {
IWrappedResource resource = (IWrappedResource) element;
Object actualObject = resource.getActualObject();
if (actualObject instanceof IFile) {
IFile iFile = (IFile) actualObject;
final String name = iFile.getName();
if (name.indexOf('.') == -1) {
try {
if (CorePlugin.markAsPyDevFileIfDetected(iFile)) {
if (FileTypesPreferences.isCythonFile(name)) {
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.CYTHON_FILE_ICON));
}
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.PY_FILE_ICON));
}
} catch (Exception e) {
// Ignore
}
}
if (FileTypesPreferences.isCythonFile(name)) {
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.CYTHON_FILE_ICON));
}
if (name.startsWith("__init__.") && PythonPathHelper.isValidSourceFile(name)) {
return ImageCache.asImage(PyTitlePreferencesPage.getInitIcon());
} else {
IProject project = iFile.getProject();
try {
if (project.hasNature(PythonNature.DJANGO_NATURE_ID)) {
String djangoModulesHandling = PyTitlePreferencesPage.getDjangoModulesHandling();
if (djangoModulesHandling == PyTitlePreferencesPage.TITLE_EDITOR_DJANGO_MODULES_SHOW_PARENT_AND_DECORATE || djangoModulesHandling == PyTitlePreferencesPage.TITLE_EDITOR_DJANGO_MODULES_DECORATE) {
if (PyTitlePreferencesPage.isDjangoModuleToDecorate(name)) {
return ImageCache.asImage(PyTitlePreferencesPage.getDjangoModuleIcon(name));
}
}
}
} catch (CoreException e) {
Log.log(e);
}
}
}
return provider.getImage(actualObject);
}
if (element instanceof ProjectConfigError) {
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.ERROR));
}
if (element instanceof TreeNode<?>) {
TreeNode<?> treeNode = (TreeNode<?>) element;
LabelAndImage data = (LabelAndImage) treeNode.getData();
return ImageCache.asImage(data.image);
}
if (element instanceof IFile) {
IFile iFile = (IFile) element;
String name = iFile.getName();
if (FileTypesPreferences.isCythonFile(name)) {
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.CYTHON_FILE_ICON));
}
}
if (element instanceof IProject) {
IProject project = (IProject) element;
if (!project.isOpen()) {
return null;
}
IMarker[] markers;
try {
markers = project.findMarkers(PythonBaseModelProvider.PYDEV_PACKAGE_EXPORER_PROBLEM_MARKER, true, 0);
} catch (CoreException e1) {
Log.log(e1);
return null;
}
if (markers == null || markers.length == 0) {
return null;
}
// We have errors: make them explicit.
if (projectWithError == null) {
synchronized (lock) {
// the other enters the lock, it does not need to recalculated).
if (projectWithError == null) {
// Note on double-checked locking idiom: http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html.
// (would not work as expected on java 1.4)
Image image = provider.getImage(element);
try {
DecorationOverlayIcon decorationOverlayIcon = new DecorationOverlayIcon(image, ImageCache.asImageDescriptor(SharedUiPlugin.getImageCache().getDescriptor(UIConstants.ERROR_SMALL)), IDecoration.BOTTOM_LEFT);
projectWithError = decorationOverlayIcon.createImage();
} catch (Exception e) {
Log.log("Unable to create error decoration for project icon.", e);
projectWithError = image;
}
}
}
}
return projectWithError;
}
if (element instanceof IWorkingSet) {
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.WORKING_SET));
}
return null;
}
use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class PythonLabelProvider method getText.
/**
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
if (element instanceof PythonNode) {
PythonNode node = (PythonNode) element;
return node.entry.toString();
}
if (element instanceof PythonSourceFolder) {
PythonSourceFolder sourceFolder = (PythonSourceFolder) element;
return provider.getText(sourceFolder.container);
}
if (element instanceof IWrappedResource) {
IWrappedResource resource = (IWrappedResource) element;
return provider.getText(resource.getActualObject());
}
if (element instanceof TreeNode<?>) {
TreeNode<?> treeNode = (TreeNode<?>) element;
LabelAndImage data = (LabelAndImage) treeNode.getData();
return data.label;
}
if (element instanceof ProjectConfigError) {
return ((ProjectConfigError) element).getLabel();
}
return provider.getText(element);
}
use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class PythonModelProvider method getPipelinedChildren.
/**
* This method basically replaces all the elements for other resource elements
* or for wrapped elements.
*
* @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedChildren(java.lang.Object, java.util.Set)
*/
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void getPipelinedChildren(Object parent, Set currentElements) {
if (DEBUG) {
System.out.println("getPipelinedChildren for: " + parent);
}
final Map<PythonNature, Set<String>> natureToSourcePathSet = new HashMap<>();
if (parent instanceof IWrappedResource) {
// Note: It seems that this NEVER happens (IWrappedResources only have getChildren called, not getPipelinedChildren)
Object[] children = getChildren(parent);
currentElements.clear();
currentElements.addAll(Arrays.asList(children));
if (DEBUG) {
System.out.println("getPipelinedChildren RETURN: " + currentElements);
}
if (parent instanceof PythonProjectSourceFolder) {
PythonProjectSourceFolder projectSourceFolder = (PythonProjectSourceFolder) parent;
IProject project = (IProject) projectSourceFolder.getActualObject();
fillChildrenForProject(currentElements, project, parent);
}
return;
} else if (parent instanceof IWorkspaceRoot) {
switch(topLevelChoice.getRootMode()) {
case TopLevelProjectsOrWorkingSetChoice.WORKING_SETS:
currentElements.clear();
currentElements.addAll(getWorkingSetsCallback.call((IWorkspaceRoot) parent));
if (currentElements.size() == 0) {
currentElements.add(createErrorNoWorkingSetsDefined(parent));
}
case TopLevelProjectsOrWorkingSetChoice.PROJECTS:
}
} else if (parent instanceof IWorkingSet) {
IWorkingSet workingSet = (IWorkingSet) parent;
currentElements.clear();
currentElements.addAll(Arrays.asList(workingSet.getElements()));
if (currentElements.size() == 0) {
currentElements.add(createErrorNoWorkingSetsDefined(workingSet));
}
} else if (parent instanceof TreeNode) {
TreeNode treeNode = (TreeNode) parent;
currentElements.addAll(treeNode.getChildren());
} else if (parent instanceof IProject) {
IProject project = (IProject) parent;
fillChildrenForProject(currentElements, project, getResourceInPythonModel(project));
}
PipelinedShapeModification modification = new PipelinedShapeModification(parent, currentElements);
convertToPythonElementsAddOrRemove(modification, true, natureToSourcePathSet);
if (DEBUG) {
System.out.println("getPipelinedChildren RETURN: " + modification.getChildren());
}
}
use of org.python.pydev.shared_core.structure.TreeNode 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));
}
}
use of org.python.pydev.shared_core.structure.TreeNode 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());
}
Aggregations