Commit | Line | Data |
---|---|---|
abfad0aa FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views.project.dialogs; | |
14 | ||
15 | import java.net.URI; | |
16 | ||
17 | import org.eclipse.core.resources.IFolder; | |
18 | import org.eclipse.core.resources.IProject; | |
19 | import org.eclipse.core.resources.IProjectDescription; | |
20 | import org.eclipse.core.resources.IWorkspace; | |
21 | import org.eclipse.core.resources.IWorkspaceRoot; | |
22 | import org.eclipse.core.resources.ResourcesPlugin; | |
23 | import org.eclipse.core.runtime.CoreException; | |
24 | import org.eclipse.core.runtime.IConfigurationElement; | |
25 | import org.eclipse.core.runtime.IProgressMonitor; | |
26 | import org.eclipse.core.runtime.NullProgressMonitor; | |
27 | import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin; | |
7995b722 | 28 | import org.eclipse.linuxtools.tmf.ui.internal.Messages; |
abfad0aa FC |
29 | import org.eclipse.linuxtools.tmf.ui.views.project.TmfProjectNature; |
30 | import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfProjectNode; | |
31 | import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; | |
32 | ||
33 | /** | |
34 | * <b><u>NewProjectWizard</u></b> | |
35 | * <p> | |
36 | * TODO: Implement me. Please. | |
37 | */ | |
38 | public class NewProjectWizard extends BasicNewResourceWizard { | |
39 | ||
40 | private String fTtitle; | |
41 | private String fDescription; | |
42 | ||
43 | protected NewProjectMainWizardPage fMainPage; | |
44 | protected String fProjectName; | |
45 | protected URI fProjectLocation; | |
46 | protected IConfigurationElement fConfigElement; | |
47 | ||
48 | protected IProject fProject; | |
49 | ||
50 | /** | |
51 | * | |
52 | */ | |
53 | public NewProjectWizard() { | |
b9763f53 | 54 | this(Messages.NewProjectWizard_DialogHeader, Messages.NewProjectWizard_DialogMessage); |
abfad0aa FC |
55 | } |
56 | ||
57 | /** | |
58 | * @param title | |
59 | * @param desc | |
60 | */ | |
61 | public NewProjectWizard(String title, String desc) { | |
62 | super(); | |
63 | setDialogSettings(TmfUiPlugin.getDefault().getDialogSettings()); | |
64 | setNeedsProgressMonitor(true); | |
65 | setForcePreviousAndNextButtons(true); | |
66 | setWindowTitle(title); | |
67 | fTtitle = title; | |
68 | fDescription = desc; | |
69 | } | |
70 | ||
71 | /* (non-Javadoc) | |
72 | * @see org.eclipse.jface.wizard.Wizard#addPages() | |
73 | */ | |
74 | @Override | |
75 | public void addPages() { | |
b9763f53 | 76 | fMainPage= new NewProjectMainWizardPage(Messages.NewProjectWizard_DialogHeader); |
abfad0aa FC |
77 | fMainPage.setTitle(fTtitle); |
78 | fMainPage.setDescription(fDescription); | |
79 | addPage(fMainPage); | |
80 | } | |
81 | ||
82 | /* (non-Javadoc) | |
83 | * @see org.eclipse.jface.wizard.Wizard#performCancel() | |
84 | */ | |
85 | @Override | |
86 | public boolean performCancel() { | |
87 | return true; | |
88 | } | |
89 | ||
90 | /* (non-Javadoc) | |
91 | * @see org.eclipse.jface.wizard.Wizard#performFinish() | |
92 | */ | |
93 | @Override | |
94 | public boolean performFinish() { | |
95 | fProjectName = fMainPage.getProjectName(); | |
96 | fProjectLocation = fMainPage.useDefaults() ? null : fMainPage.getLocationURI(); | |
97 | fProject = createProject(fProjectName, fProjectLocation, new NullProgressMonitor()); | |
98 | return true; | |
99 | } | |
100 | ||
101 | public IProject getProject() { | |
102 | return fProject; | |
103 | } | |
104 | ||
105 | /** | |
106 | * @param projectName | |
107 | * @param projectLocation | |
108 | * @param monitor | |
109 | * @return | |
110 | */ | |
111 | private IProject createProject(String projectName, URI projectLocation, IProgressMonitor monitor) { | |
112 | ||
113 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | |
114 | IWorkspaceRoot root = workspace.getRoot(); | |
115 | IProject project = root.getProject(projectName); | |
116 | ||
117 | try { | |
118 | if (!project.exists()) { | |
119 | IProjectDescription description = workspace.newProjectDescription(project.getName()); | |
120 | if (projectLocation != null) | |
121 | description.setLocationURI(projectLocation); | |
122 | project.create(description, monitor); | |
123 | } | |
124 | ||
125 | if (!project.isOpen()) | |
126 | project.open(monitor); | |
127 | ||
128 | IProjectDescription description = project.getDescription(); | |
129 | description.setNatureIds(new String[] { TmfProjectNature.ID } ); | |
130 | project.setDescription(description, null); | |
131 | ||
132 | IFolder folder = project.getFolder(TmfProjectNode.TRACE_FOLDER_NAME); | |
133 | if (!folder.exists()) | |
134 | folder.create(true, true, null); | |
135 | ||
136 | folder = project.getFolder(TmfProjectNode.EXPER_FOLDER_NAME); | |
137 | if (!folder.exists()) | |
138 | folder.create(true, true, null); | |
139 | ||
140 | return project; | |
141 | } | |
142 | catch (CoreException e) { | |
143 | e.printStackTrace(); | |
144 | } | |
145 | return null; | |
146 | } | |
147 | ||
148 | } |