1 package net.sourceforge.phpeclipse.wizards;
3 import java.lang.reflect.InvocationTargetException;
5 import net.sourceforge.phpdt.core.JavaCore;
6 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
8 import org.eclipse.core.resources.IProject;
9 import org.eclipse.core.resources.IProjectDescription;
10 import org.eclipse.core.resources.IWorkspace;
11 import org.eclipse.core.runtime.CoreException;
12 import org.eclipse.core.runtime.IConfigurationElement;
13 import org.eclipse.core.runtime.IExecutableExtension;
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.Platform;
17 import org.eclipse.core.runtime.SubProgressMonitor;
18 import org.eclipse.jface.operation.IRunnableWithProgress;
19 import org.eclipse.ui.INewWizard;
20 import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
21 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
22 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
23 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
25 public class NewProjectCreationWizard extends BasicNewResourceWizard implements INewWizard, IExecutableExtension {
26 protected WizardNewProjectCreationPage projectPage;
27 protected IConfigurationElement configurationElement;
28 protected IProject newProject;
30 public NewProjectCreationWizard() {
31 setWindowTitle(PHPWizardMessages.getString("NewProjectCreationWizard.windowTitle"));
34 public boolean performFinish() {
35 IRunnableWithProgress projectCreationOperation = new WorkspaceModifyDelegatingOperation(getProjectCreationRunnable());
38 getContainer().run(false, true, projectCreationOperation);
39 } catch (Exception e) {
40 PHPeclipsePlugin.log(e);
44 BasicNewProjectResourceWizard.updatePerspective(configurationElement);
45 selectAndReveal(newProject);
50 protected IRunnableWithProgress getProjectCreationRunnable() {
51 return new IRunnableWithProgress() {
52 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
53 int remainingWorkUnits = 10;
54 monitor.beginTask(PHPWizardMessages.getString("NewProjectCreationWizard.projectCreationMessage"), remainingWorkUnits);
56 IWorkspace workspace = PHPeclipsePlugin.getWorkspace();
57 newProject = projectPage.getProjectHandle();
59 IProjectDescription description = workspace.newProjectDescription(newProject.getName());
60 IPath path = Platform.getLocation();
61 IPath customPath = projectPage.getLocationPath();
62 if (!path.equals(customPath)) {
64 description.setLocation(path);
68 if (!newProject.exists()) {
69 newProject.create(description, new SubProgressMonitor(monitor, 1));
72 if (!newProject.isOpen()) {
73 newProject.open(new SubProgressMonitor(monitor, 1));
76 JavaCore.addPHPNature(newProject, new SubProgressMonitor(monitor, remainingWorkUnits));
77 } catch (CoreException e) {
78 throw new InvocationTargetException(e);
86 public void addPages() {
89 projectPage = new WizardNewProjectCreationPage(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageName"));
90 projectPage.setTitle(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageTitle"));
91 projectPage.setDescription(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageDescription"));
96 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
97 configurationElement = config;