inital plugin from webtools project
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / wizards / TempnewPHPProject.java
1 package net.sourceforge.phpeclipse.wizards;
2
3 import java.lang.reflect.InvocationTargetException;
4
5 import net.sourceforge.phpdt.core.JavaCore;
6 import net.sourceforge.phpdt.internal.ui.util.ExceptionHandler;
7
8 import org.eclipse.core.resources.IProject;
9 import org.eclipse.core.resources.IProjectDescription;
10 import org.eclipse.core.runtime.CoreException;
11 import org.eclipse.core.runtime.IConfigurationElement;
12 import org.eclipse.core.runtime.IPath;
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.core.runtime.NullProgressMonitor;
15 import org.eclipse.core.runtime.Platform;
16 import org.eclipse.swt.widgets.Shell;
17 import org.eclipse.ui.INewWizard;
18 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
19 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
20 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
21
22 public class TempnewPHPProject extends BasicNewResourceWizard implements INewWizard {
23   /*
24    * This class has been added to cvs to provide a project page that works correctly and doesn't freezde while i investigate the
25    * errors completely
26    */
27   private WizardNewProjectCreationPage phpProjPage;
28
29   private IConfigurationElement fConfigElement;
30
31   public TempnewPHPProject() {
32     setNeedsProgressMonitor(true);
33     setWindowTitle("New Project creation"); //$NON-NLS-1$
34
35   }
36
37   public void addPages() {
38     super.addPages();
39     phpProjPage = new WizardNewProjectCreationPage("NewProjectCreationWizard"); //$NON-NLS-1$
40     phpProjPage.setTitle(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageTitle")); //$NON-NLS-1$
41     phpProjPage.setDescription(PHPWizardMessages.getString("WizardNewProjectCreationPage.pageDescription")); //$NON-NLS-1$
42     addPage(phpProjPage);
43   }
44
45   public void setInitializationData(IConfigurationElement cfig, String propertyName, Object data) {
46     fConfigElement = cfig;
47   }
48
49   protected void initializeDefaultPageImageDescriptor() {
50     // not used yet
51   }
52
53   protected void finishPage() throws InterruptedException, CoreException {
54     createProject(phpProjPage.getProjectHandle(), phpProjPage.getLocationPath(), new NullProgressMonitor());
55     BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
56     selectAndReveal(phpProjPage.getProjectHandle());
57   }
58
59   protected void handleFinishException(Shell shell, InvocationTargetException e) {
60     ExceptionHandler.handle(e, getShell(), "Error title", "Error message");
61   }
62
63   public boolean performFinish() {
64     try {
65       finishPage();
66     } catch (InterruptedException e) {
67     } catch (CoreException e) {
68     }
69     return true;
70   }
71
72   public void createProject(IProject project, IPath locationPath, IProgressMonitor monitor) throws CoreException {
73     try {
74       if (!project.exists()) {
75         IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName());
76         if (Platform.getLocation().equals(locationPath)) {
77           locationPath = null;
78         }
79         desc.setLocation(locationPath);
80         project.create(desc, monitor);
81         monitor = null;
82       }
83       if (!project.isOpen()) {
84         project.open(monitor);
85         monitor = null;
86       }
87       JavaCore.addPHPNature(project, new NullProgressMonitor());
88     } finally {
89       if (monitor != null) {
90         monitor.done();
91       }
92     }
93   }
94 }