Removed some internal constants
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / wizards / NewProjectCreationWizard.java
1 package net.sourceforge.phpeclipse.wiki.wizards;
2
3 import java.lang.reflect.InvocationTargetException;
4
5 import net.sourceforge.phpeclipse.wiki.builder.AddBuilderAction;
6 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
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
27   protected IConfigurationElement configurationElement;
28
29   protected IProject newProject;
30
31   public NewProjectCreationWizard() {
32     setWindowTitle(WizardMessages.getString("NewProjectCreationWizard.windowTitle"));
33   }
34
35   public boolean performFinish() {
36     IRunnableWithProgress projectCreationOperation = new WorkspaceModifyDelegatingOperation(getProjectCreationRunnable());
37
38     try {
39       getContainer().run(false, true, projectCreationOperation);
40     } catch (Exception e) {
41       WikiEditorPlugin.log(e);
42       return false;
43     }
44
45     BasicNewProjectResourceWizard.updatePerspective(configurationElement);
46     selectAndReveal(newProject);
47
48     return true;
49   }
50
51   protected IRunnableWithProgress getProjectCreationRunnable() {
52     return new IRunnableWithProgress() {
53       public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
54         int remainingWorkUnits = 10;
55         monitor.beginTask(WizardMessages.getString("NewProjectCreationWizard.projectCreationMessage"), remainingWorkUnits);
56
57         IWorkspace workspace = WikiEditorPlugin.getWorkspace();
58         newProject = projectPage.getProjectHandle();
59
60         IProjectDescription description = workspace.newProjectDescription(newProject.getName());
61         IPath path = Platform.getLocation();
62         IPath customPath = projectPage.getLocationPath();
63         if (!path.equals(customPath)) {
64           path = customPath;
65           description.setLocation(path);
66         }
67
68         try {
69           if (!newProject.exists()) {
70             newProject.create(description, new SubProgressMonitor(monitor, 1));
71             remainingWorkUnits--;
72           }
73           if (!newProject.isOpen()) {
74             newProject.open(new SubProgressMonitor(monitor, 1));
75             remainingWorkUnits--;
76           }
77 //          addWikipediaNature(newProject, new SubProgressMonitor(monitor, remainingWorkUnits));
78           AddBuilderAction.addBuilder(newProject);
79         }
80         catch (CoreException e) {
81           throw new InvocationTargetException(e);
82         } finally {
83           monitor.done();
84         }
85       }
86     };
87   }
88
89 //  public static void addWikipediaNature(IProject project, IProgressMonitor monitor) throws CoreException {
90 //    if (!project.hasNature(WikiEditorPlugin.NATURE_ID)) {
91 //      IProjectDescription description = project.getDescription();
92 //      String[] prevNatures = description.getNatureIds();
93 //      String[] newNatures = new String[prevNatures.length + 1];
94 //      System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
95 //      newNatures[prevNatures.length] = WikiEditorPlugin.NATURE_ID;
96 //      description.setNatureIds(newNatures);
97 //      project.setDescription(description, monitor);
98 //    }
99 //  }
100
101   public void addPages() {
102     super.addPages();
103
104     projectPage = new WizardNewProjectCreationPage(WizardMessages.getString("WizardNewProjectCreationPage.pageName"));
105     projectPage.setTitle(WizardMessages.getString("WizardNewProjectCreationPage.pageTitle"));
106     projectPage.setDescription(WizardMessages.getString("WizardNewProjectCreationPage.pageDescription"));
107
108     addPage(projectPage);
109   }
110
111   public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
112     configurationElement = config;
113   }
114
115 }