Search in sources :

Example 16 with PythonSourceFolder

use of org.python.pydev.navigator.elements.PythonSourceFolder in project Pydev by fabioz.

the class PythonModelProvider method doWrapPossibleSourceFolder.

/**
 * Try to wrap a folder or project as a source folder...
 * @param natureToSourcePathSet
 */
private PythonSourceFolder doWrapPossibleSourceFolder(Object parent, IContainer container, Map<PythonNature, Set<String>> natureToSourcePathSet) {
    IProject project;
    if (!(container instanceof IProject)) {
        project = ((IContainer) parent).getProject();
    } else {
        project = (IProject) container;
    }
    PythonNature nature = PythonNature.getPythonNature(project);
    if (nature != null) {
        // check for source folder
        Set<String> sourcePathSet = this.getSourcePathSet(natureToSourcePathSet, nature);
        PythonSourceFolder newSourceFolder = tryWrapSourceFolder(parent, container, sourcePathSet);
        if (newSourceFolder != null) {
            return newSourceFolder;
        }
    }
    return null;
}
Also used : PythonNature(org.python.pydev.plugin.nature.PythonNature) IProject(org.eclipse.core.resources.IProject) PythonSourceFolder(org.python.pydev.navigator.elements.PythonSourceFolder)

Example 17 with PythonSourceFolder

use of org.python.pydev.navigator.elements.PythonSourceFolder in project Pydev by fabioz.

the class PythonModelProvider method tryWrapSourceFolder.

/**
 * This method checks if the given folder can be wrapped as a source-folder, and if that's possible, creates and returns
 * it
 * @return a created source folder or null if it couldn't be created.
 */
private PythonSourceFolder tryWrapSourceFolder(Object parent, IContainer container, Set<String> sourcePathSet) {
    IPath fullPath = container.getFullPath();
    if (sourcePathSet.contains(fullPath.toString())) {
        PythonSourceFolder sourceFolder;
        if (container instanceof IFolder) {
            sourceFolder = new PythonSourceFolder(parent, (IFolder) container);
        } else if (container instanceof IProject) {
            sourceFolder = new PythonProjectSourceFolder(parent, (IProject) container);
        } else {
            // some other container we don't know how to treat!
            return null;
        }
        // System.out.println("Created source folder: "+ret[i]+" - "+folder.getProject()+" - "+folder.getProjectRelativePath());
        Set<PythonSourceFolder> sourceFolders = getProjectSourceFolders(container.getProject());
        sourceFolders.add(sourceFolder);
        return sourceFolder;
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) PythonProjectSourceFolder(org.python.pydev.navigator.elements.PythonProjectSourceFolder) PythonSourceFolder(org.python.pydev.navigator.elements.PythonSourceFolder) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

PythonSourceFolder (org.python.pydev.navigator.elements.PythonSourceFolder)17 PythonNature (org.python.pydev.plugin.nature.PythonNature)10 HashSet (java.util.HashSet)9 IProject (org.eclipse.core.resources.IProject)8 IFolder (org.eclipse.core.resources.IFolder)6 IWorkingSet (org.eclipse.ui.IWorkingSet)6 IWrappedResource (org.python.pydev.navigator.elements.IWrappedResource)6 File (java.io.File)5 Set (java.util.Set)5 IContainer (org.eclipse.core.resources.IContainer)5 IResource (org.eclipse.core.resources.IResource)5 PythonFolder (org.python.pydev.navigator.elements.PythonFolder)5 IFile (org.eclipse.core.resources.IFile)4 PythonProjectSourceFolder (org.python.pydev.navigator.elements.PythonProjectSourceFolder)4 IPath (org.eclipse.core.runtime.IPath)3 PipelinedShapeModification (org.eclipse.ui.navigator.PipelinedShapeModification)3 FolderStub (org.python.pydev.shared_core.resource_stubs.FolderStub)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IPythonNature (org.python.pydev.core.IPythonNature)2