Fix for bug #1839622 RSE Path error. You can now create a PHP Project and use RSE...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / wizards / NewProjectCreationWizard.java
1 package net.sourceforge.phpeclipse.wizards;
2
3 import java.lang.reflect.InvocationTargetException;
4 import java.net.URI;
5
6 import net.sourceforge.phpdt.core.JavaCore;
7 import net.sourceforge.phpdt.ui.actions.OpenPHPPerspectiveAction;
8 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
9
10 import org.eclipse.core.resources.IProject;
11 import org.eclipse.core.resources.IProjectDescription;
12 import org.eclipse.core.resources.IWorkspace;
13 import org.eclipse.core.resources.ResourcesPlugin;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IConfigurationElement;
16 import org.eclipse.core.runtime.IExecutableExtension;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.SubProgressMonitor;
19 import org.eclipse.jface.operation.IRunnableWithProgress;
20 import org.eclipse.ui.INewWizard;
21 import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
22 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
23 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
24 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
25
26 public class NewProjectCreationWizard extends BasicNewResourceWizard implements
27                 INewWizard, IExecutableExtension {
28         protected WizardNewProjectCreationPage projectPage;
29
30         protected IConfigurationElement configurationElement;
31
32         protected IProject newProject;
33
34         public NewProjectCreationWizard() {
35                 setWindowTitle(PHPWizardMessages
36                                 .getString("NewProjectCreationWizard.windowTitle"));
37         }
38
39         public boolean performFinish() {
40                 IRunnableWithProgress projectCreationOperation = new WorkspaceModifyDelegatingOperation(
41                                 getProjectCreationRunnable());
42
43                 try {
44                         getContainer().run(false, true, projectCreationOperation);
45                 } catch (Exception e) {
46                         PHPeclipsePlugin.log(e);
47                         return false;
48                 }
49
50                 BasicNewProjectResourceWizard.updatePerspective(configurationElement);
51                 selectAndReveal(newProject);
52                 // open the PHP perspective
53                 new OpenPHPPerspectiveAction().run();
54                 return true;
55         }
56
57         protected IRunnableWithProgress getProjectCreationRunnable() {
58                 return new IRunnableWithProgress() {
59                         public void run(IProgressMonitor monitor)
60                                         throws InvocationTargetException, InterruptedException {
61                                 int remainingWorkUnits = 10;
62                                 monitor
63                                                 .beginTask(
64                                                                 PHPWizardMessages
65                                                                                 .getString("NewProjectCreationWizard.projectCreationMessage"),
66                                                                 remainingWorkUnits);
67
68                                 IWorkspace workspace = PHPeclipsePlugin.getWorkspace();
69                                 String projectName = projectPage.getProjectHandle().getName();
70                                 newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
71                                 IProjectDescription description = workspace
72                                                 .newProjectDescription(projectName);
73                                 
74                                 URI uriPath = (!projectPage.useDefaults()) ? projectPage
75                                 .getLocationURI() : null;
76                                 if (uriPath != null) {                              
77                                         description.setLocationURI(uriPath);
78                                 }
79
80                                 try {
81                                         if (!newProject.exists()) {
82                                                 newProject.create(description, new SubProgressMonitor(
83                                                                 monitor, 1));
84                                                 remainingWorkUnits--;
85                                         }
86                                         if (!newProject.isOpen()) {
87                                                 newProject.open(new SubProgressMonitor(monitor, 1));
88                                                 remainingWorkUnits--;
89                                         }
90                                         JavaCore.addPHPNature(newProject, new SubProgressMonitor(
91                                                         monitor, remainingWorkUnits));
92
93                                 } catch (CoreException e) {
94                                     System.out.println(e);
95                                         throw new InvocationTargetException(e);
96                                 } finally {
97                                         monitor.done();
98                                 }
99                         }
100                 };
101         }
102
103         public void addPages() {
104                 super.addPages();
105
106                 projectPage = new WizardNewProjectCreationPage(PHPWizardMessages
107                                 .getString("WizardNewProjectCreationPage.pageName"));
108                 projectPage.setTitle(PHPWizardMessages
109                                 .getString("WizardNewProjectCreationPage.pageTitle"));
110                 projectPage.setDescription(PHPWizardMessages
111                                 .getString("WizardNewProjectCreationPage.pageDescription"));
112
113                 addPage(projectPage);
114         }
115
116         public void setInitializationData(IConfigurationElement config,
117                         String propertyName, Object data) throws CoreException {
118                 configurationElement = config;
119         }
120
121 }