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
.TmfUiPlugin
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.TmfProjectNature
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentFolder
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceFolder
;
34 import org
.eclipse
.ui
.INewWizard
;
35 import org
.eclipse
.ui
.IWorkbench
;
36 import org
.eclipse
.ui
.wizards
.newresource
.BasicNewProjectResourceWizard
;
39 * <b><u>NewTmfProjectWizard</u></b>
42 public class NewTmfProjectWizard
extends Wizard
implements INewWizard
, IExecutableExtension
{
44 private final String fTtitle
;
45 private final String fDescription
;
47 protected NewTmfProjectMainWizardPage fMainPage
;
48 protected String fProjectName
;
49 protected URI fProjectLocation
;
50 protected IConfigurationElement fConfigElement
;
52 protected IProject fProject
;
57 public NewTmfProjectWizard() {
58 this(Messages
.NewProjectWizard_DialogHeader
, Messages
.NewProjectWizard_DialogMessage
);
65 public NewTmfProjectWizard(String title
, String desc
) {
67 setDialogSettings(TmfUiPlugin
.getDefault().getDialogSettings());
68 setNeedsProgressMonitor(true);
69 setForcePreviousAndNextButtons(true);
70 setWindowTitle(title
);
78 * @see org.eclipse.jface.wizard.Wizard#addPages()
81 public void addPages() {
82 fMainPage
= new NewTmfProjectMainWizardPage(Messages
.NewProjectWizard_DialogHeader
);
83 fMainPage
.setTitle(fTtitle
);
84 fMainPage
.setDescription(fDescription
);
91 * @see org.eclipse.jface.wizard.Wizard#performCancel()
94 public boolean performCancel() {
101 * @see org.eclipse.jface.wizard.Wizard#performFinish()
104 public boolean performFinish() {
105 fProjectName
= fMainPage
.getProjectName();
106 fProjectLocation
= fMainPage
.useDefaults() ?
null : fMainPage
.getLocationURI();
107 fProject
= createProject(fProjectName
, fProjectLocation
, new NullProgressMonitor());
108 BasicNewProjectResourceWizard
.updatePerspective(fConfigElement
);
114 * @param projectLocation
118 private IProject
createProject(String projectName
, URI projectLocation
, IProgressMonitor monitor
) {
120 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
121 IWorkspaceRoot root
= workspace
.getRoot();
122 IProject project
= root
.getProject(projectName
);
125 if (!project
.exists()) {
126 IProjectDescription description
= workspace
.newProjectDescription(project
.getName());
127 if (projectLocation
!= null)
128 description
.setLocationURI(projectLocation
);
129 project
.create(description
, monitor
);
132 if (!project
.isOpen())
133 project
.open(monitor
);
135 IProjectDescription description
= project
.getDescription();
136 description
.setNatureIds(new String
[] { TmfProjectNature
.ID
});
137 project
.setDescription(description
, null);
139 IFolder folder
= project
.getFolder(TmfTraceFolder
.TRACE_FOLDER_NAME
);
140 if (!folder
.exists())
141 folder
.create(true, true, null);
143 folder
= project
.getFolder(TmfExperimentFolder
.EXPER_FOLDER_NAME
);
144 if (!folder
.exists())
145 folder
.create(true, true, null);
148 } catch (CoreException e
) {
154 // ------------------------------------------------------------------------
156 // ------------------------------------------------------------------------
159 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
162 public void init(IWorkbench iworkbench
, IStructuredSelection istructuredselection
) {
165 // ------------------------------------------------------------------------
166 // IExecutableExtension
167 // ------------------------------------------------------------------------
170 public void setInitializationData(IConfigurationElement config
, String propertyName
, Object data
) throws CoreException
{
171 fConfigElement
= config
;