1 /*******************************************************************************
2 * Copyright (c) 2009, 2011 Ericsson, MontaVista Software
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 * Yufen Kuo (ykuo@mvista.com) - add support to allow user specify trace library path
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.project
.dialogs
;
18 import org
.eclipse
.core
.resources
.IFolder
;
19 import org
.eclipse
.core
.resources
.IProject
;
20 import org
.eclipse
.core
.resources
.IProjectDescription
;
21 import org
.eclipse
.core
.resources
.IWorkspace
;
22 import org
.eclipse
.core
.resources
.IWorkspaceRoot
;
23 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
24 import org
.eclipse
.core
.runtime
.CoreException
;
25 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
26 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
27 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
28 import org
.eclipse
.linuxtools
.lttng
.LTTngProjectNature
;
29 import org
.eclipse
.linuxtools
.lttng
.TraceHelper
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
31 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.project
.model
.LTTngProjectNode
;
32 import org
.eclipse
.ui
.wizards
.newresource
.BasicNewResourceWizard
;
35 * <b><u>NewProjectWizard</u></b>
37 * TODO: Implement me. Please.
39 public class NewProjectWizard
extends BasicNewResourceWizard
{
41 private String fTtitle
;
42 private String fDescription
;
44 protected NewProjectMainWizardPage fMainPage
;
45 protected String fProjectName
;
46 protected URI fProjectLocation
;
47 protected IConfigurationElement fConfigElement
;
49 protected IProject fProject
;
50 private TraceLibraryPathWizardPage traceLibraryPathPage
;
55 public NewProjectWizard() {
56 this(Messages
.NewProjectWizard_Title
, Messages
.NewProjectWizard_Description
);
63 public NewProjectWizard(String title
, String desc
) {
65 setDialogSettings(LTTngUiPlugin
.getDefault().getDialogSettings());
66 setNeedsProgressMonitor(true);
67 setForcePreviousAndNextButtons(true);
68 setWindowTitle(title
);
74 * @see org.eclipse.jface.wizard.Wizard#addPages()
77 public void addPages() {
78 fMainPage
= new NewProjectMainWizardPage(Messages
.NewProjectWizard_Title
);
79 fMainPage
.setTitle(fTtitle
);
80 fMainPage
.setDescription(fDescription
);
82 traceLibraryPathPage
= new TraceLibraryPathWizardPage(Messages
.NewProjectWizard_Title
);
83 traceLibraryPathPage
.setTitle(Messages
.TraceLibraryPathWizardPage_Title
);
84 traceLibraryPathPage
.setDescription(Messages
.TraceLibraryPathWizardPage_Description
);
85 addPage(traceLibraryPathPage
);
90 * @see org.eclipse.jface.wizard.Wizard#performCancel()
93 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 String traceLibraryPath
= traceLibraryPathPage
.getPath();
106 if (traceLibraryPath
!= null){
107 return TraceHelper
.setProjectPreference(fProject
, "traceLibraryPath", traceLibraryPath
);
112 public IProject
getProject() {
118 * @param projectLocation
122 private IProject
createProject(String projectName
, URI projectLocation
, IProgressMonitor monitor
) {
124 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
125 IWorkspaceRoot root
= workspace
.getRoot();
126 IProject project
= root
.getProject(projectName
);
129 if (!project
.exists()) {
130 IProjectDescription description
= workspace
.newProjectDescription(project
.getName());
131 if (projectLocation
!= null)
132 description
.setLocationURI(projectLocation
);
133 project
.create(description
, monitor
);
136 if (!project
.isOpen())
137 project
.open(monitor
);
139 IProjectDescription description
= project
.getDescription();
140 description
.setNatureIds(new String
[] { LTTngProjectNature
.ID
} );
141 project
.setDescription(description
, null);
143 IFolder folder
= project
.getFolder(LTTngProjectNode
.TRACE_FOLDER_NAME
);
144 if (!folder
.exists())
145 folder
.create(true, true, null);
147 folder
= project
.getFolder(LTTngProjectNode
.EXPER_FOLDER_NAME
);
148 if (!folder
.exists())
149 folder
.create(true, true, null);
153 catch (CoreException e
) {