tmf: Use a common method to get opened tmf projects
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / model / TraceUtils.java
index ba5dce5dc7cd342f240e28f313cbf287437f4c6c..2fe7b859a13002e7a89749726adb8de8e375119c 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 École Polytechnique de Montréal
+ * Copyright (c) 2013 École Polytechnique de Montréal and others
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,10 +8,19 @@
  *
  * Contributors:
  *   Geneviève Bastien - Initial API and implementation
+ *   Marc-Andre Laperle - Add method to get opened tmf projects
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.project.model;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.ui.PlatformUI;
@@ -42,4 +51,25 @@ public class TraceUtils {
             }
         });
     }
+
+    /**
+     * Get the opened (accessible) projects with Tmf nature
+     *
+     * @return the Tmf projects
+     * @since 2.2
+     */
+    public static List<IProject> getOpenedTmfProjects() {
+        IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+        List<IProject> tmfProjects = new ArrayList<IProject>();
+        for (IProject project : projects) {
+            try {
+                if (project.isAccessible() && project.getNature(TmfProjectNature.ID) != null) {
+                    tmfProjects.add(project);
+                }
+            } catch (CoreException e) {
+                Activator.getDefault().logError("Error getting opened tmf projects", e); //$NON-NLS-1$
+            }
+        }
+        return tmfProjects;
+    }
 }
This page took 0.025098 seconds and 5 git commands to generate.