1 /*******************************************************************************
2 * Copyright (c) 2009, 2011 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.wizards
;
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
;
40 * <b><u>NewTmfProjectWizard</u></b>
43 public class NewTmfProjectWizard
extends Wizard
implements INewWizard
, IExecutableExtension
{
45 private final String fTtitle
;
46 private final String fDescription
;
48 protected NewTmfProjectMainWizardPage fMainPage
;
49 protected String fProjectName
;
50 protected URI fProjectLocation
;
51 protected IConfigurationElement fConfigElement
;
53 protected IProject fProject
;
58 public NewTmfProjectWizard() {
59 this(Messages
.NewProjectWizard_DialogHeader
, Messages
.NewProjectWizard_DialogMessage
);
66 public NewTmfProjectWizard(String title
, String desc
) {
68 setDialogSettings(Activator
.getDefault().getDialogSettings());
69 setNeedsProgressMonitor(true);
70 setForcePreviousAndNextButtons(true);
71 setWindowTitle(title
);
79 * @see org.eclipse.jface.wizard.Wizard#addPages()
82 public void addPages() {
83 fMainPage
= new NewTmfProjectMainWizardPage(Messages
.NewProjectWizard_DialogHeader
);
84 fMainPage
.setTitle(fTtitle
);
85 fMainPage
.setDescription(fDescription
);
92 * @see org.eclipse.jface.wizard.Wizard#performCancel()
95 public boolean performCancel() {
102 * @see org.eclipse.jface.wizard.Wizard#performFinish()
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
);
115 * @param projectLocation
119 private IProject
createProject(String projectName
, URI projectLocation
, IProgressMonitor monitor
) {
121 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
122 IWorkspaceRoot root
= workspace
.getRoot();
123 IProject project
= root
.getProject(projectName
);
126 if (!project
.exists()) {
127 IProjectDescription description
= workspace
.newProjectDescription(project
.getName());
128 if (projectLocation
!= null)
129 description
.setLocationURI(projectLocation
);
130 project
.create(description
, monitor
);
133 if (!project
.isOpen())
134 project
.open(monitor
);
136 IProjectDescription description
= project
.getDescription();
137 description
.setNatureIds(new String
[] { TmfProjectNature
.ID
});
138 project
.setDescription(description
, null);
140 IFolder folder
= project
.getFolder(TmfTraceFolder
.TRACE_FOLDER_NAME
);
141 if (!folder
.exists())
142 folder
.create(true, true, null);
144 folder
= project
.getFolder(TmfExperimentFolder
.EXPER_FOLDER_NAME
);
145 if (!folder
.exists())
146 folder
.create(true, true, null);
148 // create folder for supplementary tracing files
149 folder
= project
.getFolder(TmfCommonConstants
.TRACE_SUPPLEMENATARY_FOLDER_NAME
);
151 if (!folder
.exists())
152 folder
.create(true, true, null);
155 } catch (CoreException e
) {
156 Activator
.getDefault().logError("Error creating TMF project " + project
.getName(), e
); //$NON-NLS-1$
161 // ------------------------------------------------------------------------
163 // ------------------------------------------------------------------------
166 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
169 public void init(IWorkbench iworkbench
, IStructuredSelection istructuredselection
) {
172 // ------------------------------------------------------------------------
173 // IExecutableExtension
174 // ------------------------------------------------------------------------
177 public void setInitializationData(IConfigurationElement config
, String propertyName
, Object data
) throws CoreException
{
178 fConfigElement
= config
;