e0bd8a303cdb6f9231c3fe1a6a76012133ffbefa
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / project / dialogs / NewProjectWizard.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng.ui.views.project.dialogs;
14
15 import java.net.URI;
16
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;
31
32 /**
33 * <b><u>NewProjectWizard</u></b>
34 * <p>
35 * TODO: Implement me. Please.
36 */
37 public class NewProjectWizard extends BasicNewResourceWizard {
38
39 private String fTtitle;
40 private String fDescription;
41
42 protected NewProjectMainWizardPage fMainPage;
43 protected String fProjectName;
44 protected URI fProjectLocation;
45 protected IConfigurationElement fConfigElement;
46
47 protected IProject fProject;
48
49 /**
50 *
51 */
52 public NewProjectWizard() {
53 this("LTTng Project", "Create an LTTng Project");
54 }
55
56 /**
57 * @param title
58 * @param desc
59 */
60 public NewProjectWizard(String title, String desc) {
61 super();
62 setDialogSettings(LTTngUiPlugin.getDefault().getDialogSettings());
63 setNeedsProgressMonitor(true);
64 setForcePreviousAndNextButtons(true);
65 setWindowTitle(title);
66 fTtitle = title;
67 fDescription = desc;
68 }
69
70 /* (non-Javadoc)
71 * @see org.eclipse.jface.wizard.Wizard#addPages()
72 */
73 @Override
74 public void addPages() {
75 fMainPage= new NewProjectMainWizardPage("LTTng Project");
76 fMainPage.setTitle(fTtitle);
77 fMainPage.setDescription(fDescription);
78 addPage(fMainPage);
79 }
80
81 /* (non-Javadoc)
82 * @see org.eclipse.jface.wizard.Wizard#performCancel()
83 */
84 @Override
85 public boolean performCancel() {
86 return true;
87 }
88
89 /* (non-Javadoc)
90 * @see org.eclipse.jface.wizard.Wizard#performFinish()
91 */
92 @Override
93 public boolean performFinish() {
94 fProjectName = fMainPage.getProjectName();
95 fProjectLocation = fMainPage.useDefaults() ? null : fMainPage.getLocationURI();
96 fProject = createProject(fProjectName, fProjectLocation, new NullProgressMonitor());
97 return true;
98 }
99
100 public IProject getProject() {
101 return fProject;
102 }
103
104 /**
105 * @param projectName
106 * @param projectLocation
107 * @param monitor
108 * @return
109 */
110 private IProject createProject(String projectName, URI projectLocation, IProgressMonitor monitor) {
111
112 IWorkspace workspace = ResourcesPlugin.getWorkspace();
113 IWorkspaceRoot root = workspace.getRoot();
114 IProject project = root.getProject(projectName);
115
116 try {
117 if (!project.exists()) {
118 IProjectDescription description = workspace.newProjectDescription(project.getName());
119 if (projectLocation != null)
120 description.setLocationURI(projectLocation);
121 project.create(description, monitor);
122 }
123
124 if (!project.isOpen())
125 project.open(monitor);
126
127 IProjectDescription description = project.getDescription();
128 description.setNatureIds(new String[] { LTTngProjectNature.ID } );
129 project.setDescription(description, null);
130
131 IFolder folder = project.getFolder(LTTngProjectNode.TRACE_FOLDER_NAME);
132 if (!folder.exists())
133 folder.create(true, true, null);
134
135 folder = project.getFolder(LTTngProjectNode.EXPER_FOLDER_NAME);
136 if (!folder.exists())
137 folder.create(true, true, null);
138
139 return project;
140 }
141 catch (CoreException e) {
142 e.printStackTrace();
143 }
144 return null;
145 }
146
147 }
This page took 0.039736 seconds and 4 git commands to generate.