summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions')
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/AbstractBitbakeCommandAction.java199
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeBuildRecipeAction.java24
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeCleanRecipeAction.java26
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeImportAction.java106
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeRebuildRecipeAction.java29
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobAction.java84
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobDialog.java328
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobHandler.java50
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewBitBakeProjectWizardAction.java48
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewRecipeWizardAction.java48
-rw-r--r--plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchVariableWizardAction.java78
11 files changed, 1020 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/AbstractBitbakeCommandAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/AbstractBitbakeCommandAction.java
new file mode 100644
index 0000000..41d5c73
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/AbstractBitbakeCommandAction.java
@@ -0,0 +1,199 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
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 *******************************************************************************/
11package org.yocto.bc.ui.actions;
12
13import java.io.IOException;
14
15import org.eclipse.core.resources.IFile;
16import org.eclipse.core.resources.IProject;
17import org.eclipse.core.runtime.CoreException;
18import org.eclipse.core.runtime.IProgressMonitor;
19import org.eclipse.core.runtime.IStatus;
20import org.eclipse.core.runtime.Status;
21import org.eclipse.core.runtime.jobs.Job;
22import org.eclipse.jface.action.IAction;
23import org.eclipse.jface.preference.JFacePreferences;
24import org.eclipse.jface.resource.JFaceResources;
25import org.eclipse.jface.viewers.ISelection;
26import org.eclipse.jface.viewers.IStructuredSelection;
27import org.eclipse.swt.graphics.Color;
28import org.eclipse.ui.IWorkbenchWindow;
29import org.eclipse.ui.IWorkbenchWindowActionDelegate;
30import org.eclipse.ui.console.MessageConsole;
31import org.eclipse.ui.console.MessageConsoleStream;
32
33import org.yocto.bc.bitbake.BBLanguageHelper;
34import org.yocto.bc.bitbake.BBSession;
35import org.yocto.bc.bitbake.ICommandResponseHandler;
36import org.yocto.bc.ui.Activator;
37import org.yocto.bc.ui.builder.BitbakeCommanderNature;
38
39public abstract class AbstractBitbakeCommandAction implements IWorkbenchWindowActionDelegate {
40
41 private class CommandJob extends Job {
42
43 public CommandJob() {
44 super(getJobTitle());
45 }
46
47 @Override
48 protected IStatus run(IProgressMonitor monitor) {
49 String cmds[] = getCommands();
50 return execCommands(cmds, monitor);
51 }
52
53 }
54 protected IAction action;
55 protected IFile recipe;
56 protected BBSession bbs;
57
58 private Color commandColor, responseColor, errorColor;
59 private boolean errorOccurred = false;
60
61 public AbstractBitbakeCommandAction() {
62 commandColor = JFaceResources.getColorRegistry().get(JFacePreferences.ACTIVE_HYPERLINK_COLOR);
63 responseColor = JFaceResources.getColorRegistry().get(JFacePreferences.HYPERLINK_COLOR);
64 errorColor = JFaceResources.getColorRegistry().get(JFacePreferences.ERROR_COLOR);
65 }
66
67 private void checkEnabled(IFile file) {
68 try {
69 if (file.getFileExtension() == null || !file.getFileExtension().equals(BBLanguageHelper.BITBAKE_RECIPE_FILE_EXTENSION)) {
70 action.setEnabled(false);
71 return;
72 }
73
74 IProject project = file.getProject();
75 if (!(project.hasNature(BitbakeCommanderNature.NATURE_ID))) {
76 action.setEnabled(false);
77 return;
78 }
79
80 bbs = Activator.getBBSession(project.getLocationURI().getPath());
81
82 if (bbs != null) {
83 recipe = file;
84 action.setEnabled(true);
85 }
86
87 } catch (CoreException e) {
88 action.setEnabled(false);
89 e.printStackTrace();
90 } catch (Exception e) {
91 action.setEnabled(false);
92 e.printStackTrace();
93 }
94 }
95
96 public void dispose() {
97 }
98
99 /**
100 * Execute array of commands with bitbake and put output in console.
101 *
102 * @param cmds
103 * @param monitor
104 * @return
105 */
106 protected IStatus execCommands(String[] cmds, final IProgressMonitor monitor) {
107 MessageConsole mc = bbs.getConsole();
108 final MessageConsoleStream cmd = mc.newMessageStream();
109 cmd.setColor(commandColor);
110 final MessageConsoleStream out = mc.newMessageStream();
111 final MessageConsoleStream err = mc.newMessageStream();
112 err.setColor(errorColor);
113
114 try {
115 for (int i = 0; i < cmds.length; ++i) {
116 cmd.println(cmds[i]);
117 monitor.subTask(cmds[i]);
118 bbs.getShell().execute(cmds[i], new ICommandResponseHandler() {
119
120 public void response(String line, boolean isError) {
121 if (monitor.isCanceled()) {
122 cmd.println("Interrupting process by user request.");
123 bbs.getShell().interrupt();
124 }
125
126 if (isError) {
127 err.println(line);
128 errorOccurred();
129 } else if (line.startsWith("ERROR:")) {
130 err.println(line);
131 } else {
132 out.println(line);
133 }
134 }
135 });
136 }
137 } catch (IOException e) {
138 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
139 } finally {
140 try {
141 if (errorOccurred) {
142 cmd.println("At least one error occured while executing this command. Check output for more details.");
143 }
144 cmd.close();
145 out.close();
146 err.close();
147 } catch (IOException e) {
148 e.printStackTrace();
149 }
150 }
151
152 return Status.OK_STATUS;
153 }
154
155 protected void errorOccurred() {
156 errorOccurred = true;
157 }
158
159 /**
160 * Return the command to be executed.
161 *
162 * @return
163 */
164 public abstract String[] getCommands();
165
166 public Job getJob() {
167 return new CommandJob();
168 }
169
170 /**
171 * Return the title of the job.
172 *
173 * @return
174 */
175 public abstract String getJobTitle();
176
177 public void init(IWorkbenchWindow window) {
178 }
179
180 public void run(IAction action) {
181 Job job = getJob();
182 job.schedule();
183 }
184
185 public void selectionChanged(IAction action, ISelection selection) {
186 this.action = action;
187 if (selection instanceof IStructuredSelection) {
188 Object sel = ((IStructuredSelection) selection).getFirstElement();
189
190 if (sel instanceof IFile) {
191 checkEnabled((IFile) sel);
192 return;
193 }
194 }
195
196 action.setEnabled(false);
197 }
198
199} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeBuildRecipeAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeBuildRecipeAction.java
new file mode 100644
index 0000000..22ac94c
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeBuildRecipeAction.java
@@ -0,0 +1,24 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
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 *******************************************************************************/
11package org.yocto.bc.ui.actions;
12
13public class BitbakeBuildRecipeAction extends AbstractBitbakeCommandAction {
14
15 @Override
16 public String [] getCommands() {
17 return new String[] {"bitbake -b " + recipe.getLocationURI().getPath()};
18 }
19
20 @Override
21 public String getJobTitle() {
22 return "Building " + recipe.getName();
23 }
24} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeCleanRecipeAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeCleanRecipeAction.java
new file mode 100644
index 0000000..f95117e
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeCleanRecipeAction.java
@@ -0,0 +1,26 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
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 *******************************************************************************/
11package org.yocto.bc.ui.actions;
12
13public class BitbakeCleanRecipeAction extends AbstractBitbakeCommandAction {
14
15 @Override
16 public String [] getCommands() {
17 return new String[] {"bitbake -c clean -b " + recipe.getLocationURI().getPath()};
18 }
19
20 @Override
21 public String getJobTitle() {
22 return "Cleaning " + recipe.getName();
23 }
24
25
26} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeImportAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeImportAction.java
new file mode 100644
index 0000000..ecceecf
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeImportAction.java
@@ -0,0 +1,106 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
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 *******************************************************************************/
11package org.yocto.bc.ui.actions;
12
13import java.io.File;
14
15import org.eclipse.core.resources.IProject;
16import org.eclipse.core.resources.IProjectDescription;
17import org.eclipse.core.resources.IResource;
18import org.eclipse.core.resources.IWorkspaceRoot;
19import org.eclipse.core.resources.ResourcesPlugin;
20import org.eclipse.core.runtime.IProgressMonitor;
21import org.eclipse.core.runtime.IStatus;
22import org.eclipse.core.runtime.Status;
23import org.eclipse.core.runtime.jobs.Job;
24
25import org.yocto.bc.bitbake.BBCommonVars;
26import org.yocto.bc.bitbake.BBRecipe;
27import org.yocto.bc.ui.Activator;
28
29public class BitbakeImportAction extends AbstractBitbakeCommandAction {
30
31 private class ImportJob extends Job {
32
33 public ImportJob() {
34 super(getJobTitle());
35 }
36
37 @Override
38 protected IStatus run(IProgressMonitor monitor) {
39
40 try {
41 BBRecipe br = new BBRecipe(bbs, recipe.getLocationURI().getPath());
42 br.initialize();
43 String filePath = (String) br.get(BBCommonVars.S);
44
45 //"${WORKDIR}/${PN}-${PV}"
46 if (filePath == null) {
47 filePath = ((String) br.get(BBCommonVars.WORKDIR)) + File.separator + ((String) br.get(BBCommonVars.PN)) + "-" + ((String) br.get(BBCommonVars.PV));
48 }
49
50 String projectName = (String) br.get(BBCommonVars.PN);
51
52 if (filePath == null || projectName == null) {
53 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to parse recipe file.");
54 }
55
56 File workdir = new File(filePath);
57
58 if (workdir.exists() && workdir.isFile()) {
59 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, workdir.getPath() + " is an invalid workdir.");
60 }
61
62 if (!workdir.exists()) {
63 execCommands(new String[] {"bitbake -c patch -b " + recipe.getLocationURI().getPath()}, monitor);
64 }
65
66 if (!workdir.exists()) {
67 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to retrieve sources from BitBake. Consult console.");
68 }
69
70 IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
71 IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
72 IProject proj = wsroot.getProject(projectName);
73 proj.create(desc, monitor);
74 proj.open(monitor);
75
76 String copyCmd = "cp -r " + workdir.getAbsolutePath() + File.separator + "* \"" + proj.getLocationURI().getPath() + "\"";
77 execCommands(new String[] {copyCmd} , monitor);
78
79 proj.refreshLocal(IResource.DEPTH_INFINITE, monitor);
80
81 } catch (Exception e) {
82 e.printStackTrace();
83 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to create project.", e);
84 }
85
86 return Status.OK_STATUS;
87 }
88
89 }
90
91 @Override
92 public String [] getCommands() {
93 return null;
94 }
95
96
97 @Override
98 public Job getJob() {
99 return new ImportJob();
100 }
101
102 @Override
103 public String getJobTitle() {
104 return "Importing " + recipe.getName();
105 }
106} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeRebuildRecipeAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeRebuildRecipeAction.java
new file mode 100644
index 0000000..c5dedea
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/BitbakeRebuildRecipeAction.java
@@ -0,0 +1,29 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
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 *******************************************************************************/
11package org.yocto.bc.ui.actions;
12
13/**
14 * Rebuild a recipe.
15 * @author kgilmer
16 *
17 */
18public class BitbakeRebuildRecipeAction extends AbstractBitbakeCommandAction {
19
20 @Override
21 public String [] getCommands() {
22 return new String[] {"bitbake -c rebuild -b " + recipe.getLocationURI().getPath()};
23 }
24
25 @Override
26 public String getJobTitle() {
27 return "Rebuilding " + recipe.getName();
28 }
29} \ No newline at end of file
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}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobDialog.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobDialog.java
new file mode 100644
index 0000000..861360d
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobDialog.java
@@ -0,0 +1,328 @@
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 java.util.Map;
14import java.util.Iterator;
15import java.util.Map.Entry;
16import java.util.ArrayList;
17import java.util.HashMap;
18import java.util.HashSet;
19import java.io.File;
20import java.io.IOException;
21
22import org.eclipse.jface.dialogs.Dialog;
23import org.eclipse.jface.dialogs.IDialogConstants;
24
25import org.eclipse.swt.SWT;
26import org.eclipse.swt.events.ModifyEvent;
27import org.eclipse.swt.events.ModifyListener;
28import org.eclipse.swt.events.SelectionAdapter;
29import org.eclipse.swt.events.SelectionEvent;
30import org.eclipse.swt.events.SelectionListener;
31import org.eclipse.swt.layout.GridData;
32import org.eclipse.swt.layout.GridLayout;
33import org.eclipse.swt.widgets.Button;
34import org.eclipse.swt.widgets.Combo;
35import org.eclipse.swt.widgets.Composite;
36import org.eclipse.swt.widgets.Control;
37import org.eclipse.swt.widgets.DirectoryDialog;
38import org.eclipse.swt.widgets.Display;
39import org.eclipse.swt.widgets.Label;
40import org.eclipse.swt.widgets.MessageBox;
41import org.eclipse.swt.widgets.Shell;
42import org.eclipse.swt.widgets.Widget;
43
44import org.eclipse.core.resources.IProject;
45import org.eclipse.core.resources.IProjectDescription;
46import org.eclipse.core.resources.ICommand;
47
48import org.yocto.bc.ui.builder.BitbakeBuilder;
49import org.yocto.bc.ui.builder.BitbakeCommanderNature;
50
51public class LaunchHobDialog extends Dialog {
52 private String title;
53 private Button buildButton;
54 private SelectionListener fSelectionListener;
55 private ModifyListener fModifyListener;
56 private Combo build_dir_combo;
57
58 private IProject project;
59 private Shell shell;
60 private String build_dir;
61
62 public LaunchHobDialog(Shell parentShell, String dialogTitle, IProject project) {
63 super(parentShell);
64 this.shell = parentShell;
65 this.project = project;
66 this.title = dialogTitle;
67 setShellStyle(getShellStyle() | SWT.RESIZE);
68
69 fSelectionListener= new SelectionListener() {
70 public void widgetDefaultSelected(SelectionEvent e) {}
71
72 public void widgetSelected(SelectionEvent e) {
73 controlChanged(e.widget);
74 }
75 };
76
77 fModifyListener= new ModifyListener() {
78 public void modifyText(ModifyEvent e) {
79 controlModified(e.widget);
80 }
81 };
82
83 }
84
85 public String getBuildDir() {
86 return build_dir;
87 }
88 @Override
89 protected Control createDialogArea(Composite parent) {
90 final Composite result = (Composite) super.createDialogArea(parent);
91
92 try {
93 createComposite(result);
94 } catch (Exception e) {
95 // TODO Auto-generated catch block
96 System.out.println("Have you ever set the project specific Yocto Settings?");
97 System.out.println(e.getMessage());
98 }
99
100 return result;
101 }
102
103 private void createComposite(Composite composite) throws Exception{
104 Label root_label, sysroot_label;
105
106 GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
107 GridLayout layout = new GridLayout(2, false);
108 composite.setLayout(layout);
109
110 gd= new GridData(SWT.FILL, SWT.CENTER, true, false);
111 gd.horizontalSpan= 2;
112 composite.setLayoutData(gd);
113
114 Label build_dir_label = new Label(composite, SWT.NONE);
115 build_dir_label.setText("Bitbake build directory: ");
116 Composite textContainer = new Composite(composite, SWT.NONE);
117 textContainer.setLayout(new GridLayout(2, false));
118 textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
119
120 build_dir_combo = new Combo(textContainer, SWT.DROP_DOWN);
121 build_dir_combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
122 initializeBuildCombo();
123
124 Button buildButton = addDirSelectButton(textContainer, build_dir_combo);
125
126 //we add the listener at the end for avoiding the useless event trigger when control
127 //changed or modified.
128 buildButton.addSelectionListener(fSelectionListener);
129 build_dir_combo.addModifyListener(fModifyListener);
130 }
131
132 private Button addDirSelectButton(final Composite parent, final Combo combo) {
133 Button button = new Button(parent, SWT.PUSH | SWT.LEAD);
134 button.setText("Browse");
135 button.addSelectionListener(new SelectionAdapter() {
136 @Override
137 public void widgetSelected(SelectionEvent event) {
138 String dirName = new DirectoryDialog(parent.getShell()).open();
139
140 if (dirName != null) {
141 combo.add(dirName);
142 combo.setText(dirName);
143 }
144 }
145 });
146 return button;
147 }
148 @Override
149 protected void configureShell(Shell newShell) {
150 super.configureShell(newShell);
151 newShell.setText(title);
152 }
153
154 protected void buttonPressed(int buttonId) {
155 if (buttonId == IDialogConstants.OK_ID) {
156 try {
157 build_dir = build_dir_combo.getText().toString();
158 updateBuildSpec(build_dir);
159 super.buttonPressed(buttonId);
160 } catch (Exception e) {
161 // TODO Auto-generated catch block
162 System.out.println(e.getMessage());
163 }
164 }
165 else if (buttonId == IDialogConstants.CANCEL_ID)
166 {
167 super.buttonPressed(buttonId);
168 }
169 }
170
171 private boolean validateInput() {
172 boolean valid = false;
173 String build_dir = build_dir_combo.getText().toString();
174 if ((build_dir == null) || build_dir.isEmpty()) {
175 Display display = Display.getCurrent();
176 Shell shell = new Shell(display);
177 MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
178 msgBox.setText("Yocto Configuration Error");
179 msgBox.setMessage("The specified build directory is empty!");
180 msgBox.open();
181 if (shell != null)
182 shell.dispose();
183 return valid;
184 }
185 String project_path = project.getLocation().toString();
186 File project_dir_file = new File(project_path);
187 File build_dir_file = new File(build_dir);
188 try {
189 if (isSubDirectory(project_dir_file, build_dir_file)) {
190 Display display = Display.getCurrent();
191 Shell shell = new Shell(display);
192 MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
193 msgBox.setText("Yocto Configuration Error");
194 msgBox.setMessage("The specified build directory is a sub-dir of project path: " + project_path);
195 msgBox.open();
196 if (shell != null)
197 shell.dispose();
198 } else
199 valid = true;
200 } catch (IOException e) {
201 System.out.println(e.getMessage());
202 }
203 return valid;
204 }
205
206 private boolean isSubDirectory(File baseDir, File subDir) throws IOException {
207 baseDir = baseDir.getCanonicalFile();
208 subDir = subDir.getCanonicalFile();
209
210 File parentFile = subDir;
211 while (parentFile != null) {
212 if (baseDir.equals(parentFile)) {
213 return true;
214 }
215 parentFile = parentFile.getParentFile();
216 }
217 return false;
218 }
219
220 private void controlChanged(Widget widget) {
221
222 if (widget == buildButton)
223 {
224 }
225 }
226
227 private void controlModified(Widget widget) {
228 if (widget == build_dir_combo)
229 {
230
231 }
232 }
233
234 private void initializeBuildCombo()
235 {
236 ArrayList<String> items = new ArrayList<String> ();
237
238 try {
239 IProjectDescription desc = project.getDescription();
240
241 ICommand[] buildSpec = desc.getBuildSpec();
242 if ((buildSpec != null) && (buildSpec.length != 0))
243 {
244 for (int i = 0; i < buildSpec.length; i++) {
245 ICommand cmd = buildSpec[i];
246 if (cmd.getBuilderName().equalsIgnoreCase(BitbakeBuilder.HOB_BUILD_ID))
247 {
248 Map<String, String> args = cmd.getArguments();
249 if ((args != null) && !args.isEmpty())
250 {
251 Iterator entries = args.entrySet().iterator();
252 while (entries.hasNext()) {
253 Entry thisEntry = (Entry) entries.next();
254 String key = (String)thisEntry.getKey();
255 if (key.equalsIgnoreCase(BitbakeCommanderNature.BUILD_DIR_KEY)) {
256 build_dir_combo.removeAll();
257 build_dir_combo.setItems(getValues((String)thisEntry.getValue()));
258 }
259 }
260 }
261 }
262 }
263 }
264 } catch (Exception e) {
265 System.out.println(e.getMessage());
266 }
267 }
268
269 private String[] getValues(String value) {
270
271 if ((value != null) && !value.isEmpty())
272 {
273 String[] pieces = value.split(",");
274 for (int i = 0; i < pieces.length; i++)
275 {
276 int start = pieces[i].indexOf("[");
277 if (start >= 0)
278 pieces[i] = pieces[i].substring(start+1);
279 int end = pieces[i].indexOf("]");
280 if (end >= 0)
281 pieces[i] = pieces[i].substring(0, end);
282 pieces[i] = pieces[i].trim();
283 }
284 return pieces;
285 }
286 return null;
287 }
288
289 private void updateBuildSpec(String build_dir)
290 {
291 try {
292 String[] items = build_dir_combo.getItems();
293 HashSet values = new HashSet();
294 Map<String, String> args = new HashMap<String, String>();
295 values.add(build_dir);
296 for (int i = 0; i < items.length; i++) {
297 values.add(items[i]);
298 }
299 args.put(BitbakeCommanderNature.BUILD_DIR_KEY, values.toString());
300 IProjectDescription desc = project.getDescription();
301 ICommand[] buildSpec = desc.getBuildSpec();
302 boolean found = false;
303 if ((buildSpec != null) || (buildSpec.length != 0)) {
304 for (int i = 0; i < buildSpec.length; i++) {
305 ICommand cmd = buildSpec[i];
306 if (cmd.getBuilderName().equalsIgnoreCase(BitbakeBuilder.HOB_BUILD_ID)) {
307 cmd.setArguments(args);
308 desc.setBuildSpec(buildSpec);
309 found = true;
310 break;
311 }
312 }
313 }
314 if (!found) {
315 ICommand[] newBuildSpec = new ICommand[buildSpec.length + 1];
316 System.arraycopy(buildSpec, 0, newBuildSpec, 0, buildSpec.length);
317 ICommand cmd = desc.newCommand();
318 cmd.setBuilderName(BitbakeBuilder.HOB_BUILD_ID);
319 cmd.setArguments(args);
320 newBuildSpec[newBuildSpec.length - 1] = cmd;
321 desc.setBuildSpec(newBuildSpec);
322 }
323 project.setDescription(desc, null);
324 } catch (Exception e) {
325 System.out.println(e.getMessage());
326 }
327 }
328}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobHandler.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobHandler.java
new file mode 100644
index 0000000..002075a
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchHobHandler.java
@@ -0,0 +1,50 @@
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.core.commands.ExecutionEvent;
14import org.eclipse.core.commands.ExecutionException;
15import org.eclipse.core.commands.IHandlerListener;
16import org.eclipse.core.commands.IHandler;
17
18public class LaunchHobHandler implements IHandler {
19
20 public Object execute(ExecutionEvent event) throws ExecutionException {
21 LaunchHobAction a = new LaunchHobAction();
22 a.run(null);
23 return null;
24 }
25
26 public void addHandlerListener(IHandlerListener handlerListener) {
27 // TODO Auto-generated method stub
28
29 }
30
31 public void dispose() {
32 // TODO Auto-generated method stub
33
34 }
35
36 public boolean isEnabled() {
37 // TODO Auto-generated method stub
38 return true;
39 }
40
41 public boolean isHandled() {
42 // TODO Auto-generated method stub
43 return true;
44 }
45
46 public void removeHandlerListener(IHandlerListener handlerListener) {
47 // TODO Auto-generated method stub
48
49 }
50}
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewBitBakeProjectWizardAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewBitBakeProjectWizardAction.java
new file mode 100644
index 0000000..b8b3144
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewBitBakeProjectWizardAction.java
@@ -0,0 +1,48 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
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 *******************************************************************************/
11package org.yocto.bc.ui.actions;
12
13import org.eclipse.jface.action.IAction;
14import org.eclipse.jface.viewers.ISelection;
15import org.eclipse.jface.viewers.IStructuredSelection;
16import org.eclipse.jface.wizard.WizardDialog;
17import org.eclipse.ui.IWorkbenchWindow;
18import org.eclipse.ui.IWorkbenchWindowActionDelegate;
19
20import org.yocto.bc.ui.wizards.importProject.ImportYoctoProjectWizard;
21
22public class LaunchNewBitBakeProjectWizardAction implements IWorkbenchWindowActionDelegate {
23
24 private IWorkbenchWindow window;
25 private IStructuredSelection selection;
26
27 public void dispose() {
28 }
29
30 public void init(IWorkbenchWindow window) {
31 this.window = window;
32 }
33
34 public void run(IAction action) {
35 ImportYoctoProjectWizard wizard = new ImportYoctoProjectWizard();
36
37 wizard.init(window.getWorkbench(), selection);
38 WizardDialog wd = new WizardDialog(window.getShell(), wizard);
39 wd.create();
40 wd.open();
41 }
42
43 public void selectionChanged(IAction action, ISelection selection) {
44 if (selection instanceof IStructuredSelection) {
45 this.selection = (IStructuredSelection) selection;
46 }
47 }
48} \ No newline at end of file
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewRecipeWizardAction.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewRecipeWizardAction.java
new file mode 100644
index 0000000..d30d37b
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchNewRecipeWizardAction.java
@@ -0,0 +1,48 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
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 *******************************************************************************/
11package org.yocto.bc.ui.actions;
12
13import org.eclipse.jface.action.IAction;
14import org.eclipse.jface.viewers.ISelection;
15import org.eclipse.jface.viewers.IStructuredSelection;
16import org.eclipse.jface.wizard.WizardDialog;
17import org.eclipse.ui.IWorkbenchWindow;
18import org.eclipse.ui.IWorkbenchWindowActionDelegate;
19
20import org.yocto.bc.ui.wizards.NewBitBakeFileRecipeWizard;
21
22public class LaunchNewRecipeWizardAction implements IWorkbenchWindowActionDelegate {
23
24 private IWorkbenchWindow window;
25 private IStructuredSelection selection;
26
27 public void dispose() {
28 }
29
30 public void init(IWorkbenchWindow window) {
31 this.window = window;
32 }
33
34 public void run(IAction action) {
35 NewBitBakeFileRecipeWizard wizard = new NewBitBakeFileRecipeWizard();
36
37 wizard.init(window.getWorkbench(), selection);
38 WizardDialog wd = new WizardDialog(window.getShell(), wizard);
39 wd.create();
40 wd.open();
41 }
42
43 public void selectionChanged(IAction action, ISelection selection) {
44 if (selection instanceof IStructuredSelection) {
45 this.selection = (IStructuredSelection) selection;
46 }
47 }
48} \ No newline at end of file
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..eaf716e
--- /dev/null
+++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/actions/LaunchVariableWizardAction.java
@@ -0,0 +1,78 @@
1/*****************************************************************************
2 * Copyright (c) 2009 Ken Gilmer
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 *******************************************************************************/
11package org.yocto.bc.ui.actions;
12
13import java.io.IOException;
14import java.util.Map;
15
16import org.eclipse.core.resources.IProject;
17import org.eclipse.core.resources.IResource;
18import org.eclipse.core.runtime.CoreException;
19import org.eclipse.jface.action.IAction;
20import org.eclipse.jface.viewers.ISelection;
21import org.eclipse.jface.viewers.IStructuredSelection;
22import org.eclipse.jface.wizard.WizardDialog;
23import org.eclipse.ui.IWorkbenchWindow;
24import org.eclipse.ui.IWorkbenchWindowActionDelegate;
25
26import org.yocto.bc.ui.Activator;
27import org.yocto.bc.ui.builder.BitbakeCommanderNature;
28import org.yocto.bc.ui.wizards.variable.VariableWizard;
29
30/**
31 * Action to launch the Variable Wizard.
32 * @author kgilmer
33 *
34 */
35public class LaunchVariableWizardAction implements IWorkbenchWindowActionDelegate {
36
37 private IWorkbenchWindow window;
38 private Map session;
39
40 public void dispose() {
41 }
42
43 public void init(IWorkbenchWindow window) {
44 this.window = window;
45 }
46
47 public void run(IAction action) {
48 VariableWizard wizard = new VariableWizard(session);
49
50 WizardDialog wd = new WizardDialog(window.getShell(), wizard);
51 wd.create();
52 wd.open();
53 }
54
55 public void selectionChanged(IAction action, ISelection selection) {
56 session = null;
57
58 if (selection instanceof IStructuredSelection) {
59 Object element = ((IStructuredSelection)selection).getFirstElement();
60
61 if (element instanceof IResource) {
62 IProject p = ((IResource)element).getProject();
63
64 try {
65 if (p.isOpen() && p.hasNature(BitbakeCommanderNature.NATURE_ID)) {
66 session = Activator.getBBSession(((IResource)element).getProject().getLocationURI().getPath());
67 }
68 } catch (IOException e) {
69 e.printStackTrace();
70 } catch (CoreException e) {
71 e.printStackTrace();
72 }
73 }
74 }
75
76 action.setEnabled(session != null);
77 }
78} \ No newline at end of file