1 package net.sourceforge.phpeclipse.wiki.wizards;
3 import java.lang.reflect.InvocationTargetException;
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;
24 public class NewProjectCreationWizard extends BasicNewResourceWizard implements INewWizard, IExecutableExtension {
25 protected WizardNewProjectCreationPage projectPage;
27 protected IConfigurationElement configurationElement;
29 protected IProject newProject;
31 public NewProjectCreationWizard() {
32 setWindowTitle(WizardMessages.getString("NewProjectCreationWizard.windowTitle"));
35 public boolean performFinish() {
36 IRunnableWithProgress projectCreationOperation = new WorkspaceModifyDelegatingOperation(getProjectCreationRunnable());
39 getContainer().run(false, true, projectCreationOperation);
40 } catch (Exception e) {
41 WikiEditorPlugin.log(e);
45 BasicNewProjectResourceWizard.updatePerspective(configurationElement);
46 selectAndReveal(newProject);
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);
57 IWorkspace workspace = WikiEditorPlugin.getWorkspace();
58 newProject = projectPage.getProjectHandle();
60 IProjectDescription description = workspace.newProjectDescription(newProject.getName());
61 IPath path = Platform.getLocation();
62 IPath customPath = projectPage.getLocationPath();
63 if (!path.equals(customPath)) {
65 description.setLocation(path);
69 if (!newProject.exists()) {
70 newProject.create(description, new SubProgressMonitor(monitor, 1));
73 if (!newProject.isOpen()) {
74 newProject.open(new SubProgressMonitor(monitor, 1));
77 // addWikipediaNature(newProject, new SubProgressMonitor(monitor, remainingWorkUnits));
78 AddBuilderAction.addBuilder(newProject);
80 catch (CoreException e) {
81 throw new InvocationTargetException(e);
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);
101 public void addPages() {
104 projectPage = new WizardNewProjectCreationPage(WizardMessages.getString("WizardNewProjectCreationPage.pageName"));
105 projectPage.setTitle(WizardMessages.getString("WizardNewProjectCreationPage.pageTitle"));
106 projectPage.setDescription(WizardMessages.getString("WizardNewProjectCreationPage.pageDescription"));
108 addPage(projectPage);
111 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
112 configurationElement = config;