1 package net.sourceforge.phpeclipse.wizards;
3 import java.lang.reflect.InvocationTargetException;
5 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
6 import net.sourceforge.phpeclipse.PHPCore;
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;
26 protected IConfigurationElement configurationElement;
27 protected IProject newProject;
29 public NewProjectCreationWizard() {
30 setWindowTitle(PHPWizardMessages.getString("NewProjectCreationWizard.windowTitle"));
33 public boolean performFinish() {
34 IRunnableWithProgress projectCreationOperation = new WorkspaceModifyDelegatingOperation(getProjectCreationRunnable());
37 getContainer().run(false, true, projectCreationOperation);
38 } catch (Exception e) {
39 PHPeclipsePlugin.log(e);
43 BasicNewProjectResourceWizard.updatePerspective(configurationElement);
44 selectAndReveal(newProject);
49 protected IRunnableWithProgress getProjectCreationRunnable() {
50 return new IRunnableWithProgress() {
51 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
52 int remainingWorkUnits = 10;
53 monitor.beginTask(PHPWizardMessages.getString("NewProjectCreationWizard.projectCreationMessage"), remainingWorkUnits);
55 IWorkspace workspace = PHPeclipsePlugin.getWorkspace();
56 newProject = projectPage.getProjectHandle();
58 IProjectDescription description = workspace.newProjectDescription(newProject.getName());
59 IPath path = Platform.getLocation();
60 IPath customPath = projectPage.getLocationPath();
61 if (!path.equals(customPath)) {
63 description.setLocation(path);
67 if (!newProject.exists()) {
68 newProject.create(description, new SubProgressMonitor(monitor, 1));
71 if (!newProject.isOpen()) {
72 newProject.open(new SubProgressMonitor(monitor, 1));
75 PHPCore.addPHPNature(newProject, new SubProgressMonitor(monitor, remainingWorkUnits));
76 } catch (CoreException e) {
77 throw new InvocationTargetException(e);
85 public void addPages() {
88 projectPage = new WizardNewProjectCreationPage(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageName"));
89 projectPage.setTitle(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageTitle"));
90 projectPage.setDescription(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageDescription"));
95 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
96 configurationElement = config;