1 | package de.uka.ipd.sdq.pcmbench.wizards; |
2 | |
3 | import org.eclipse.core.resources.IProject; |
4 | import org.eclipse.core.resources.IProjectDescription; |
5 | import org.eclipse.core.resources.IWorkspace; |
6 | import org.eclipse.core.resources.ResourcesPlugin; |
7 | import org.eclipse.core.runtime.CoreException; |
8 | import org.eclipse.core.runtime.IStatus; |
9 | import org.eclipse.jface.dialogs.IMessageProvider; |
10 | import org.eclipse.jface.viewers.IStructuredSelection; |
11 | import org.eclipse.jface.wizard.Wizard; |
12 | import org.eclipse.ui.INewWizard; |
13 | import org.eclipse.ui.IWorkbench; |
14 | import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; |
15 | |
16 | import de.uka.ipd.sdq.pcmbench.PCMBenchActivator; |
17 | |
18 | /** |
19 | * @author steffen, johann |
20 | * |
21 | */ |
22 | public class RepositoryProjectWizard extends Wizard implements INewWizard { |
23 | |
24 | private IWorkbench workbench; |
25 | private IStructuredSelection selection; |
26 | private WizardNewProjectCreationPage page; |
27 | private IWorkspace workspace; |
28 | /** |
29 | * |
30 | */ |
31 | public RepositoryProjectWizard() { |
32 | workspace = ResourcesPlugin.getWorkspace(); |
33 | } |
34 | |
35 | @Override |
36 | public boolean performFinish() { |
37 | IProject newProject = workspace.getRoot().getProject(page.getProjectName()); |
38 | try { |
39 | if (!newProject.exists()) |
40 | newProject.create(null); |
41 | newProject.open(null); |
42 | IProjectDescription description = newProject.getDescription(); |
43 | String[] natures = description.getNatureIds(); |
44 | String[] newNatures = new String[natures.length + 1]; |
45 | System.arraycopy(natures, 0, newNatures, 0, natures.length); |
46 | newNatures[natures.length] = "de.uka.ipd.sdq.pcmbench.nature"; |
47 | IStatus status = workspace.validateNatureSet(natures); |
48 | |
49 | // check the status and decide what to do |
50 | if (status.getCode() == IStatus.OK) { |
51 | description.setNatureIds(newNatures); |
52 | newProject.setDescription(description, null); |
53 | } else { |
54 | // raise a user error |
55 | } |
56 | } catch (CoreException e) { |
57 | // TODO Auto-generated catch block |
58 | e.printStackTrace(); |
59 | return false; |
60 | } |
61 | return true; |
62 | } |
63 | |
64 | public void init(IWorkbench workbench, IStructuredSelection selection) { |
65 | this.workbench = workbench; |
66 | this.selection = selection; |
67 | } |
68 | |
69 | /* (non-Javadoc) |
70 | * @see org.eclipse.jface.wizard.Wizard#addPages() |
71 | */ |
72 | @Override |
73 | public void addPages() { |
74 | page = new WizardNewProjectCreationPage("Create New Palladio Component Repository Project"); |
75 | page.setDescription("Create a new Palladio Component Repository Modelling Project. "+ |
76 | "This type of project is used to specify component repositories."); |
77 | page.setMessage(page.getDescription(),IMessageProvider.INFORMATION); |
78 | page.setImageDescriptor(PCMBenchActivator.imageDescriptorFromPlugin( |
79 | PCMBenchActivator.PLUGIN_ID, |
80 | "icons/palladio-logo.gif")); |
81 | page.setTitle("Create a PCM Component Repository Modelling Project"); |
82 | this.addPage(page); |
83 | } |
84 | |
85 | } |