SQL Plugin copied from Quantum plugin and refactored for PHPEclipse
[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.internal.ui.util.ExceptionHandler;
6 import net.sourceforge.phpeclipse.PHPCore;
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
23 public class TempnewPHPProject extends BasicNewResourceWizard implements INewWizard {
24 /*This class has been added to cvs to provide a project page that
25  * works correctly and doesn't freezde while i investigate the 
26  * errors completely
27  */
28     private WizardNewProjectCreationPage phpProjPage;
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     protected void handleFinishException(Shell shell, InvocationTargetException e) {
59         ExceptionHandler.handle(e, getShell(), "Error title", "Error message");
60     }   
61
62     public boolean performFinish() {
63                 try {
64                         finishPage();
65                 } catch (InterruptedException e) {
66                 } catch (CoreException e) {
67         }      
68         return true;
69     }   
70
71     public void createProject(IProject project, IPath locationPath, IProgressMonitor monitor) throws CoreException {
72         try {
73                         if (!project.exists()) {
74                                 IProjectDescription desc= project.getWorkspace().newProjectDescription(project.getName());
75                                 if (Platform.getLocation().equals(locationPath)) {
76                                         locationPath= null;
77                                 }
78                                 desc.setLocation(locationPath);
79                                 project.create(desc, monitor);
80                                 monitor= null;
81                         }
82                         if (!project.isOpen()) {
83                                 project.open(monitor);
84                                 monitor= null;
85                         }
86                         PHPCore.addPHPNature(project, new NullProgressMonitor());
87                 } finally {
88                         if (monitor != null) {
89                                 monitor.done();
90                         }
91                 }
92         }
93 }