Search in sources :

Example 1 with PipelinedShapeModification

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;
}
Also used : INavigatorPipelineService(org.eclipse.ui.navigator.INavigatorPipelineService) IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) ContributorTrackingSet(org.eclipse.ui.internal.navigator.ContributorTrackingSet) PipelinedShapeModification(org.eclipse.ui.navigator.PipelinedShapeModification) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource)

Example 2 with PipelinedShapeModification

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());
    }
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) PythonNature(org.python.pydev.plugin.nature.PythonNature) HashMap(java.util.HashMap) PythonProjectSourceFolder(org.python.pydev.navigator.elements.PythonProjectSourceFolder) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) PipelinedShapeModification(org.eclipse.ui.navigator.PipelinedShapeModification) TreeNode(org.python.pydev.shared_core.structure.TreeNode) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 3 with PipelinedShapeModification

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);
}
Also used : PythonNature(org.python.pydev.plugin.nature.PythonNature) FolderStub(org.python.pydev.shared_core.resource_stubs.FolderStub) PipelinedShapeModification(org.eclipse.ui.navigator.PipelinedShapeModification) File(java.io.File) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource) HashSet(java.util.HashSet)

Example 4 with PipelinedShapeModification

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();
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) PythonNature(org.python.pydev.plugin.nature.PythonNature) PythonFolder(org.python.pydev.navigator.elements.PythonFolder) FolderStub(org.python.pydev.shared_core.resource_stubs.FolderStub) PythonSourceFolder(org.python.pydev.navigator.elements.PythonSourceFolder) PipelinedShapeModification(org.eclipse.ui.navigator.PipelinedShapeModification) File(java.io.File) HashSet(java.util.HashSet)

Example 5 with PipelinedShapeModification

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();
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) PythonNature(org.python.pydev.plugin.nature.PythonNature) PythonFolder(org.python.pydev.navigator.elements.PythonFolder) FolderStub(org.python.pydev.shared_core.resource_stubs.FolderStub) PythonSourceFolder(org.python.pydev.navigator.elements.PythonSourceFolder) PipelinedShapeModification(org.eclipse.ui.navigator.PipelinedShapeModification) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

PipelinedShapeModification (org.eclipse.ui.navigator.PipelinedShapeModification)7 HashSet (java.util.HashSet)6 PythonNature (org.python.pydev.plugin.nature.PythonNature)6 File (java.io.File)5 Set (java.util.Set)4 IWorkingSet (org.eclipse.ui.IWorkingSet)4 IWrappedResource (org.python.pydev.navigator.elements.IWrappedResource)4 FolderStub (org.python.pydev.shared_core.resource_stubs.FolderStub)4 PythonSourceFolder (org.python.pydev.navigator.elements.PythonSourceFolder)3 PythonFolder (org.python.pydev.navigator.elements.PythonFolder)2 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 ContributorTrackingSet (org.eclipse.ui.internal.navigator.ContributorTrackingSet)1 INavigatorPipelineService (org.eclipse.ui.navigator.INavigatorPipelineService)1 PythonProjectSourceFolder (org.python.pydev.navigator.elements.PythonProjectSourceFolder)1 FileStub (org.python.pydev.shared_core.resource_stubs.FileStub)1