/*******************************************************************************
- * Copyright (c) 2009, 2011 Ericsson
+ * Copyright (c) 2009, 2013 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
*
* Contributors:
* Francois Chouinard - Initial API and implementation
+ * Bernd Hufmann - Moved project creation utility method to TmfProjectRegistry
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.wizards;
import java.net.URI;
-import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
-import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
-import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder;
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
// Wizard
// ------------------------------------------------------------------------
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.wizard.Wizard#addPages()
- */
@Override
public void addPages() {
fMainPage = new NewTmfProjectMainWizardPage(Messages.NewProjectWizard_DialogHeader);
addPage(fMainPage);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.wizard.Wizard#performCancel()
- */
@Override
public boolean performCancel() {
return true;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.wizard.Wizard#performFinish()
- */
@Override
public boolean performFinish() {
fProjectName = fMainPage.getProjectName();
fProjectLocation = fMainPage.useDefaults() ? null : fMainPage.getLocationURI();
- fProject = createProject(fProjectName, fProjectLocation, new NullProgressMonitor());
+ fProject = TmfProjectRegistry.createProject(fProjectName, fProjectLocation, new NullProgressMonitor());
BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
return true;
}
- private static IProject createProject(String projectName, URI projectLocation, IProgressMonitor monitor) {
-
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IWorkspaceRoot root = workspace.getRoot();
- IProject project = root.getProject(projectName);
-
- try {
- if (!project.exists()) {
- IProjectDescription description = workspace.newProjectDescription(project.getName());
- if (projectLocation != null) {
- description.setLocationURI(projectLocation);
- }
- project.create(description, monitor);
- }
-
- if (!project.isOpen()) {
- project.open(monitor);
- }
-
- IProjectDescription description = project.getDescription();
- description.setNatureIds(new String[] { TmfProjectNature.ID });
- project.setDescription(description, null);
-
- IFolder folder = project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME);
- if (!folder.exists()) {
- folder.create(true, true, null);
- }
-
- folder = project.getFolder(TmfExperimentFolder.EXPER_FOLDER_NAME);
- if (!folder.exists()) {
- folder.create(true, true, null);
- }
-
- // create folder for supplementary tracing files
- folder = project.getFolder(TmfCommonConstants.TRACE_SUPPLEMENATARY_FOLDER_NAME);
-
- if (!folder.exists()) {
- folder.create(true, true, null);
- }
-
- return project;
- } catch (CoreException e) {
- Activator.getDefault().logError("Error creating TMF project " + project.getName(), e); //$NON-NLS-1$
- }
- return null;
- }
-
// ------------------------------------------------------------------------
// INewWizard
// ------------------------------------------------------------------------
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
- */
@Override
public void init(IWorkbench iworkbench, IStructuredSelection istructuredselection) {
}
// IExecutableExtension
// ------------------------------------------------------------------------
- /*
- * (non-Javadoc)
- * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
- */
@Override
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
fConfigElement = config;