1 package net.sourceforge.phpeclipse.wizards;
3 import java.lang.reflect.InvocationTargetException;
6 import net.sourceforge.phpdt.core.JavaCore;
7 import net.sourceforge.phpdt.ui.actions.OpenPHPPerspectiveAction;
8 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
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;
26 public class NewProjectCreationWizard extends BasicNewResourceWizard implements
27 INewWizard, IExecutableExtension {
28 protected WizardNewProjectCreationPage projectPage;
30 protected IConfigurationElement configurationElement;
32 protected IProject newProject;
34 public NewProjectCreationWizard() {
35 setWindowTitle(PHPWizardMessages
36 .getString("NewProjectCreationWizard.windowTitle"));
39 public boolean performFinish() {
40 IRunnableWithProgress projectCreationOperation = new WorkspaceModifyDelegatingOperation(
41 getProjectCreationRunnable());
44 getContainer().run(false, true, projectCreationOperation);
45 } catch (Exception e) {
46 PHPeclipsePlugin.log(e);
50 BasicNewProjectResourceWizard.updatePerspective(configurationElement);
51 selectAndReveal(newProject);
52 // open the PHP perspective
53 new OpenPHPPerspectiveAction().run();
57 protected IRunnableWithProgress getProjectCreationRunnable() {
58 return new IRunnableWithProgress() {
59 public void run(IProgressMonitor monitor)
60 throws InvocationTargetException, InterruptedException {
61 int remainingWorkUnits = 10;
65 .getString("NewProjectCreationWizard.projectCreationMessage"),
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);
74 URI uriPath = (!projectPage.useDefaults()) ? projectPage
75 .getLocationURI() : null;
76 if (uriPath != null) {
77 description.setLocationURI(uriPath);
81 if (!newProject.exists()) {
82 newProject.create(description, new SubProgressMonitor(
86 if (!newProject.isOpen()) {
87 newProject.open(new SubProgressMonitor(monitor, 1));
90 JavaCore.addPHPNature(newProject, new SubProgressMonitor(
91 monitor, remainingWorkUnits));
93 } catch (CoreException e) {
94 System.out.println(e);
95 throw new InvocationTargetException(e);
103 public void addPages() {
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"));
113 addPage(projectPage);
116 public void setInitializationData(IConfigurationElement config,
117 String propertyName, Object data) throws CoreException {
118 configurationElement = config;