a little bug fixed in the switch labels
[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
5 import net.sourceforge.phpeclipse.PHPCore;
6 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
7
8 import org.eclipse.core.resources.IProject;
9 import org.eclipse.core.resources.IProjectDescription;
10 import org.eclipse.core.resources.IWorkspace;
11 import org.eclipse.core.runtime.CoreException;
12 import org.eclipse.core.runtime.IConfigurationElement;
13 import org.eclipse.core.runtime.IExecutableExtension;
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.Platform;
17 import org.eclipse.core.runtime.SubProgressMonitor;
18 import org.eclipse.jface.operation.IRunnableWithProgress;
19 import org.eclipse.ui.INewWizard;
20 import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
21 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
22 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
23 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
24
25 public class NewProjectCreationWizard extends BasicNewResourceWizard implements INewWizard, IExecutableExtension {
26         protected WizardNewProjectCreationPage projectPage;
27         protected IConfigurationElement configurationElement;
28         protected IProject newProject;
29         
30         public NewProjectCreationWizard() {
31                 setWindowTitle(PHPWizardMessages.getString("NewProjectCreationWizard.windowTitle"));
32         }
33
34         public boolean performFinish() {
35                 IRunnableWithProgress projectCreationOperation = new WorkspaceModifyDelegatingOperation(getProjectCreationRunnable());
36
37                 try {
38                         getContainer().run(false, true, projectCreationOperation);
39                 } catch (Exception e) { 
40                         PHPeclipsePlugin.log(e);
41                         return false;
42                 }
43
44                 BasicNewProjectResourceWizard.updatePerspective(configurationElement);
45                 selectAndReveal(newProject);
46
47                 return true;
48         }
49
50         protected IRunnableWithProgress getProjectCreationRunnable() {
51                 return new IRunnableWithProgress() {
52                         public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
53                                 int remainingWorkUnits = 10;
54                                 monitor.beginTask(PHPWizardMessages.getString("NewProjectCreationWizard.projectCreationMessage"), remainingWorkUnits);
55
56                                 IWorkspace workspace = PHPeclipsePlugin.getWorkspace();
57                                 newProject = projectPage.getProjectHandle();
58                                 
59                                 IProjectDescription description = workspace.newProjectDescription(newProject.getName());
60                                 IPath path = Platform.getLocation();
61                                 IPath customPath = projectPage.getLocationPath();
62                                 if (!path.equals(customPath)) {
63                                         path = customPath;
64                                         description.setLocation(path);
65                                 }
66
67                                 try {
68                                         if (!newProject.exists()) {
69                                                 newProject.create(description, new SubProgressMonitor(monitor, 1));
70                                                 remainingWorkUnits--;
71                                         }
72                                         if (!newProject.isOpen()) {
73                                                 newProject.open(new SubProgressMonitor(monitor, 1));
74                                                 remainingWorkUnits--;
75                                         }
76                                         PHPCore.addPHPNature(newProject, new SubProgressMonitor(monitor, remainingWorkUnits));
77                                 } catch (CoreException e) {
78                                         throw new InvocationTargetException(e);
79                                 } finally {
80                                         monitor.done();
81                                 }
82                         }
83                 };
84         }
85
86         public void addPages() {
87                 super.addPages();
88
89                 projectPage = new WizardNewProjectCreationPage(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageName"));
90                 projectPage.setTitle(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageTitle"));
91                 projectPage.setDescription(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageDescription"));
92
93                 addPage(projectPage);
94         }
95
96         public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
97                 configurationElement = config;
98         }
99
100 }