1 /*******************************************************************************
2 * Copyright (c) 2009 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
.lttng
.ui
.views
.project
.dialogs
;
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
.IProgressMonitor
;
26 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.project
.LTTngProjectNature
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.project
.model
.LTTngProjectNode
;
30 import org
.eclipse
.ui
.wizards
.newresource
.BasicNewResourceWizard
;
33 * <b><u>NewProjectWizard</u></b>
35 * TODO: Implement me. Please.
37 public class NewProjectWizard
extends BasicNewResourceWizard
{
39 private String fTtitle
;
40 private String fDescription
;
42 protected NewProjectMainWizardPage fMainPage
;
43 protected String fProjectName
;
44 protected URI fProjectLocation
;
45 protected IConfigurationElement fConfigElement
;
47 protected IProject fProject
;
52 public NewProjectWizard() {
53 this("LTTng Project", "Create an LTTng Project");
60 public NewProjectWizard(String title
, String desc
) {
62 setDialogSettings(LTTngUiPlugin
.getDefault().getDialogSettings());
63 setNeedsProgressMonitor(true);
64 setForcePreviousAndNextButtons(true);
65 setWindowTitle(title
);
71 * @see org.eclipse.jface.wizard.Wizard#addPages()
74 public void addPages() {
75 fMainPage
= new NewProjectMainWizardPage("LTTng Project");
76 fMainPage
.setTitle(fTtitle
);
77 fMainPage
.setDescription(fDescription
);
82 * @see org.eclipse.jface.wizard.Wizard#performCancel()
85 public boolean performCancel() {
90 * @see org.eclipse.jface.wizard.Wizard#performFinish()
93 public boolean performFinish() {
94 fProjectName
= fMainPage
.getProjectName();
95 fProjectLocation
= fMainPage
.useDefaults() ?
null : fMainPage
.getLocationURI();
96 fProject
= createProject(fProjectName
, fProjectLocation
, new NullProgressMonitor());
100 public IProject
getProject() {
106 * @param projectLocation
110 private IProject
createProject(String projectName
, URI projectLocation
, IProgressMonitor monitor
) {
112 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
113 IWorkspaceRoot root
= workspace
.getRoot();
114 IProject project
= root
.getProject(projectName
);
117 if (!project
.exists()) {
118 IProjectDescription description
= workspace
.newProjectDescription(project
.getName());
119 if (projectLocation
!= null)
120 description
.setLocationURI(projectLocation
);
121 project
.create(description
, monitor
);
124 if (!project
.isOpen())
125 project
.open(monitor
);
127 IProjectDescription description
= project
.getDescription();
128 description
.setNatureIds(new String
[] { LTTngProjectNature
.ID
} );
129 project
.setDescription(description
, null);
131 IFolder folder
= project
.getFolder(LTTngProjectNode
.TRACE_FOLDER_NAME
);
132 if (!folder
.exists())
133 folder
.create(true, true, null);
135 folder
= project
.getFolder(LTTngProjectNode
.EXPER_FOLDER_NAME
);
136 if (!folder
.exists())
137 folder
.create(true, true, null);
141 catch (CoreException e
) {