Changeset 3507 for devel-tools
- Timestamp:
- Mar 13, 2008, 5:13:04 PM (13 years ago)
- Location:
- devel-tools/trunk/eclipse/org.refal.plus.rfpdt.ui/src/org/refal/plus/rfpdt/ui/wizards
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.ui/src/org/refal/plus/rfpdt/ui/wizards/ProjectCreationWizard.java
r3491 r3507 27 27 private IConfigurationElement configElement; 28 28 29 private ProjectCreationOperation fOperation;29 private RfpProjectCreationOperation fOperation; 30 30 31 public ProjectCreationWizard( ProjectCreationOperation operation) {31 public ProjectCreationWizard(RfpProjectCreationOperation operation) { 32 32 super(); 33 33 fOperation = operation; -
devel-tools/trunk/eclipse/org.refal.plus.rfpdt.ui/src/org/refal/plus/rfpdt/ui/wizards/RfpProjectCreationOperation.java
r3503 r3507 3 3 import java.lang.reflect.InvocationTargetException; 4 4 5 import org.eclipse.core.resources.IFolder;6 5 import org.eclipse.core.resources.IProject; 7 6 import org.eclipse.core.resources.IProjectDescription; … … 15 14 import org.eclipse.core.runtime.Platform; 16 15 import org.eclipse.core.runtime.SubProgressMonitor; 16 import org.eclipse.jdt.core.JavaCore; 17 17 import org.eclipse.jface.operation.IRunnableWithProgress; 18 18 import org.refal.plus.rfpdt.core.RfpCorePlugin; 19 import org.refal.plus.rfpdt.core.RfpNature; 19 20 20 public abstract classProjectCreationOperation implements IRunnableWithProgress {21 public class RfpProjectCreationOperation implements IRunnableWithProgress { 21 22 22 23 23 private String _projectName; 24 private String _location; 24 25 25 public void run(final IProgressMonitor passedMon) 26 throws InvocationTargetException, InterruptedException { 27 IProgressMonitor mon = (passedMon == null) ? new NullProgressMonitor() 28 : passedMon; 29 IWorkspaceRunnable operation = new IWorkspaceRunnable() { 30 public void run(final IProgressMonitor monitor) 31 throws CoreException { 32 monitor.beginTask("Creating project ...", 33 getDirectories().length + 3); 26 public void run (final IProgressMonitor passedMon) throws InvocationTargetException, InterruptedException { 27 IProgressMonitor mon = (passedMon == null) ? new NullProgressMonitor() : passedMon; 28 IWorkspaceRunnable operation = new IWorkspaceRunnable() { 29 public void run (final IProgressMonitor monitor) throws CoreException { 30 monitor.beginTask("Creating project ...", 3); 31 monitor.subTask("Inializing resources ..."); 32 IProject project = createProjectResource(); 33 monitor.worked(1); 34 monitor.subTask("Adding natures ..."); 35 addNatures(monitor, project); 36 } 37 }; 38 try { 39 ResourcesPlugin.getWorkspace().run(operation, mon); 40 } catch (CoreException e) { 41 RfpCorePlugin.log("Problem creating new project.", e); 42 } finally { 43 mon.done(); 44 } 45 } 34 46 35 monitor.subTask("Inializing resources ..."); 36 IProject project = createProjectResource();37 monitor.worked(1); 47 public void setProjectName (String name) { 48 _projectName = name; 49 } 38 50 39 monitor.subTask("Adding natures ..."); 40 addNatures(monitor, project); 51 public String getProjectName () { 52 return _projectName; 53 } 41 54 42 monitor.subTask("Creating directory structure ..."); 43 createDirectories(monitor, project); 44 } 45 }; 46 try { 47 ResourcesPlugin.getWorkspace().run(operation, mon); 48 } catch (CoreException e) { 49 RfpCorePlugin.log("Problem creating new project.", e); 50 } finally { 51 mon.done(); 52 } 53 } 55 public void setProjectLocation (String location) { 56 _location = location; 57 } 54 58 55 public void setProjectName(String name) {56 _projectName = name;57 59 public String getProjectLocation () { 60 return _location; 61 } 58 62 59 public String getProjectName() { 60 return _projectName; 61 } 63 // helping methods 64 // //////////////// 62 65 63 public void setProjectLocation(String location) { 64 _location = location; 65 } 66 private IProject createProjectResource () throws CoreException { 67 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); 68 final String projectName = getProjectName(); 69 final String projectLocation = getProjectLocation(); 66 70 67 public String getProjectLocation() { 68 return _location; 69 } 71 IProject result = root.getProject(projectName); 72 IProjectDescription desc = null; 70 73 71 // helping methods 72 // //////////////// 74 if (isDefaultLocation(projectLocation)) { 75 desc = null; 76 } else { 77 desc = result.getWorkspace().newProjectDescription(projectName); 78 desc.setLocation(new Path(projectLocation)); 79 } 73 80 74 private IProject createProjectResource() throws CoreException { 75 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); 76 final String projectName = getProjectName(); 77 final String projectLocation = getProjectLocation(); 81 if (!result.exists()) { 82 result.create(desc, null); 83 } 84 if (!result.isOpen()) { 85 result.open(null); 86 } 87 return result; 88 } 78 89 79 IProject result = root.getProject(projectName); 80 IProjectDescription desc = null; 90 private boolean isDefaultLocation (final String projectLocation) { 91 return null == projectLocation || "".equals(projectLocation) 92 || Platform.getLocation().toString().equals(projectLocation); 93 } 81 94 82 if (isDefaultLocation(projectLocation)){83 desc = null;84 } else { 85 desc = result.getWorkspace().newProjectDescription(projectName);86 desc.setLocation(new Path(projectLocation));87 95 private void addNatures (final IProgressMonitor mon, final IProject project) throws CoreException { 96 IProjectDescription desc = project.getDescription(); 97 desc.setNatureIds(getProjectNatures()); 98 mon.worked(1); 99 project.setDescription(desc, new SubProgressMonitor(mon, 1)); 100 } 88 101 89 if (!result.exists()) { 90 result.create(desc, null); 91 } 92 if (!result.isOpen()) { 93 result.open(null); 94 } 95 return result; 96 } 97 98 private boolean isDefaultLocation(final String projectLocation) { 99 return null == projectLocation || "".equals(projectLocation) 100 || Platform.getLocation().toString().equals(projectLocation); 101 } 102 103 private void addNatures(final IProgressMonitor mon, final IProject project) 104 throws CoreException { 105 IProjectDescription desc = project.getDescription(); 106 desc.setNatureIds(getProjectNatures()); 107 project.setDescription(desc, new SubProgressMonitor(mon, 1)); 108 } 109 110 /** 111 * Returns an array of project nature ids to be added to the created 112 * project. 113 */ 114 protected abstract String[] getProjectNatures(); 115 116 /** 117 * Returns an array of directory names to be created inside the project. 118 */ 119 protected abstract String[] getDirectories(); 120 121 private void createDirectories(final IProgressMonitor mon, 122 final IProject proj) throws CoreException { 123 String[] directories = getDirectories(); 124 for (int i = 0; i < directories.length; i++) { 125 if (!directories[i].equals("")) { 126 IFolder dir = proj.getFolder(directories[i]); 127 dir.create(true, true, new SubProgressMonitor(mon, 1)); 128 } 129 } 130 } 102 /** 103 * Returns an array of project nature ids to be added to the created project. 104 */ 105 private String[] getProjectNatures () { 106 return new String[] { RfpNature.NATURE_ID, JavaCore.NATURE_ID }; 107 } 131 108 }
Note: See TracChangeset
for help on using the changeset viewer.