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