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 INewWizard, IExecutableExtension {
27 protected WizardNewProjectCreationPage projectPage;
28 protected IConfigurationElement configurationElement;
29 protected IProject newProject;
31 public NewProjectCreationWizard() {
32 setWindowTitle(PHPWizardMessages.getString("NewProjectCreationWizard.windowTitle"));
35 public boolean performFinish() {
36 IRunnableWithProgress projectCreationOperation = new WorkspaceModifyDelegatingOperation(getProjectCreationRunnable());
39 getContainer().run(false, true, projectCreationOperation);
40 } catch (Exception e) {
41 PHPeclipsePlugin.log(e);
45 BasicNewProjectResourceWizard.updatePerspective(configurationElement);
46 selectAndReveal(newProject);
47 // open the PHP perspective
48 new OpenPHPPerspectiveAction().run();
52 protected IRunnableWithProgress getProjectCreationRunnable() {
53 return new IRunnableWithProgress() {
54 public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
55 int remainingWorkUnits = 10;
56 monitor.beginTask(PHPWizardMessages.getString("NewProjectCreationWizard.projectCreationMessage"), remainingWorkUnits);
58 IWorkspace workspace = PHPeclipsePlugin.getWorkspace();
59 newProject = projectPage.getProjectHandle();
61 IProjectDescription description = workspace.newProjectDescription(newProject.getName());
62 IPath path = Platform.getLocation();
63 IPath customPath = projectPage.getLocationPath();
64 if (!path.equals(customPath)) {
66 description.setLocation(path);
70 if (!newProject.exists()) {
71 newProject.create(description, new SubProgressMonitor(monitor, 1));
74 if (!newProject.isOpen()) {
75 newProject.open(new SubProgressMonitor(monitor, 1));
78 JavaCore.addPHPNature(newProject, new SubProgressMonitor(monitor, remainingWorkUnits));
79 } catch (CoreException e) {
80 throw new InvocationTargetException(e);
88 public void addPages() {
91 projectPage = new WizardNewProjectCreationPage(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageName"));
92 projectPage.setTitle(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageTitle"));
93 projectPage.setDescription(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageDescription"));
98 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
99 configurationElement = config;