1 /*******************************************************************************
2 * Copyright (c) 2009, 2011 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.wizards
;
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
;
40 * Wizard implementation for creating a TMF tracing project.
43 * @author Francois Chouinard
45 public class NewTmfProjectWizard
extends Wizard
implements INewWizard
, IExecutableExtension
{
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
56 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.views.ui.wizards.newProject"; //$NON-NLS-1$
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
62 private final String fTtitle
;
63 private final String fDescription
;
68 protected NewTmfProjectMainWizardPage fMainPage
;
73 protected String fProjectName
;
76 * The project location
79 protected URI fProjectLocation
;
82 * The configuration element.
84 protected IConfigurationElement fConfigElement
;
87 * The project reference
89 protected IProject fProject
;
91 // ------------------------------------------------------------------------
93 // ------------------------------------------------------------------------
98 public NewTmfProjectWizard() {
99 this(Messages
.NewProjectWizard_DialogHeader
, Messages
.NewProjectWizard_DialogMessage
);
104 * @param title The tile string
105 * @param desc The description string
107 public NewTmfProjectWizard(String title
, String desc
) {
109 setDialogSettings(Activator
.getDefault().getDialogSettings());
110 setNeedsProgressMonitor(true);
111 setForcePreviousAndNextButtons(true);
112 setWindowTitle(title
);
117 // ------------------------------------------------------------------------
119 // ------------------------------------------------------------------------
124 * @see org.eclipse.jface.wizard.Wizard#addPages()
127 public void addPages() {
128 fMainPage
= new NewTmfProjectMainWizardPage(Messages
.NewProjectWizard_DialogHeader
);
129 fMainPage
.setTitle(fTtitle
);
130 fMainPage
.setDescription(fDescription
);
137 * @see org.eclipse.jface.wizard.Wizard#performCancel()
140 public boolean performCancel() {
147 * @see org.eclipse.jface.wizard.Wizard#performFinish()
150 public boolean performFinish() {
151 fProjectName
= fMainPage
.getProjectName();
152 fProjectLocation
= fMainPage
.useDefaults() ?
null : fMainPage
.getLocationURI();
153 fProject
= createProject(fProjectName
, fProjectLocation
, new NullProgressMonitor());
154 BasicNewProjectResourceWizard
.updatePerspective(fConfigElement
);
158 private static IProject
createProject(String projectName
, URI projectLocation
, IProgressMonitor monitor
) {
160 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
161 IWorkspaceRoot root
= workspace
.getRoot();
162 IProject project
= root
.getProject(projectName
);
165 if (!project
.exists()) {
166 IProjectDescription description
= workspace
.newProjectDescription(project
.getName());
167 if (projectLocation
!= null) {
168 description
.setLocationURI(projectLocation
);
170 project
.create(description
, monitor
);
173 if (!project
.isOpen()) {
174 project
.open(monitor
);
177 IProjectDescription description
= project
.getDescription();
178 description
.setNatureIds(new String
[] { TmfProjectNature
.ID
});
179 project
.setDescription(description
, null);
181 IFolder folder
= project
.getFolder(TmfTraceFolder
.TRACE_FOLDER_NAME
);
182 if (!folder
.exists()) {
183 folder
.create(true, true, null);
186 folder
= project
.getFolder(TmfExperimentFolder
.EXPER_FOLDER_NAME
);
187 if (!folder
.exists()) {
188 folder
.create(true, true, null);
191 // create folder for supplementary tracing files
192 folder
= project
.getFolder(TmfCommonConstants
.TRACE_SUPPLEMENATARY_FOLDER_NAME
);
194 if (!folder
.exists()) {
195 folder
.create(true, true, null);
199 } catch (CoreException e
) {
200 Activator
.getDefault().logError("Error creating TMF project " + project
.getName(), e
); //$NON-NLS-1$
205 // ------------------------------------------------------------------------
207 // ------------------------------------------------------------------------
210 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
213 public void init(IWorkbench iworkbench
, IStructuredSelection istructuredselection
) {
216 // ------------------------------------------------------------------------
217 // IExecutableExtension
218 // ------------------------------------------------------------------------
222 * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
225 public void setInitializationData(IConfigurationElement config
, String propertyName
, Object data
) throws CoreException
{
226 fConfigElement
= config
;