Add a "Clear Tracing Views" command
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / wizards / NewTmfProjectWizard.java
CommitLineData
abfad0aa 1/*******************************************************************************
12c155f5 2 * Copyright (c) 2009, 2011 Ericsson
abbdd66a 3 *
abfad0aa
FC
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
abbdd66a 8 *
abfad0aa
FC
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
12c155f5 13package org.eclipse.linuxtools.tmf.ui.project.wizards;
abfad0aa
FC
14
15import java.net.URI;
16
17import org.eclipse.core.resources.IFolder;
18import org.eclipse.core.resources.IProject;
19import org.eclipse.core.resources.IProjectDescription;
20import org.eclipse.core.resources.IWorkspace;
21import org.eclipse.core.resources.IWorkspaceRoot;
22import org.eclipse.core.resources.ResourcesPlugin;
23import org.eclipse.core.runtime.CoreException;
24import org.eclipse.core.runtime.IConfigurationElement;
12c155f5 25import org.eclipse.core.runtime.IExecutableExtension;
abfad0aa
FC
26import org.eclipse.core.runtime.IProgressMonitor;
27import org.eclipse.core.runtime.NullProgressMonitor;
8f5c078d
FC
28import org.eclipse.jface.viewers.IStructuredSelection;
29import org.eclipse.jface.wizard.Wizard;
8fd82db5 30import org.eclipse.linuxtools.internal.tmf.ui.Activator;
e12ecd30 31import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
d34665f9 32import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
12c155f5
FC
33import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder;
34import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
8f5c078d
FC
35import org.eclipse.ui.INewWizard;
36import org.eclipse.ui.IWorkbench;
12c155f5 37import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
abfad0aa
FC
38
39/**
b544077e 40 * Wizard implementation for creating a TMF tracing project.
ea279a69 41 *
b544077e
BH
42 * @version 1.0
43 * @author Francois Chouinard
abfad0aa 44 */
8f5c078d 45public class NewTmfProjectWizard extends Wizard implements INewWizard, IExecutableExtension {
abfad0aa 46
ea279a69
FC
47 // ------------------------------------------------------------------------
48 // Constants
49 // ------------------------------------------------------------------------
50
51 /**
52 * The wizard id
53 *
54 * @since 2.0
55 */
56 public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.ui.wizards.newProject"; //$NON-NLS-1$
57
58 // ------------------------------------------------------------------------
59 // Attributes
60 // ------------------------------------------------------------------------
61
12c155f5
FC
62 private final String fTtitle;
63 private final String fDescription;
abfad0aa 64
b544077e
BH
65 /**
66 * Wizard main page
67 */
9501fb58 68 protected NewTmfProjectMainWizardPage fMainPage;
ea279a69 69
b544077e
BH
70 /**
71 * The Project name
72 */
abfad0aa 73 protected String fProjectName;
ea279a69 74
b544077e
BH
75 /**
76 * The project location
77 */
ea279a69 78
abfad0aa 79 protected URI fProjectLocation;
ea279a69 80
b544077e
BH
81 /**
82 * The configuration element.
83 */
abfad0aa
FC
84 protected IConfigurationElement fConfigElement;
85
b544077e
BH
86 /**
87 * The project reference
88 */
abfad0aa
FC
89 protected IProject fProject;
90
ea279a69
FC
91 // ------------------------------------------------------------------------
92 // Constructors
93 // ------------------------------------------------------------------------
94
abfad0aa 95 /**
b544077e 96 * Default constructor
abfad0aa 97 */
9501fb58 98 public NewTmfProjectWizard() {
b9763f53 99 this(Messages.NewProjectWizard_DialogHeader, Messages.NewProjectWizard_DialogMessage);
abfad0aa
FC
100 }
101
102 /**
b544077e
BH
103 * Constructor
104 * @param title The tile string
105 * @param desc The description string
abfad0aa 106 */
9501fb58 107 public NewTmfProjectWizard(String title, String desc) {
abfad0aa 108 super();
8fd82db5 109 setDialogSettings(Activator.getDefault().getDialogSettings());
abfad0aa
FC
110 setNeedsProgressMonitor(true);
111 setForcePreviousAndNextButtons(true);
112 setWindowTitle(title);
113 fTtitle = title;
114 fDescription = desc;
115 }
116
ea279a69
FC
117 // ------------------------------------------------------------------------
118 // Wizard
119 // ------------------------------------------------------------------------
120
12c155f5
FC
121 /*
122 * (non-Javadoc)
abbdd66a 123 *
abfad0aa
FC
124 * @see org.eclipse.jface.wizard.Wizard#addPages()
125 */
126 @Override
127 public void addPages() {
9501fb58 128 fMainPage = new NewTmfProjectMainWizardPage(Messages.NewProjectWizard_DialogHeader);
abfad0aa
FC
129 fMainPage.setTitle(fTtitle);
130 fMainPage.setDescription(fDescription);
131 addPage(fMainPage);
132 }
133
12c155f5
FC
134 /*
135 * (non-Javadoc)
abbdd66a 136 *
abfad0aa
FC
137 * @see org.eclipse.jface.wizard.Wizard#performCancel()
138 */
139 @Override
140 public boolean performCancel() {
141 return true;
142 }
143
12c155f5
FC
144 /*
145 * (non-Javadoc)
abbdd66a 146 *
abfad0aa
FC
147 * @see org.eclipse.jface.wizard.Wizard#performFinish()
148 */
149 @Override
150 public boolean performFinish() {
151 fProjectName = fMainPage.getProjectName();
152 fProjectLocation = fMainPage.useDefaults() ? null : fMainPage.getLocationURI();
153 fProject = createProject(fProjectName, fProjectLocation, new NullProgressMonitor());
12c155f5 154 BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
abfad0aa
FC
155 return true;
156 }
157
ea279a69 158 private static IProject createProject(String projectName, URI projectLocation, IProgressMonitor monitor) {
abfad0aa
FC
159
160 IWorkspace workspace = ResourcesPlugin.getWorkspace();
161 IWorkspaceRoot root = workspace.getRoot();
162 IProject project = root.getProject(projectName);
163
164 try {
165 if (!project.exists()) {
166 IProjectDescription description = workspace.newProjectDescription(project.getName());
abbdd66a 167 if (projectLocation != null) {
abfad0aa 168 description.setLocationURI(projectLocation);
abbdd66a 169 }
abfad0aa
FC
170 project.create(description, monitor);
171 }
172
abbdd66a 173 if (!project.isOpen()) {
abfad0aa 174 project.open(monitor);
abbdd66a 175 }
abfad0aa
FC
176
177 IProjectDescription description = project.getDescription();
12c155f5 178 description.setNatureIds(new String[] { TmfProjectNature.ID });
abfad0aa
FC
179 project.setDescription(description, null);
180
12c155f5 181 IFolder folder = project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME);
abbdd66a 182 if (!folder.exists()) {
abfad0aa 183 folder.create(true, true, null);
abbdd66a 184 }
abfad0aa 185
12c155f5 186 folder = project.getFolder(TmfExperimentFolder.EXPER_FOLDER_NAME);
abbdd66a 187 if (!folder.exists()) {
e12ecd30 188 folder.create(true, true, null);
abbdd66a 189 }
e12ecd30
BH
190
191 // create folder for supplementary tracing files
192 folder = project.getFolder(TmfCommonConstants.TRACE_SUPPLEMENATARY_FOLDER_NAME);
193
abbdd66a 194 if (!folder.exists()) {
abfad0aa 195 folder.create(true, true, null);
abbdd66a 196 }
abfad0aa
FC
197
198 return project;
12c155f5 199 } catch (CoreException e) {
abbdd66a 200 Activator.getDefault().logError("Error creating TMF project " + project.getName(), e); //$NON-NLS-1$
abfad0aa
FC
201 }
202 return null;
203 }
204
8f5c078d
FC
205 // ------------------------------------------------------------------------
206 // INewWizard
207 // ------------------------------------------------------------------------
208
209 /* (non-Javadoc)
210 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
211 */
212 @Override
213 public void init(IWorkbench iworkbench, IStructuredSelection istructuredselection) {
214 }
215
12c155f5
FC
216 // ------------------------------------------------------------------------
217 // IExecutableExtension
218 // ------------------------------------------------------------------------
219
b544077e
BH
220 /*
221 * (non-Javadoc)
222 * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
223 */
12c155f5
FC
224 @Override
225 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
226 fConfigElement = config;
227 }
228
229}
This page took 0.04693 seconds and 5 git commands to generate.