1 /*******************************************************************************
2 * Copyright (c) 2009 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
.views
.project
.dialogs
;
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
.IProgressMonitor
;
26 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.internal
.Messages
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.TmfProjectNature
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.model
.TmfProjectNode
;
31 import org
.eclipse
.ui
.wizards
.newresource
.BasicNewResourceWizard
;
34 * <b><u>NewProjectWizard</u></b>
36 * TODO: Implement me. Please.
38 public class NewProjectWizard
extends BasicNewResourceWizard
{
40 private String fTtitle
;
41 private String fDescription
;
43 protected NewProjectMainWizardPage fMainPage
;
44 protected String fProjectName
;
45 protected URI fProjectLocation
;
46 protected IConfigurationElement fConfigElement
;
48 protected IProject fProject
;
53 public NewProjectWizard() {
54 this(Messages
.NewProjectWizard_DialogHeader
, Messages
.NewProjectWizard_DialogMessage
);
61 public NewProjectWizard(String title
, String desc
) {
63 setDialogSettings(TmfUiPlugin
.getDefault().getDialogSettings());
64 setNeedsProgressMonitor(true);
65 setForcePreviousAndNextButtons(true);
66 setWindowTitle(title
);
72 * @see org.eclipse.jface.wizard.Wizard#addPages()
75 public void addPages() {
76 fMainPage
= new NewProjectMainWizardPage(Messages
.NewProjectWizard_DialogHeader
);
77 fMainPage
.setTitle(fTtitle
);
78 fMainPage
.setDescription(fDescription
);
83 * @see org.eclipse.jface.wizard.Wizard#performCancel()
86 public boolean performCancel() {
91 * @see org.eclipse.jface.wizard.Wizard#performFinish()
94 public boolean performFinish() {
95 fProjectName
= fMainPage
.getProjectName();
96 fProjectLocation
= fMainPage
.useDefaults() ?
null : fMainPage
.getLocationURI();
97 fProject
= createProject(fProjectName
, fProjectLocation
, new NullProgressMonitor());
101 public IProject
getProject() {
107 * @param projectLocation
111 private IProject
createProject(String projectName
, URI projectLocation
, IProgressMonitor monitor
) {
113 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
114 IWorkspaceRoot root
= workspace
.getRoot();
115 IProject project
= root
.getProject(projectName
);
118 if (!project
.exists()) {
119 IProjectDescription description
= workspace
.newProjectDescription(project
.getName());
120 if (projectLocation
!= null)
121 description
.setLocationURI(projectLocation
);
122 project
.create(description
, monitor
);
125 if (!project
.isOpen())
126 project
.open(monitor
);
128 IProjectDescription description
= project
.getDescription();
129 description
.setNatureIds(new String
[] { TmfProjectNature
.ID
} );
130 project
.setDescription(description
, null);
132 IFolder folder
= project
.getFolder(TmfProjectNode
.TRACE_FOLDER_NAME
);
133 if (!folder
.exists())
134 folder
.create(true, true, null);
136 folder
= project
.getFolder(TmfProjectNode
.EXPER_FOLDER_NAME
);
137 if (!folder
.exists())
138 folder
.create(true, true, null);
142 catch (CoreException e
) {