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