1 package net.sourceforge.phpeclipse.wizards;
3 import java.lang.reflect.InvocationTargetException;
5 import net.sourceforge.phpdt.core.JavaCore;
6 import net.sourceforge.phpdt.ui.actions.OpenPHPPerspectiveAction;
7 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
9 import org.eclipse.core.resources.IProject;
10 import org.eclipse.core.resources.IProjectDescription;
11 import org.eclipse.core.resources.IWorkspace;
12 import org.eclipse.core.runtime.CoreException;
13 import org.eclipse.core.runtime.IConfigurationElement;
14 import org.eclipse.core.runtime.IExecutableExtension;
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.Platform;
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 newProject = projectPage.getProjectHandle();
71 IProjectDescription description = workspace
72 .newProjectDescription(newProject.getName());
73 IPath path = Platform.getLocation();
74 IPath customPath = projectPage.getLocationPath();
75 if (!path.equals(customPath)) {
77 description.setLocation(path);
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));
92 } catch (CoreException e) {
93 throw new InvocationTargetException(e);
101 public void addPages() {
104 projectPage = new WizardNewProjectCreationPage(PHPWizardMessages
105 .getString("WizardNewProjectCreationPage.pageName"));
106 projectPage.setTitle(PHPWizardMessages
107 .getString("WizardNewProjectCreationPage.pageTitle"));
108 projectPage.setDescription(PHPWizardMessages
109 .getString("WizardNewProjectCreationPage.pageDescription"));
111 addPage(projectPage);
114 public void setInitializationData(IConfigurationElement config,
115 String propertyName, Object data) throws CoreException {
116 configurationElement = config;