summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchVariableWizardAction.java
diff options
context:
space:
mode:
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.java89
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 *******************************************************************************/
12package org.yocto.bc.ui.actions;
13
14import java.io.IOException;
15import java.lang.reflect.InvocationTargetException;
16import java.util.Map;
17
18import org.eclipse.core.resources.IProject;
19import org.eclipse.core.resources.IResource;
20import org.eclipse.core.runtime.CoreException;
21import org.eclipse.core.runtime.NullProgressMonitor;
22import org.eclipse.jface.action.IAction;
23import org.eclipse.jface.viewers.ISelection;
24import org.eclipse.jface.viewers.IStructuredSelection;
25import org.eclipse.jface.wizard.WizardDialog;
26import org.eclipse.ui.IWorkbenchWindow;
27import org.eclipse.ui.IWorkbenchWindowActionDelegate;
28import org.yocto.bc.ui.Activator;
29import org.yocto.bc.ui.builder.BitbakeCommanderNature;
30import org.yocto.bc.ui.model.ProjectInfo;
31import org.yocto.bc.ui.wizards.variable.VariableWizard;
32
33/**
34 * Action to launch the Variable Wizard.
35 * @author kgilmer
36 *
37 */
38public 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}