use of org.python.pydev.navigator.elements.IWrappedResource 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.navigator.elements.IWrappedResource in project Pydev by fabioz.
the class PythonModelProvider method convertToPythonElementsUpdateOrRefresh.
/**
* Converts elements to the python model -- but only creates it if it's parent is found in the python model
*/
protected boolean convertToPythonElementsUpdateOrRefresh(Set<Object> currentChildren) {
final Map<PythonNature, Set<String>> natureToSourcePathSet = new HashMap<>();
LinkedHashSet<Object> convertedChildren = new LinkedHashSet<>();
for (Iterator<Object> childrenItr = currentChildren.iterator(); childrenItr.hasNext(); ) {
Object child = childrenItr.next();
if (child == null) {
// only case when a child is removed and another one is not added (null)
childrenItr.remove();
continue;
}
if (child instanceof IResource && !(child instanceof IWrappedResource)) {
IResource res = (IResource) child;
Object resourceInPythonModel = getResourceInPythonModel(res, true);
if (resourceInPythonModel != null) {
// if it is in the python model, just go on
childrenItr.remove();
convertedChildren.add(resourceInPythonModel);
} else {
// now, if it's not but its parent is, go on and create it
IContainer p = res.getParent();
if (p == null) {
continue;
}
Object pythonParent = getResourceInPythonModel(p, true);
if (pythonParent instanceof IWrappedResource) {
IWrappedResource parent = (IWrappedResource) pythonParent;
if (res instanceof IProject) {
throw new RuntimeException("A project's parent should never be an IWrappedResource!");
} else if (res instanceof IFolder) {
childrenItr.remove();
convertedChildren.add(new PythonFolder(parent, (IFolder) res, parent.getSourceFolder()));
} else if (res instanceof IFile) {
childrenItr.remove();
convertedChildren.add(new PythonFile(parent, (IFile) res, parent.getSourceFolder()));
} else if (child instanceof IResource) {
childrenItr.remove();
convertedChildren.add(new PythonResource(parent, (IResource) child, parent.getSourceFolder()));
}
} else if (res instanceof IFolder) {
// ok, still not in the model... could it be a PythonSourceFolder
IFolder folder = (IFolder) res;
IProject project = folder.getProject();
if (project == null) {
continue;
}
PythonNature nature = PythonNature.getPythonNature(project);
if (nature == null) {
continue;
}
Set<String> sourcePathSet = this.getSourcePathSet(natureToSourcePathSet, nature);
PythonSourceFolder wrapped = tryWrapSourceFolder(p, folder, sourcePathSet);
if (wrapped != null) {
childrenItr.remove();
convertedChildren.add(wrapped);
}
}
}
}
}
if (!convertedChildren.isEmpty()) {
currentChildren.addAll(convertedChildren);
return true;
}
return false;
}
use of org.python.pydev.navigator.elements.IWrappedResource 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.navigator.elements.IWrappedResource in project Pydev by fabioz.
the class PythonModelProviderTest method testProjectIsRoot2.
/**
* Test if setting the project root as a source folder will return an object from the python model.
*/
public void testProjectIsRoot2() throws Exception {
String pythonpathLoc = TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot";
final HashSet<String> pythonPathSet = new HashSet<String>();
pythonPathSet.add(pythonpathLoc);
PythonNature nature = createNature(pythonPathSet);
WorkspaceRootStub workspaceRootStub = new WorkspaceRootStub();
project = new ProjectStub(new File(pythonpathLoc), nature);
provider = new PythonModelProvider();
FolderStub folder = new FolderStub(project, new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source"));
workspaceRootStub.addChild(project);
project.setParent(workspaceRootStub);
HashSet<Object> folders = new HashSet<Object>();
folders.add(folder);
PipelinedShapeModification addModification = new PipelinedShapeModification(project, folders);
addModification.setParent(project);
provider.interceptAdd(addModification);
assertEquals(1, addModification.getChildren().size());
// it should've been wrapped
assertTrue(addModification.getChildren().iterator().next() instanceof IWrappedResource);
}
use of org.python.pydev.navigator.elements.IWrappedResource in project Pydev by fabioz.
the class CustomizationCommons method getResourceFromObject.
public static IResource getResourceFromObject(Object receiver) {
if (receiver instanceof IWrappedResource) {
IWrappedResource wrappedResource = (IWrappedResource) receiver;
Object actualObject = wrappedResource.getActualObject();
if (actualObject instanceof IResource) {
return (IResource) actualObject;
}
}
if (receiver instanceof IResource) {
return (IResource) receiver;
}
return null;
}
Aggregations