ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / wizards / NewTmfProjectWizard.java
index 0faf968695937f85e3cb87d553b55224d9aaffb6..85894718c28f1043ca867ab6c29950ef2d9a3abd 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * 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
@@ -8,30 +8,22 @@
  *
  * 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;
@@ -118,11 +110,6 @@ public class NewTmfProjectWizard extends Wizard implements INewWizard, IExecutab
     // Wizard
     // ------------------------------------------------------------------------
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.eclipse.jface.wizard.Wizard#addPages()
-     */
     @Override
     public void addPages() {
         fMainPage = new NewTmfProjectMainWizardPage(Messages.NewProjectWizard_DialogHeader);
@@ -131,84 +118,24 @@ public class NewTmfProjectWizard extends Wizard implements INewWizard, IExecutab
         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) {
     }
@@ -217,10 +144,6 @@ public class NewTmfProjectWizard extends Wizard implements INewWizard, IExecutab
     // 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;
This page took 0.025496 seconds and 5 git commands to generate.