diff options
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchVariableWizardAction.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchVariableWizardAction.java | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchVariableWizardAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchVariableWizardAction.java new file mode 100644 index 0000000..3104564 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchVariableWizardAction.java | |||
@@ -0,0 +1,89 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2013 Ken Gilmer, 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 | * Ken Gilmer - initial API and implementation | ||
10 | * Ioana Grigoropol (Intel) - adapt class for remote support | ||
11 | *******************************************************************************/ | ||
12 | package org.yocto.bc.ui.actions; | ||
13 | |||
14 | import java.io.IOException; | ||
15 | import java.lang.reflect.InvocationTargetException; | ||
16 | import java.util.Map; | ||
17 | |||
18 | import org.eclipse.core.resources.IProject; | ||
19 | import org.eclipse.core.resources.IResource; | ||
20 | import org.eclipse.core.runtime.CoreException; | ||
21 | import org.eclipse.core.runtime.NullProgressMonitor; | ||
22 | import org.eclipse.jface.action.IAction; | ||
23 | import org.eclipse.jface.viewers.ISelection; | ||
24 | import org.eclipse.jface.viewers.IStructuredSelection; | ||
25 | import org.eclipse.jface.wizard.WizardDialog; | ||
26 | import org.eclipse.ui.IWorkbenchWindow; | ||
27 | import org.eclipse.ui.IWorkbenchWindowActionDelegate; | ||
28 | import org.yocto.bc.ui.Activator; | ||
29 | import org.yocto.bc.ui.builder.BitbakeCommanderNature; | ||
30 | import org.yocto.bc.ui.model.ProjectInfo; | ||
31 | import org.yocto.bc.ui.wizards.variable.VariableWizard; | ||
32 | |||
33 | /** | ||
34 | * Action to launch the Variable Wizard. | ||
35 | * @author kgilmer | ||
36 | * | ||
37 | */ | ||
38 | public class LaunchVariableWizardAction implements IWorkbenchWindowActionDelegate { | ||
39 | |||
40 | private IWorkbenchWindow window; | ||
41 | private Map session; | ||
42 | |||
43 | public void dispose() { | ||
44 | } | ||
45 | |||
46 | public void init(IWorkbenchWindow window) { | ||
47 | this.window = window; | ||
48 | } | ||
49 | |||
50 | public void run(IAction action) { | ||
51 | VariableWizard wizard = new VariableWizard(session); | ||
52 | |||
53 | WizardDialog wd = new WizardDialog(window.getShell(), wizard); | ||
54 | wd.create(); | ||
55 | wd.open(); | ||
56 | } | ||
57 | |||
58 | public void selectionChanged(IAction action, ISelection selection) { | ||
59 | session = null; | ||
60 | |||
61 | if (selection instanceof IStructuredSelection) { | ||
62 | Object element = ((IStructuredSelection)selection).getFirstElement(); | ||
63 | |||
64 | if (element instanceof IResource) { | ||
65 | IProject p = ((IResource)element).getProject(); | ||
66 | |||
67 | try { | ||
68 | if (p.isAccessible() && p.isOpen() && p.hasNature(BitbakeCommanderNature.NATURE_ID)) { | ||
69 | IProject proj = ((IResource)element).getProject(); | ||
70 | ProjectInfo projInfo = Activator.getProjInfo(proj.getLocationURI()); | ||
71 | session = Activator.getBBSession(projInfo, new NullProgressMonitor()); | ||
72 | } | ||
73 | } catch (IOException e) { | ||
74 | e.printStackTrace(); | ||
75 | } catch (CoreException e) { | ||
76 | e.printStackTrace(); | ||
77 | } catch (InvocationTargetException e) { | ||
78 | e.printStackTrace(); | ||
79 | } catch (InterruptedException e) { | ||
80 | e.printStackTrace(); | ||
81 | } catch (Exception e) { | ||
82 | e.printStackTrace(); | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | |||
87 | action.setEnabled(session != null); | ||
88 | } | ||
89 | } | ||