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 private final String fTtitle
;
48 private final String fDescription
;
53 protected NewTmfProjectMainWizardPage fMainPage
;
57 protected String fProjectName
;
59 * The project location
61 protected URI fProjectLocation
;
63 * The configuration element.
65 protected IConfigurationElement fConfigElement
;
68 * The project reference
70 protected IProject fProject
;
75 public NewTmfProjectWizard() {
76 this(Messages
.NewProjectWizard_DialogHeader
, Messages
.NewProjectWizard_DialogMessage
);
81 * @param title The tile string
82 * @param desc The description string
84 public NewTmfProjectWizard(String title
, String desc
) {
86 setDialogSettings(Activator
.getDefault().getDialogSettings());
87 setNeedsProgressMonitor(true);
88 setForcePreviousAndNextButtons(true);
89 setWindowTitle(title
);
97 * @see org.eclipse.jface.wizard.Wizard#addPages()
100 public void addPages() {
101 fMainPage
= new NewTmfProjectMainWizardPage(Messages
.NewProjectWizard_DialogHeader
);
102 fMainPage
.setTitle(fTtitle
);
103 fMainPage
.setDescription(fDescription
);
110 * @see org.eclipse.jface.wizard.Wizard#performCancel()
113 public boolean performCancel() {
120 * @see org.eclipse.jface.wizard.Wizard#performFinish()
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
);
131 private static IProject
createProject(String projectName
,
132 URI projectLocation
, IProgressMonitor monitor
) {
134 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
135 IWorkspaceRoot root
= workspace
.getRoot();
136 IProject project
= root
.getProject(projectName
);
139 if (!project
.exists()) {
140 IProjectDescription description
= workspace
.newProjectDescription(project
.getName());
141 if (projectLocation
!= null) {
142 description
.setLocationURI(projectLocation
);
144 project
.create(description
, monitor
);
147 if (!project
.isOpen()) {
148 project
.open(monitor
);
151 IProjectDescription description
= project
.getDescription();
152 description
.setNatureIds(new String
[] { TmfProjectNature
.ID
});
153 project
.setDescription(description
, null);
155 IFolder folder
= project
.getFolder(TmfTraceFolder
.TRACE_FOLDER_NAME
);
156 if (!folder
.exists()) {
157 folder
.create(true, true, null);
160 folder
= project
.getFolder(TmfExperimentFolder
.EXPER_FOLDER_NAME
);
161 if (!folder
.exists()) {
162 folder
.create(true, true, null);
165 // create folder for supplementary tracing files
166 folder
= project
.getFolder(TmfCommonConstants
.TRACE_SUPPLEMENATARY_FOLDER_NAME
);
168 if (!folder
.exists()) {
169 folder
.create(true, true, null);
173 } catch (CoreException e
) {
174 Activator
.getDefault().logError("Error creating TMF project " + project
.getName(), e
); //$NON-NLS-1$
179 // ------------------------------------------------------------------------
181 // ------------------------------------------------------------------------
184 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
187 public void init(IWorkbench iworkbench
, IStructuredSelection istructuredselection
) {
190 // ------------------------------------------------------------------------
191 // IExecutableExtension
192 // ------------------------------------------------------------------------
196 * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
199 public void setInitializationData(IConfigurationElement config
, String propertyName
, Object data
) throws CoreException
{
200 fConfigElement
= config
;