/*******************************************************************************
- * 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
*
* Contributors:
* Marc-Andre Laperle - Initial API and implementation
+ * Patrick Tasse - Add support for folder elements
*******************************************************************************/
package org.eclipse.linuxtools.internal.tmf.ui.commands;
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
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;
+ }
}