Internalize some classes and fix a pile of warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / wizards / NewTmfProjectWizard.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2011 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.tmf.ui.project.wizards;
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.IExecutableExtension;
26 import org.eclipse.core.runtime.IProgressMonitor;
27 import org.eclipse.core.runtime.NullProgressMonitor;
28 import org.eclipse.jface.viewers.IStructuredSelection;
29 import org.eclipse.jface.wizard.Wizard;
30 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
31 import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
32 import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
33 import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder;
34 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
35 import org.eclipse.ui.INewWizard;
36 import org.eclipse.ui.IWorkbench;
37 import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
38
39 /**
40 * <b><u>NewTmfProjectWizard</u></b>
41 * <p>
42 */
43 public class NewTmfProjectWizard extends Wizard implements INewWizard, IExecutableExtension {
44
45 private final String fTtitle;
46 private final String fDescription;
47
48 protected NewTmfProjectMainWizardPage fMainPage;
49 protected String fProjectName;
50 protected URI fProjectLocation;
51 protected IConfigurationElement fConfigElement;
52
53 protected IProject fProject;
54
55 /**
56 *
57 */
58 public NewTmfProjectWizard() {
59 this(Messages.NewProjectWizard_DialogHeader, Messages.NewProjectWizard_DialogMessage);
60 }
61
62 /**
63 * @param title
64 * @param desc
65 */
66 public NewTmfProjectWizard(String title, String desc) {
67 super();
68 setDialogSettings(Activator.getDefault().getDialogSettings());
69 setNeedsProgressMonitor(true);
70 setForcePreviousAndNextButtons(true);
71 setWindowTitle(title);
72 fTtitle = title;
73 fDescription = desc;
74 }
75
76 /*
77 * (non-Javadoc)
78 *
79 * @see org.eclipse.jface.wizard.Wizard#addPages()
80 */
81 @Override
82 public void addPages() {
83 fMainPage = new NewTmfProjectMainWizardPage(Messages.NewProjectWizard_DialogHeader);
84 fMainPage.setTitle(fTtitle);
85 fMainPage.setDescription(fDescription);
86 addPage(fMainPage);
87 }
88
89 /*
90 * (non-Javadoc)
91 *
92 * @see org.eclipse.jface.wizard.Wizard#performCancel()
93 */
94 @Override
95 public boolean performCancel() {
96 return true;
97 }
98
99 /*
100 * (non-Javadoc)
101 *
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());
109 BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
110 return true;
111 }
112
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();
137 description.setNatureIds(new String[] { TmfProjectNature.ID });
138 project.setDescription(description, null);
139
140 IFolder folder = project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME);
141 if (!folder.exists())
142 folder.create(true, true, null);
143
144 folder = project.getFolder(TmfExperimentFolder.EXPER_FOLDER_NAME);
145 if (!folder.exists())
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())
152 folder.create(true, true, null);
153
154 return project;
155 } catch (CoreException e) {
156 Activator.getDefault().logError("Error creating TMF project " + project.getName(), e); //$NON-NLS-1$
157 }
158 return null;
159 }
160
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
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 }
This page took 0.038411 seconds and 6 git commands to generate.