use of org.eclipse.ui.navigator.PipelinedShapeModification in project Pydev by fabioz.
the class PydevPackageExplorer method getPythonModelElement.
/**
* @param element the element that should be gotten as an element from the pydev model
* @return a pydev element or the same element passed as a parameter.
*/
private Object getPythonModelElement(Object element) {
if (element instanceof IWrappedResource) {
return element;
}
INavigatorPipelineService pipelineService = this.getNavigatorContentService().getPipelineService();
if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
IFile file = adaptable.getAdapter(IFile.class);
if (file != null) {
HashSet<Object> files = new ContributorTrackingSet((NavigatorContentService) this.getNavigatorContentService());
files.add(file);
pipelineService.interceptAdd(new PipelinedShapeModification(file.getParent(), files));
if (files.size() > 0) {
element = files.iterator().next();
}
}
}
return element;
}
use of org.eclipse.ui.navigator.PipelinedShapeModification 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.eclipse.ui.navigator.PipelinedShapeModification 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.eclipse.ui.navigator.PipelinedShapeModification in project Pydev by fabioz.
the class PythonModelProviderTest method testFolderToSourceFolder2.
public void testFolderToSourceFolder2() throws Exception {
final HashSet<String> pythonPathSet = new HashSet<String>();
pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source");
String source2Folder = TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source2";
File f = new File(source2Folder);
File f1 = new File(f, "childFolder");
File f2 = new File(f1, "rechildFolder");
if (f2.exists()) {
f2.delete();
}
if (f1.exists()) {
f1.delete();
}
if (f.exists()) {
f.delete();
}
// still not created!
pythonPathSet.add(source2Folder);
PythonNature nature = createNature(pythonPathSet);
project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature, false);
provider = new PythonModelProvider();
Object[] children1 = provider.getChildren(project);
assertEquals(1, children1.length);
assertTrue("Expected source folder. Received: " + children1[0], children1[0] instanceof PythonSourceFolder);
f.mkdir();
f1.mkdir();
f2.mkdir();
try {
FolderStub source2FolderFile = new FolderStub(project, f);
FolderStub source2FolderChild = new FolderStub(project, source2FolderFile, f1);
FolderStub source2FolderReChild = new FolderStub(project, source2FolderChild, f2);
Set set = new HashSet();
set.add(source2FolderReChild);
provider.interceptAdd(new PipelinedShapeModification(source2FolderChild, set));
assertEquals(1, set.size());
PythonFolder c = (PythonFolder) set.iterator().next();
PythonSourceFolder sourceFolder = c.getSourceFolder();
assertTrue(sourceFolder instanceof PythonSourceFolder);
set.clear();
set.add(source2FolderChild);
provider.interceptRemove(new PipelinedShapeModification(source2FolderFile, set));
assertTrue(set.iterator().next() instanceof PythonFolder);
// System.out.println(set);
set.clear();
set.add(source2FolderReChild);
provider.interceptAdd(new PipelinedShapeModification(source2FolderChild, set));
assertTrue(set.iterator().next() instanceof PythonFolder);
// System.out.println(set);
set.clear();
set.add(source2FolderChild);
provider.interceptRemove(new PipelinedShapeModification(source2FolderFile, set));
assertTrue(set.iterator().next() instanceof PythonFolder);
// System.out.println(set);
set.clear();
set.add(source2FolderReChild);
provider.interceptAdd(new PipelinedShapeModification(source2FolderChild, set));
assertTrue(set.iterator().next() instanceof PythonFolder);
// System.out.println(set);
} finally {
f2.delete();
f1.delete();
f.delete();
}
}
use of org.eclipse.ui.navigator.PipelinedShapeModification in project Pydev by fabioz.
the class PythonModelProviderTest method testFolderToSourceFolder.
public void testFolderToSourceFolder() throws Exception {
final HashSet<String> pythonPathSet = new HashSet<String>();
pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source");
String source2Folder = TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source2";
File f = new File(source2Folder);
File f1 = new File(f, "childFolder");
if (f1.exists()) {
f1.delete();
}
if (f.exists()) {
f.delete();
}
// still not created!
pythonPathSet.add(source2Folder);
PythonNature nature = createNature(pythonPathSet);
project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature, false);
provider = new PythonModelProvider();
Object[] children1 = provider.getChildren(project);
assertEquals(1, children1.length);
assertTrue("Found: " + children1[0], children1[0] instanceof PythonSourceFolder);
f.mkdir();
f1.mkdir();
try {
FolderStub source2FolderFile = new FolderStub(project, f);
FolderStub source2FolderChild = new FolderStub(project, source2FolderFile, f1);
Set set = new HashSet();
set.add(source2FolderChild);
provider.interceptAdd(new PipelinedShapeModification(source2FolderFile, set));
assertEquals(1, set.size());
PythonFolder c = (PythonFolder) set.iterator().next();
PythonSourceFolder sourceFolder = c.getSourceFolder();
assertTrue(sourceFolder instanceof PythonSourceFolder);
set.clear();
set.add(source2FolderChild);
provider.interceptAdd(new PipelinedShapeModification(source2FolderFile, set));
} finally {
f1.delete();
f.delete();
}
}
Aggregations