1 /** |
|
2 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 */ |
|
19 package org.symbian.tools.mtw.ui; |
|
20 |
|
21 import org.eclipse.core.commands.ExecutionEvent; |
|
22 import org.eclipse.core.resources.IProject; |
|
23 import org.eclipse.core.resources.IResource; |
|
24 import org.eclipse.core.runtime.IAdaptable; |
|
25 import org.eclipse.jface.viewers.ISelection; |
|
26 import org.eclipse.jface.viewers.IStructuredSelection; |
|
27 import org.eclipse.ui.IEditorPart; |
|
28 import org.eclipse.ui.IWorkbenchPart; |
|
29 import org.eclipse.ui.handlers.HandlerUtil; |
|
30 import org.symbian.tools.mtw.core.MTWCore; |
|
31 import org.symbian.tools.mtw.core.projects.IMTWProject; |
|
32 |
|
33 public class UIUtils { |
|
34 public static IMTWProject getProjectFromCommandContext(ExecutionEvent event) { |
|
35 IResource resource = null; |
|
36 IWorkbenchPart activePart = HandlerUtil.getActivePart(event); |
|
37 if (activePart instanceof IEditorPart) { |
|
38 resource = (IResource) ((IEditorPart) activePart).getEditorInput().getAdapter(IResource.class); |
|
39 } else { |
|
40 ISelection selection = HandlerUtil.getCurrentSelection(event); |
|
41 if (!selection.isEmpty() && selection instanceof IStructuredSelection) { |
|
42 Object[] array = ((IStructuredSelection) selection).toArray(); |
|
43 if (array.length == 1 && array[0] instanceof IAdaptable) { |
|
44 resource = (IResource) ((IAdaptable) array[0]).getAdapter(IResource.class); |
|
45 } |
|
46 } |
|
47 } |
|
48 if (resource != null) { |
|
49 IProject project = resource.getProject(); |
|
50 return MTWCore.getDefault().create(project); |
|
51 } |
|
52 return null; |
|
53 } |
|
54 } |
|