ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / commands / TmfHandlerUtil.java
index cdc5a00b03c315e0f243941243d8daeb3aa4942b..ebfe2a49a67f17cf25495ec41952608753023af6 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 2014 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,6 +8,7 @@
  *
  * Contributors:
  *     Marc-Andre Laperle - Initial API and implementation
+ *     Patrick Tasse - Add support for folder elements
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.tmf.ui.commands;
@@ -16,6 +17,7 @@ import org.eclipse.core.resources.IProject;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
 
 /**
  * Utility methods for handlers
@@ -45,4 +47,30 @@ public class TmfHandlerUtil {
 
         return null;
     }
+
+    /**
+     * Get the trace folder from the selection
+     *
+     * @param selection
+     *            the selection
+     *
+     * @return the enclosing project or null if selection is no enclosed by a
+     *         project
+     */
+    public static TmfTraceFolder getTraceFolderFromSelection(ISelection selection) {
+        if (selection instanceof IStructuredSelection) {
+            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+            Object firstElement = structuredSelection.getFirstElement();
+            if (firstElement instanceof ITmfProjectModelElement) {
+                ITmfProjectModelElement element = (ITmfProjectModelElement) firstElement;
+                while (element != null) {
+                    if (element instanceof TmfTraceFolder) {
+                        return (TmfTraceFolder) element;
+                    }
+                    element = element.getParent();
+                }
+            }
+        }
+        return null;
+    }
 }
This page took 0.025512 seconds and 5 git commands to generate.