tmf/lttng: Remove unneeded (non-Javadoc) comments
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / wizards / NewTmfProjectWizard.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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.project.wizards;
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.IExecutableExtension;
26 import org.eclipse.core.runtime.IProgressMonitor;
27 import org.eclipse.core.runtime.NullProgressMonitor;
28 import org.eclipse.jface.viewers.IStructuredSelection;
29 import org.eclipse.jface.wizard.Wizard;
30 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
31 import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
32 import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
33 import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder;
34 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
35 import org.eclipse.ui.INewWizard;
36 import org.eclipse.ui.IWorkbench;
37 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
38
39 /**
40 * Wizard implementation for creating a TMF tracing project.
41 *
42 * @version 1.0
43 * @author Francois Chouinard
44 */
45 public class NewTmfProjectWizard extends Wizard implements INewWizard, IExecutableExtension {
46
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
62 private final String fTtitle;
63 private final String fDescription;
64
65 /**
66 * Wizard main page
67 */
68 protected NewTmfProjectMainWizardPage fMainPage;
69
70 /**
71 * The Project name
72 */
73 protected String fProjectName;
74
75 /**
76 * The project location
77 */
78
79 protected URI fProjectLocation;
80
81 /**
82 * The configuration element.
83 */
84 protected IConfigurationElement fConfigElement;
85
86 /**
87 * The project reference
88 */
89 protected IProject fProject;
90
91 // ------------------------------------------------------------------------
92 // Constructors
93 // ------------------------------------------------------------------------
94
95 /**
96 * Default constructor
97 */
98 public NewTmfProjectWizard() {
99 this(Messages.NewProjectWizard_DialogHeader, Messages.NewProjectWizard_DialogMessage);
100 }
101
102 /**
103 * Constructor
104 * @param title The tile string
105 * @param desc The description string
106 */
107 public NewTmfProjectWizard(String title, String desc) {
108 super();
109 setDialogSettings(Activator.getDefault().getDialogSettings());
110 setNeedsProgressMonitor(true);
111 setForcePreviousAndNextButtons(true);
112 setWindowTitle(title);
113 fTtitle = title;
114 fDescription = desc;
115 }
116
117 // ------------------------------------------------------------------------
118 // Wizard
119 // ------------------------------------------------------------------------
120
121 @Override
122 public void addPages() {
123 fMainPage = new NewTmfProjectMainWizardPage(Messages.NewProjectWizard_DialogHeader);
124 fMainPage.setTitle(fTtitle);
125 fMainPage.setDescription(fDescription);
126 addPage(fMainPage);
127 }
128
129 @Override
130 public boolean performCancel() {
131 return true;
132 }
133
134 @Override
135 public boolean performFinish() {
136 fProjectName = fMainPage.getProjectName();
137 fProjectLocation = fMainPage.useDefaults() ? null : fMainPage.getLocationURI();
138 fProject = createProject(fProjectName, fProjectLocation, new NullProgressMonitor());
139 BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
140 return true;
141 }
142
143 private static IProject createProject(String projectName, URI projectLocation, IProgressMonitor monitor) {
144
145 IWorkspace workspace = ResourcesPlugin.getWorkspace();
146 IWorkspaceRoot root = workspace.getRoot();
147 IProject project = root.getProject(projectName);
148
149 try {
150 if (!project.exists()) {
151 IProjectDescription description = workspace.newProjectDescription(project.getName());
152 if (projectLocation != null) {
153 description.setLocationURI(projectLocation);
154 }
155 project.create(description, monitor);
156 }
157
158 if (!project.isOpen()) {
159 project.open(monitor);
160 }
161
162 IProjectDescription description = project.getDescription();
163 description.setNatureIds(new String[] { TmfProjectNature.ID });
164 project.setDescription(description, null);
165
166 IFolder folder = project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME);
167 if (!folder.exists()) {
168 folder.create(true, true, null);
169 }
170
171 folder = project.getFolder(TmfExperimentFolder.EXPER_FOLDER_NAME);
172 if (!folder.exists()) {
173 folder.create(true, true, null);
174 }
175
176 // create folder for supplementary tracing files
177 folder = project.getFolder(TmfCommonConstants.TRACE_SUPPLEMENATARY_FOLDER_NAME);
178
179 if (!folder.exists()) {
180 folder.create(true, true, null);
181 }
182
183 return project;
184 } catch (CoreException e) {
185 Activator.getDefault().logError("Error creating TMF project " + project.getName(), e); //$NON-NLS-1$
186 }
187 return null;
188 }
189
190 // ------------------------------------------------------------------------
191 // INewWizard
192 // ------------------------------------------------------------------------
193
194 @Override
195 public void init(IWorkbench iworkbench, IStructuredSelection istructuredselection) {
196 }
197
198 // ------------------------------------------------------------------------
199 // IExecutableExtension
200 // ------------------------------------------------------------------------
201
202 @Override
203 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
204 fConfigElement = config;
205 }
206
207 }
This page took 0.037809 seconds and 6 git commands to generate.