Internalize some more TMF APIs
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / wizards / NewTmfProjectWizard.java
CommitLineData
abfad0aa 1/*******************************************************************************
12c155f5 2 * Copyright (c) 2009, 2011 Ericsson
abfad0aa
FC
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
12c155f5 13package org.eclipse.linuxtools.tmf.ui.project.wizards;
abfad0aa
FC
14
15import java.net.URI;
16
17import org.eclipse.core.resources.IFolder;
18import org.eclipse.core.resources.IProject;
19import org.eclipse.core.resources.IProjectDescription;
20import org.eclipse.core.resources.IWorkspace;
21import org.eclipse.core.resources.IWorkspaceRoot;
22import org.eclipse.core.resources.ResourcesPlugin;
23import org.eclipse.core.runtime.CoreException;
24import org.eclipse.core.runtime.IConfigurationElement;
12c155f5 25import org.eclipse.core.runtime.IExecutableExtension;
abfad0aa
FC
26import org.eclipse.core.runtime.IProgressMonitor;
27import org.eclipse.core.runtime.NullProgressMonitor;
8f5c078d
FC
28import org.eclipse.jface.viewers.IStructuredSelection;
29import org.eclipse.jface.wizard.Wizard;
d34665f9
FC
30import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin;
31import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
12c155f5
FC
32import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder;
33import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
8f5c078d
FC
34import org.eclipse.ui.INewWizard;
35import org.eclipse.ui.IWorkbench;
12c155f5 36import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
abfad0aa
FC
37
38/**
9501fb58 39 * <b><u>NewTmfProjectWizard</u></b>
abfad0aa 40 * <p>
abfad0aa 41 */
8f5c078d 42public class NewTmfProjectWizard extends Wizard implements INewWizard, IExecutableExtension {
abfad0aa 43
12c155f5
FC
44 private final String fTtitle;
45 private final String fDescription;
abfad0aa 46
9501fb58 47 protected NewTmfProjectMainWizardPage fMainPage;
abfad0aa
FC
48 protected String fProjectName;
49 protected URI fProjectLocation;
50 protected IConfigurationElement fConfigElement;
51
52 protected IProject fProject;
53
54 /**
55 *
56 */
9501fb58 57 public NewTmfProjectWizard() {
b9763f53 58 this(Messages.NewProjectWizard_DialogHeader, Messages.NewProjectWizard_DialogMessage);
abfad0aa
FC
59 }
60
61 /**
62 * @param title
63 * @param desc
64 */
9501fb58 65 public NewTmfProjectWizard(String title, String desc) {
abfad0aa
FC
66 super();
67 setDialogSettings(TmfUiPlugin.getDefault().getDialogSettings());
68 setNeedsProgressMonitor(true);
69 setForcePreviousAndNextButtons(true);
70 setWindowTitle(title);
71 fTtitle = title;
72 fDescription = desc;
73 }
74
12c155f5
FC
75 /*
76 * (non-Javadoc)
77 *
abfad0aa
FC
78 * @see org.eclipse.jface.wizard.Wizard#addPages()
79 */
80 @Override
81 public void addPages() {
9501fb58 82 fMainPage = new NewTmfProjectMainWizardPage(Messages.NewProjectWizard_DialogHeader);
abfad0aa
FC
83 fMainPage.setTitle(fTtitle);
84 fMainPage.setDescription(fDescription);
85 addPage(fMainPage);
86 }
87
12c155f5
FC
88 /*
89 * (non-Javadoc)
90 *
abfad0aa
FC
91 * @see org.eclipse.jface.wizard.Wizard#performCancel()
92 */
93 @Override
94 public boolean performCancel() {
95 return true;
96 }
97
12c155f5
FC
98 /*
99 * (non-Javadoc)
100 *
abfad0aa
FC
101 * @see org.eclipse.jface.wizard.Wizard#performFinish()
102 */
103 @Override
104 public boolean performFinish() {
105 fProjectName = fMainPage.getProjectName();
106 fProjectLocation = fMainPage.useDefaults() ? null : fMainPage.getLocationURI();
107 fProject = createProject(fProjectName, fProjectLocation, new NullProgressMonitor());
12c155f5 108 BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
abfad0aa
FC
109 return true;
110 }
111
abfad0aa
FC
112 /**
113 * @param projectName
114 * @param projectLocation
115 * @param monitor
116 * @return
117 */
118 private IProject createProject(String projectName, URI projectLocation, IProgressMonitor monitor) {
119
120 IWorkspace workspace = ResourcesPlugin.getWorkspace();
121 IWorkspaceRoot root = workspace.getRoot();
122 IProject project = root.getProject(projectName);
123
124 try {
125 if (!project.exists()) {
126 IProjectDescription description = workspace.newProjectDescription(project.getName());
127 if (projectLocation != null)
128 description.setLocationURI(projectLocation);
129 project.create(description, monitor);
130 }
131
132 if (!project.isOpen())
133 project.open(monitor);
134
135 IProjectDescription description = project.getDescription();
12c155f5 136 description.setNatureIds(new String[] { TmfProjectNature.ID });
abfad0aa
FC
137 project.setDescription(description, null);
138
12c155f5 139 IFolder folder = project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME);
abfad0aa
FC
140 if (!folder.exists())
141 folder.create(true, true, null);
142
12c155f5 143 folder = project.getFolder(TmfExperimentFolder.EXPER_FOLDER_NAME);
abfad0aa
FC
144 if (!folder.exists())
145 folder.create(true, true, null);
146
147 return project;
12c155f5 148 } catch (CoreException e) {
abfad0aa
FC
149 e.printStackTrace();
150 }
151 return null;
152 }
153
8f5c078d
FC
154 // ------------------------------------------------------------------------
155 // INewWizard
156 // ------------------------------------------------------------------------
157
158 /* (non-Javadoc)
159 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
160 */
161 @Override
162 public void init(IWorkbench iworkbench, IStructuredSelection istructuredselection) {
163 }
164
12c155f5
FC
165 // ------------------------------------------------------------------------
166 // IExecutableExtension
167 // ------------------------------------------------------------------------
168
169 @Override
170 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
171 fConfigElement = config;
172 }
173
174}
This page took 0.037757 seconds and 5 git commands to generate.