1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Marc-Andre Laperle - Initial API and implementation
11 * Patrick Tasse - Add support for folder elements
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
;
16 import org
.eclipse
.core
.resources
.IProject
;
17 import org
.eclipse
.jface
.viewers
.ISelection
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.ITmfProjectModelElement
;
20 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceFolder
;
23 * Utility methods for handlers
25 * @author Marc-Andre Laperle
27 public class TmfHandlerUtil
{
30 * Get the enclosing project from the selection
35 * @return the enclosing project or null if selection is no enclosed by a
38 public static IProject
getProjectFromSelection(ISelection selection
) {
39 if (selection
instanceof IStructuredSelection
) {
40 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
41 Object firstElement
= structuredSelection
.getFirstElement();
42 if (firstElement
instanceof ITmfProjectModelElement
) {
43 ITmfProjectModelElement tmfProjectElement
= (ITmfProjectModelElement
) firstElement
;
44 return tmfProjectElement
.getProject().getResource();
52 * Get the trace folder from the selection
57 * @return the enclosing project or null if selection is no enclosed by a
60 public static TmfTraceFolder
getTraceFolderFromSelection(ISelection selection
) {
61 if (selection
instanceof IStructuredSelection
) {
62 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
63 Object firstElement
= structuredSelection
.getFirstElement();
64 if (firstElement
instanceof ITmfProjectModelElement
) {
65 ITmfProjectModelElement element
= (ITmfProjectModelElement
) firstElement
;
66 while (element
!= null) {
67 if (element
instanceof TmfTraceFolder
) {
68 return (TmfTraceFolder
) element
;
70 element
= element
.getParent();