summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobAction.java
diff options
context:
space:
mode:
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.java84
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 *******************************************************************************/
11package org.yocto.bc.ui.actions;
12
13import org.eclipse.ui.PlatformUI;
14import org.eclipse.ui.IWorkbench;
15import org.eclipse.ui.IWorkbenchPage;
16import org.eclipse.ui.IWorkbenchWindow;
17
18import org.eclipse.core.resources.IProject;
19import org.eclipse.core.resources.IResource;
20import org.eclipse.core.runtime.IAdaptable;
21import org.eclipse.jface.action.IAction;
22import org.eclipse.jface.viewers.ISelection;
23import org.eclipse.jface.viewers.IStructuredSelection;
24
25import org.eclipse.swt.widgets.Shell;
26
27import org.yocto.bc.ui.builder.BitbakeCommanderNature;
28
29
30public 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}