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.IResource;
13 import org.eclipse.core.resources.IWorkspace;
14 import org.eclipse.core.resources.ResourcesPlugin;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.core.runtime.IExecutableExtension;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.SubProgressMonitor;
20 import org.eclipse.jface.operation.IRunnableWithProgress;
21 import org.eclipse.ui.INewWizard;
22 import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
23 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
24 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
25 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
27 public class NewProjectCreationWizard extends BasicNewResourceWizard implements
28 INewWizard, IExecutableExtension {
29 protected WizardNewProjectCreationPage projectPage;
31 protected IConfigurationElement configurationElement;
33 protected IProject newProject;
35 public NewProjectCreationWizard() {
36 setWindowTitle(PHPWizardMessages
37 .getString("NewProjectCreationWizard.windowTitle"));
40 public boolean performFinish() {
41 IRunnableWithProgress projectCreationOperation = new WorkspaceModifyDelegatingOperation(
42 getProjectCreationRunnable());
45 getContainer().run(false, true, projectCreationOperation);
46 } catch (Exception e) {
47 PHPeclipsePlugin.log(e);
51 BasicNewProjectResourceWizard.updatePerspective(configurationElement);
52 selectAndReveal(newProject);
53 // open the PHP perspective
54 new OpenPHPPerspectiveAction().run();
58 protected IRunnableWithProgress getProjectCreationRunnable() {
59 return new IRunnableWithProgress() {
60 public void run(IProgressMonitor monitor)
61 throws InvocationTargetException, InterruptedException {
62 int remainingWorkUnits = 10;
66 .getString("NewProjectCreationWizard.projectCreationMessage"),
69 IWorkspace workspace = PHPeclipsePlugin.getWorkspace();
70 String projectName = projectPage.getProjectHandle().getName();
71 newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
72 IProjectDescription description = workspace
73 .newProjectDescription(projectName);
75 URI uriPath = (!projectPage.useDefaults()) ? projectPage
76 .getLocationURI() : null;
77 if (uriPath != null) {
78 description.setLocationURI(uriPath);
82 if (!newProject.exists()) {
83 newProject.create(description, new SubProgressMonitor(
87 if (!newProject.isOpen()) {
88 newProject.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1));
91 JavaCore.addPHPNature(newProject, new SubProgressMonitor(
92 monitor, remainingWorkUnits));
94 } catch (CoreException e) {
95 System.out.println(e);
96 throw new InvocationTargetException(e);
104 public void addPages() {
107 projectPage = new WizardNewProjectCreationPage(PHPWizardMessages
108 .getString("WizardNewProjectCreationPage.pageName"));
109 projectPage.setTitle(PHPWizardMessages
110 .getString("WizardNewProjectCreationPage.pageTitle"));
111 projectPage.setDescription(PHPWizardMessages
112 .getString("WizardNewProjectCreationPage.pageDescription"));
114 addPage(projectPage);
117 public void setInitializationData(IConfigurationElement config,
118 String propertyName, Object data) throws CoreException {
119 configurationElement = config;