Contribute CNF based TMF project handling
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / project / dialogs / NewProjectWizard.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2011 Ericsson, MontaVista Software
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 * Yufen Kuo (ykuo@mvista.com) - add support to allow user specify trace library path
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.lttng.ui.views.project.dialogs;
15
16 import java.net.URI;
17
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;
33
34 /**
35 * <b><u>NewProjectWizard</u></b>
36 * <p>
37 * TODO: Implement me. Please.
38 */
39 public class NewProjectWizard extends BasicNewResourceWizard {
40
41 private String fTtitle;
42 private String fDescription;
43
44 protected NewProjectMainWizardPage fMainPage;
45 protected String fProjectName;
46 protected URI fProjectLocation;
47 protected IConfigurationElement fConfigElement;
48
49 protected IProject fProject;
50 private TraceLibraryPathWizardPage traceLibraryPathPage;
51
52 /**
53 *
54 */
55 public NewProjectWizard() {
56 this(Messages.NewProjectWizard_Title, Messages.NewProjectWizard_Description);
57 }
58
59 /**
60 * @param title
61 * @param desc
62 */
63 public NewProjectWizard(String title, String desc) {
64 super();
65 setDialogSettings(LTTngUiPlugin.getDefault().getDialogSettings());
66 setNeedsProgressMonitor(true);
67 setForcePreviousAndNextButtons(true);
68 setWindowTitle(title);
69 fTtitle = title;
70 fDescription = desc;
71 }
72
73 /* (non-Javadoc)
74 * @see org.eclipse.jface.wizard.Wizard#addPages()
75 */
76 @Override
77 public void addPages() {
78 fMainPage= new NewProjectMainWizardPage(Messages.NewProjectWizard_Title);
79 fMainPage.setTitle(fTtitle);
80 fMainPage.setDescription(fDescription);
81 addPage(fMainPage);
82 traceLibraryPathPage = new TraceLibraryPathWizardPage(Messages.NewProjectWizard_Title);
83 traceLibraryPathPage.setTitle(Messages.TraceLibraryPathWizardPage_Title);
84 traceLibraryPathPage.setDescription(Messages.TraceLibraryPathWizardPage_Description);
85 addPage(traceLibraryPathPage);
86
87 }
88
89 /* (non-Javadoc)
90 * @see org.eclipse.jface.wizard.Wizard#performCancel()
91 */
92 @Override
93 public boolean performCancel() {
94 return true;
95 }
96
97 /* (non-Javadoc)
98 * @see org.eclipse.jface.wizard.Wizard#performFinish()
99 */
100 @Override
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);
108 }
109 return true;
110 }
111
112 public IProject getProject() {
113 return fProject;
114 }
115
116 /**
117 * @param projectName
118 * @param projectLocation
119 * @param monitor
120 * @return
121 */
122 private IProject createProject(String projectName, URI projectLocation, IProgressMonitor monitor) {
123
124 IWorkspace workspace = ResourcesPlugin.getWorkspace();
125 IWorkspaceRoot root = workspace.getRoot();
126 IProject project = root.getProject(projectName);
127
128 try {
129 if (!project.exists()) {
130 IProjectDescription description = workspace.newProjectDescription(project.getName());
131 if (projectLocation != null)
132 description.setLocationURI(projectLocation);
133 project.create(description, monitor);
134 }
135
136 if (!project.isOpen())
137 project.open(monitor);
138
139 IProjectDescription description = project.getDescription();
140 description.setNatureIds(new String[] { LTTngProjectNature.ID } );
141 project.setDescription(description, null);
142
143 IFolder folder = project.getFolder(LTTngProjectNode.TRACE_FOLDER_NAME);
144 if (!folder.exists())
145 folder.create(true, true, null);
146
147 folder = project.getFolder(LTTngProjectNode.EXPER_FOLDER_NAME);
148 if (!folder.exists())
149 folder.create(true, true, null);
150
151 return project;
152 }
153 catch (CoreException e) {
154 e.printStackTrace();
155 }
156 return null;
157 }
158
159 }
This page took 0.03618 seconds and 5 git commands to generate.