diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:36:50 +0100 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 15:25:03 +0100 |
commit | 41ac47d732eed8392d60d0f6773e5a279d49b999 (patch) | |
tree | cf19d099db9cfdb8d73aa21c31e7aa1cc86ff860 /plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobAction.java | |
download | eclipse-poky-juno-41ac47d732eed8392d60d0f6773e5a279d49b999.tar.gz |
Migrated from the internal git server on the dora-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobAction.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobAction.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobAction.java new file mode 100644 index 0000000..e92fac0 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobAction.java | |||
@@ -0,0 +1,84 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2011 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.actions; | ||
12 | |||
13 | import org.eclipse.ui.PlatformUI; | ||
14 | import org.eclipse.ui.IWorkbench; | ||
15 | import org.eclipse.ui.IWorkbenchPage; | ||
16 | import org.eclipse.ui.IWorkbenchWindow; | ||
17 | |||
18 | import org.eclipse.core.resources.IProject; | ||
19 | import org.eclipse.core.resources.IResource; | ||
20 | import org.eclipse.core.runtime.IAdaptable; | ||
21 | import org.eclipse.jface.action.IAction; | ||
22 | import org.eclipse.jface.viewers.ISelection; | ||
23 | import org.eclipse.jface.viewers.IStructuredSelection; | ||
24 | |||
25 | import org.eclipse.swt.widgets.Shell; | ||
26 | |||
27 | import org.yocto.bc.ui.builder.BitbakeCommanderNature; | ||
28 | |||
29 | |||
30 | public class LaunchHobAction { | ||
31 | private static final String DIALOG_TITLE = "Launch HOB"; | ||
32 | |||
33 | public void run(IAction action) { | ||
34 | IResource resource = getSelectedResource(); | ||
35 | if (resource == null) | ||
36 | return; | ||
37 | |||
38 | IProject project = resource.getProject(); | ||
39 | LaunchHobDialog hobDialog = new LaunchHobDialog(new Shell(), DIALOG_TITLE, project); | ||
40 | hobDialog.open(); | ||
41 | String buildDir = hobDialog.getBuildDir(); | ||
42 | |||
43 | if (buildDir != null) { | ||
44 | try { | ||
45 | BitbakeCommanderNature.launchHob(project,buildDir); | ||
46 | } catch (Exception e){ | ||
47 | System.out.println(e.getMessage()); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | } | ||
52 | |||
53 | public void dispose() { | ||
54 | |||
55 | } | ||
56 | |||
57 | private IResource getSelectedResource() { | ||
58 | IWorkbench iworkbench = PlatformUI.getWorkbench(); | ||
59 | if (iworkbench == null){ | ||
60 | return null; | ||
61 | } | ||
62 | IWorkbenchWindow iworkbenchwindow = iworkbench.getActiveWorkbenchWindow(); | ||
63 | if (iworkbenchwindow == null) { | ||
64 | return null; | ||
65 | } | ||
66 | IWorkbenchPage iworkbenchpage = iworkbenchwindow.getActivePage(); | ||
67 | if (iworkbenchpage == null) { | ||
68 | return null; | ||
69 | } | ||
70 | ISelection sel = iworkbenchpage.getSelection(); | ||
71 | |||
72 | if (!(sel instanceof IStructuredSelection)) | ||
73 | return null; | ||
74 | IStructuredSelection ss = (IStructuredSelection) sel; | ||
75 | Object element = ss.getFirstElement(); | ||
76 | if (element instanceof IResource) | ||
77 | return (IResource) element; | ||
78 | if (!(element instanceof IAdaptable)) | ||
79 | return null; | ||
80 | IAdaptable adaptable = (IAdaptable)element; | ||
81 | Object adapter = adaptable.getAdapter(IResource.class); | ||
82 | return (IResource) adapter; | ||
83 | } | ||
84 | } | ||