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; | |
6c13869b | 28 | import org.eclipse.linuxtools.tmf.core.TmfProjectNature; |
abfad0aa | 29 | import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin; |
12c155f5 FC |
30 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder; |
31 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; | |
32 | import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; | |
abfad0aa FC |
33 | import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; |
34 | ||
35 | /** | |
9501fb58 | 36 | * <b><u>NewTmfProjectWizard</u></b> |
abfad0aa | 37 | * <p> |
abfad0aa | 38 | */ |
9501fb58 | 39 | public class NewTmfProjectWizard extends BasicNewResourceWizard implements IExecutableExtension { |
abfad0aa | 40 | |
12c155f5 FC |
41 | private final String fTtitle; |
42 | private final String fDescription; | |
abfad0aa | 43 | |
9501fb58 | 44 | protected NewTmfProjectMainWizardPage fMainPage; |
abfad0aa FC |
45 | protected String fProjectName; |
46 | protected URI fProjectLocation; | |
47 | protected IConfigurationElement fConfigElement; | |
48 | ||
49 | protected IProject fProject; | |
50 | ||
51 | /** | |
52 | * | |
53 | */ | |
9501fb58 | 54 | public NewTmfProjectWizard() { |
b9763f53 | 55 | this(Messages.NewProjectWizard_DialogHeader, Messages.NewProjectWizard_DialogMessage); |
abfad0aa FC |
56 | } |
57 | ||
58 | /** | |
59 | * @param title | |
60 | * @param desc | |
61 | */ | |
9501fb58 | 62 | public NewTmfProjectWizard(String title, String desc) { |
abfad0aa FC |
63 | super(); |
64 | setDialogSettings(TmfUiPlugin.getDefault().getDialogSettings()); | |
65 | setNeedsProgressMonitor(true); | |
66 | setForcePreviousAndNextButtons(true); | |
67 | setWindowTitle(title); | |
68 | fTtitle = title; | |
69 | fDescription = desc; | |
70 | } | |
71 | ||
12c155f5 FC |
72 | /* |
73 | * (non-Javadoc) | |
74 | * | |
abfad0aa FC |
75 | * @see org.eclipse.jface.wizard.Wizard#addPages() |
76 | */ | |
77 | @Override | |
78 | public void addPages() { | |
9501fb58 | 79 | fMainPage = new NewTmfProjectMainWizardPage(Messages.NewProjectWizard_DialogHeader); |
abfad0aa FC |
80 | fMainPage.setTitle(fTtitle); |
81 | fMainPage.setDescription(fDescription); | |
82 | addPage(fMainPage); | |
83 | } | |
84 | ||
12c155f5 FC |
85 | /* |
86 | * (non-Javadoc) | |
87 | * | |
abfad0aa FC |
88 | * @see org.eclipse.jface.wizard.Wizard#performCancel() |
89 | */ | |
90 | @Override | |
91 | public boolean performCancel() { | |
92 | return true; | |
93 | } | |
94 | ||
12c155f5 FC |
95 | /* |
96 | * (non-Javadoc) | |
97 | * | |
abfad0aa FC |
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()); | |
12c155f5 | 105 | BasicNewProjectResourceWizard.updatePerspective(fConfigElement); |
abfad0aa FC |
106 | return true; |
107 | } | |
108 | ||
abfad0aa FC |
109 | /** |
110 | * @param projectName | |
111 | * @param projectLocation | |
112 | * @param monitor | |
113 | * @return | |
114 | */ | |
115 | private IProject createProject(String projectName, URI projectLocation, IProgressMonitor monitor) { | |
116 | ||
117 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); | |
118 | IWorkspaceRoot root = workspace.getRoot(); | |
119 | IProject project = root.getProject(projectName); | |
120 | ||
121 | try { | |
122 | if (!project.exists()) { | |
123 | IProjectDescription description = workspace.newProjectDescription(project.getName()); | |
124 | if (projectLocation != null) | |
125 | description.setLocationURI(projectLocation); | |
126 | project.create(description, monitor); | |
127 | } | |
128 | ||
129 | if (!project.isOpen()) | |
130 | project.open(monitor); | |
131 | ||
132 | IProjectDescription description = project.getDescription(); | |
12c155f5 | 133 | description.setNatureIds(new String[] { TmfProjectNature.ID }); |
abfad0aa FC |
134 | project.setDescription(description, null); |
135 | ||
12c155f5 | 136 | IFolder folder = project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME); |
abfad0aa FC |
137 | if (!folder.exists()) |
138 | folder.create(true, true, null); | |
139 | ||
12c155f5 | 140 | folder = project.getFolder(TmfExperimentFolder.EXPER_FOLDER_NAME); |
abfad0aa FC |
141 | if (!folder.exists()) |
142 | folder.create(true, true, null); | |
143 | ||
144 | return project; | |
12c155f5 | 145 | } catch (CoreException e) { |
abfad0aa FC |
146 | e.printStackTrace(); |
147 | } | |
148 | return null; | |
149 | } | |
150 | ||
12c155f5 FC |
151 | // ------------------------------------------------------------------------ |
152 | // IExecutableExtension | |
153 | // ------------------------------------------------------------------------ | |
154 | ||
155 | @Override | |
156 | public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { | |
157 | fConfigElement = config; | |
158 | } | |
159 | ||
160 | } |