source: trunk/org.modelica.mdt/src/org/modelica/mdt/NewProjectWizard.java @ 36

Last change on this file since 36 was 35, checked in by boris, 19 years ago
  • added some error handling
File size: 2.8 KB
Line 
1package org.modelica.mdt;
2
3import java.lang.reflect.InvocationTargetException;
4import org.eclipse.core.resources.IProject;
5import org.eclipse.core.runtime.CoreException;
6import org.eclipse.core.runtime.IProgressMonitor;
7import org.eclipse.core.runtime.IStatus;
8import org.eclipse.core.runtime.Status;
9import org.eclipse.jface.dialogs.ErrorDialog;
10import org.eclipse.jface.operation.IRunnableWithProgress;
11import org.eclipse.jface.viewers.IStructuredSelection;
12import org.eclipse.ui.IWorkbench;
13import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
14import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
15
16public class NewProjectWizard extends BasicNewResourceWizard
17{
18    public class CreateNewProjectRunnable implements IRunnableWithProgress
19    {
20        IProject newProject;
21       
22        public CreateNewProjectRunnable(IProject newProject)
23        {
24            this.newProject = newProject;
25        }
26
27        public void run(IProgressMonitor monitor)
28                throws InvocationTargetException, InterruptedException
29        {
30            monitor.beginTask("creating project " + newProject.getName(), 3);
31            try
32            {
33                /* create the project */
34                newProject.create(monitor);
35                monitor.worked(1);
36
37                /* open project */
38                newProject.open(monitor);
39                monitor.worked(2);
40
41                /* add modelica nature to the project */
42                MdtPlugin.addModelicaNature(newProject);
43               
44            }
45            catch (CoreException e)
46            {
47                showProjectCreationError(e.getStatus());
48            }           
49            monitor.done();
50        }
51
52    }
53    protected WizardNewProjectCreationPage projectPage;
54
55    public void init(IWorkbench workbench,IStructuredSelection selection)
56    {
57        super.init(workbench, selection);
58        setNeedsProgressMonitor(true);
59        setWindowTitle("New Modelica Project");
60       
61    }
62   
63
64    public void showProjectCreationError(String message, Exception e)
65    {
66        showProjectCreationError(new Status(IStatus.ERROR, 
67                MdtPlugin.getSymbolicName(), 0, message, e));
68    }
69   
70   
71    public void showProjectCreationError(IStatus status)
72    {
73        ErrorDialog.openError(null, "Error", "Could not create project", status);   
74    }
75
76    @Override
77    public boolean performFinish()
78    {
79        try 
80        {
81            IProject project = projectPage.getProjectHandle();
82            getContainer().run(false, true, 
83                    new CreateNewProjectRunnable(project));
84
85            selectAndReveal(project);
86        } 
87        catch (InvocationTargetException e)
88        {
89            showProjectCreationError("internal error during project creation", e);
90        }
91        catch (InterruptedException e)
92        {
93            return false;
94        }
95        return true;
96    }
97    public void addPages()
98    {
99        super.addPages();
100       
101        projectPage = new WizardNewProjectCreationPage("");
102        projectPage.setTitle("Create a Modelica project");
103        projectPage.setDescription("Create a Modelica project in the workspace" +
104                " or in an external location.");
105
106        addPage(projectPage);
107       
108     }
109
110}
Note: See TracBrowser for help on using the repository browser.