1 /*******************************************************************************
2 * Copyright (c) 2013 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.commands
;
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
;
21 * Utility methods for handlers
23 * @author Marc-Andre Laperle
25 public class TmfHandlerUtil
{
28 * Get the enclosing project from the selection
33 * @return the enclosing project or null if selection is no enclosed by a
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();