~vil/pydev/upstream

« back to all changes in this revision

Viewing changes to org.python.pydev/src/org/python/pydev/ui/wizards/files/PythonSourceFolderWizard.java

  • Committer: Vladimír Lapáček
  • Date: 2006-08-30 18:38:44 UTC
  • Revision ID: vladimir.lapacek@gmail.com-20060830183844-f4d82c1239a7770a
Initial import of upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Created on Jan 22, 2006
 
3
 */
 
4
package org.python.pydev.ui.wizards.files;
 
5
 
 
6
import org.eclipse.core.resources.IFile;
 
7
import org.eclipse.core.resources.IFolder;
 
8
import org.eclipse.core.resources.IProject;
 
9
import org.eclipse.core.runtime.CoreException;
 
10
import org.eclipse.core.runtime.IProgressMonitor;
 
11
import org.python.pydev.core.IPythonNature;
 
12
import org.python.pydev.core.IPythonPathNature;
 
13
import org.python.pydev.plugin.nature.PythonNature;
 
14
 
 
15
public class PythonSourceFolderWizard extends AbstractPythonWizard {
 
16
 
 
17
    public static final String WIZARD_ID = "org.python.pydev.ui.wizards.files.PythonSourceFolderWizard";
 
18
 
 
19
    @Override
 
20
    protected PythonAbstractPathPage createPathPage() {
 
21
        return new PythonAbstractPathPage("Create a new Source Folder", selection){
 
22
 
 
23
            @Override
 
24
            protected boolean shouldCreateSourceFolderSelect() {
 
25
                return false;
 
26
            }
 
27
            
 
28
            @Override
 
29
            protected boolean shouldCreatePackageSelect() {
 
30
                return false;
 
31
            }
 
32
            
 
33
        };
 
34
    }
 
35
 
 
36
    @Override
 
37
    protected IFile doCreateNew(IProgressMonitor monitor) throws CoreException {
 
38
        IProject project = filePage.getValidatedProject();
 
39
        String name = filePage.getValidatedName();
 
40
        if(project == null || !project.exists()){
 
41
            throw new RuntimeException("The project selected does not exist in the workspace.");
 
42
        }
 
43
        IPythonPathNature pathNature = PythonNature.getPythonPathNature(project);
 
44
        if(pathNature == null){
 
45
            IPythonNature nature = PythonNature.addNature(project, monitor);
 
46
            pathNature = nature.getPythonPathNature();
 
47
            if(pathNature == null){
 
48
                throw new RuntimeException("Unable to add the nature to the seleted project.");
 
49
            }
 
50
        }
 
51
        IFolder folder = project.getFolder(name);
 
52
        if(!folder.exists()){
 
53
            folder.create(true, true, monitor);
 
54
        }
 
55
        String newPath = folder.getFullPath().toString();
 
56
        
 
57
        String curr = pathNature.getProjectSourcePath();
 
58
        if(curr == null){
 
59
            curr = "";
 
60
        }
 
61
        if(curr.endsWith("|")){
 
62
            curr = curr.substring(0, curr.length()-1);
 
63
        }
 
64
        if(curr.length() > 0){
 
65
            //there is already some path
 
66
            curr+="|"+newPath;
 
67
        }else{
 
68
            //there is still no other path
 
69
            curr=newPath;
 
70
        }
 
71
        pathNature.setProjectSourcePath(curr);
 
72
        PythonNature.getPythonNature(project).rebuildPath();
 
73
        return null;
 
74
    }
 
75
 
 
76
 
 
77
}