Merge branch 'master' into luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / commands / TmfHandlerUtil.java
1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.tmf.ui.commands;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.jface.viewers.ISelection;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement;
19
20 /**
21 * Utility methods for handlers
22 *
23 * @author Marc-Andre Laperle
24 */
25 public class TmfHandlerUtil {
26
27 /**
28 * Get the enclosing project from the selection
29 *
30 * @param selection
31 * the selection
32 *
33 * @return the enclosing project or null if selection is no enclosed by a
34 * project
35 */
36 public static IProject getProjectFromSelection(ISelection selection) {
37 if (selection instanceof IStructuredSelection) {
38 IStructuredSelection structuredSelection = (IStructuredSelection) selection;
39 Object firstElement = structuredSelection.getFirstElement();
40 if (firstElement instanceof ITmfProjectModelElement) {
41 ITmfProjectModelElement tmfProjectElement = (ITmfProjectModelElement) firstElement;
42 return tmfProjectElement.getProject().getResource();
43 }
44 }
45
46 return null;
47 }
48 }
This page took 0.037387 seconds and 6 git commands to generate.