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