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
.linuxtools
.tmf
.TmfProjectNature
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentFolder
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceFolder
;
32 import org
.eclipse
.ui
.wizards
.newresource
.BasicNewProjectResourceWizard
;
33 import org
.eclipse
.ui
.wizards
.newresource
.BasicNewResourceWizard
;
36 * <b><u>NewTmfProjectWizard</u></b>
39 public class NewTmfProjectWizard
extends BasicNewResourceWizard
implements IExecutableExtension
{
41 private final String fTtitle
;
42 private final String fDescription
;
44 protected NewTmfProjectMainWizardPage fMainPage
;
45 protected String fProjectName
;
46 protected URI fProjectLocation
;
47 protected IConfigurationElement fConfigElement
;
49 protected IProject fProject
;
54 public NewTmfProjectWizard() {
55 this(Messages
.NewProjectWizard_DialogHeader
, Messages
.NewProjectWizard_DialogMessage
);
62 public NewTmfProjectWizard(String title
, String desc
) {
64 setDialogSettings(TmfUiPlugin
.getDefault().getDialogSettings());
65 setNeedsProgressMonitor(true);
66 setForcePreviousAndNextButtons(true);
67 setWindowTitle(title
);
75 * @see org.eclipse.jface.wizard.Wizard#addPages()
78 public void addPages() {
79 fMainPage
= new NewTmfProjectMainWizardPage(Messages
.NewProjectWizard_DialogHeader
);
80 fMainPage
.setTitle(fTtitle
);
81 fMainPage
.setDescription(fDescription
);
88 * @see org.eclipse.jface.wizard.Wizard#performCancel()
91 public boolean performCancel() {
98 * @see org.eclipse.jface.wizard.Wizard#performFinish()
101 public boolean performFinish() {
102 fProjectName
= fMainPage
.getProjectName();
103 fProjectLocation
= fMainPage
.useDefaults() ?
null : fMainPage
.getLocationURI();
104 fProject
= createProject(fProjectName
, fProjectLocation
, new NullProgressMonitor());
105 BasicNewProjectResourceWizard
.updatePerspective(fConfigElement
);
111 * @param projectLocation
115 private IProject
createProject(String projectName
, URI projectLocation
, IProgressMonitor monitor
) {
117 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
118 IWorkspaceRoot root
= workspace
.getRoot();
119 IProject project
= root
.getProject(projectName
);
122 if (!project
.exists()) {
123 IProjectDescription description
= workspace
.newProjectDescription(project
.getName());
124 if (projectLocation
!= null)
125 description
.setLocationURI(projectLocation
);
126 project
.create(description
, monitor
);
129 if (!project
.isOpen())
130 project
.open(monitor
);
132 IProjectDescription description
= project
.getDescription();
133 description
.setNatureIds(new String
[] { TmfProjectNature
.ID
});
134 project
.setDescription(description
, null);
136 IFolder folder
= project
.getFolder(TmfTraceFolder
.TRACE_FOLDER_NAME
);
137 if (!folder
.exists())
138 folder
.create(true, true, null);
140 folder
= project
.getFolder(TmfExperimentFolder
.EXPER_FOLDER_NAME
);
141 if (!folder
.exists())
142 folder
.create(true, true, null);
145 } catch (CoreException e
) {
151 // ------------------------------------------------------------------------
152 // IExecutableExtension
153 // ------------------------------------------------------------------------
156 public void setInitializationData(IConfigurationElement config
, String propertyName
, Object data
) throws CoreException
{
157 fConfigElement
= config
;