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