summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/PropertiesPage.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/PropertiesPage.java')
-rw-r--r--plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/PropertiesPage.java498
1 files changed, 498 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/PropertiesPage.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/PropertiesPage.java
new file mode 100644
index 0000000..18149e7
--- /dev/null
+++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/wizards/bsp/PropertiesPage.java
@@ -0,0 +1,498 @@
1/*******************************************************************************
2 * Copyright (c) 2012 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.sdk.remotetools.wizards.bsp;
12
13import java.util.ArrayList;
14import java.util.Collections;
15import java.util.Enumeration;
16import java.util.HashSet;
17import java.util.Hashtable;
18import java.util.Iterator;
19
20import org.eclipse.jface.dialogs.MessageDialog;
21import org.eclipse.jface.wizard.WizardPage;
22import org.eclipse.swt.SWT;
23import org.eclipse.swt.custom.ScrolledComposite;
24import org.eclipse.swt.events.SelectionEvent;
25import org.eclipse.swt.events.SelectionListener;
26import org.eclipse.swt.layout.GridData;
27import org.eclipse.swt.layout.GridLayout;
28import org.eclipse.swt.widgets.Button;
29import org.eclipse.swt.widgets.Combo;
30import org.eclipse.swt.widgets.Composite;
31import org.eclipse.swt.widgets.Control;
32import org.eclipse.swt.widgets.Group;
33import org.eclipse.swt.widgets.Label;
34import org.eclipse.swt.widgets.Text;
35import org.eclipse.swt.widgets.Widget;
36import org.yocto.sdk.remotetools.YoctoBspElement;
37import org.yocto.sdk.remotetools.YoctoBspPropertyElement;
38import org.yocto.sdk.remotetools.YoctoJSONHelper;
39/**
40 *
41 * Setting up the parameters for creating the new Yocto BSP
42 *
43 * @author jzhang
44 */
45public class PropertiesPage extends WizardPage {
46 private static final String PAGE_NAME = "Properties";
47 private static final String VALUES_CMD_PREFIX = "yocto-bsp list ";
48 private static final String VALUES_CMD_SURFIX = " property ";
49 private static final String KERNEL_CHOICE = "kernel_choice";
50 private static final String DEFAULT_KERNEL = "use_default_kernel";
51 private static final String SMP_NAME = "smp";
52 private static final String EXISTING_KBRANCH_NAME = "existing_kbranch";
53 private static final String NEED_NEW_KBRANCH_NAME = "need_new_kbranch";
54 private static final String NEW_KBRANCH_NAME = "new_kbranch";
55 private static final String QARCH_NAME = "qemuarch";
56
57 private static final String KERNEL_CHOICES = "choices";
58 private static final String KERNEL_BRANCHES = "branches";
59
60 private Hashtable<YoctoBspPropertyElement, Control> propertyControlMap;
61 HashSet<YoctoBspPropertyElement> properties;
62
63 private ScrolledComposite composite;
64 private Composite controlContainer = null;
65
66 private YoctoBspElement bspElem = null;
67 private boolean kArchChanged = false;
68
69 private Combo kernelCombo;
70 private Combo branchesCombo;
71
72 private Button newBranchButton;
73 private Button existingBranchButton;
74
75 private Button smpButton;
76
77 private Group kGroup = null;
78 private Group kbGroup = null;
79// private Group otherSettingsGroup = null;
80 private Group propertyGroup = null;
81
82 public PropertiesPage(YoctoBspElement element) {
83 super(PAGE_NAME, "yocto-bsp Properties page", null);
84 this.bspElem = element;
85 }
86
87 public void onEnterPage(YoctoBspElement element) {
88 if (!element.getValidPropertiesFile()) {
89 setErrorMessage("There's no valid properties file created, please choose \"Back\" to reselect kernel architecture!");
90 return;
91 }
92
93 if (this.bspElem == null || this.bspElem.getKarch().isEmpty() || !this.bspElem.getKarch().contentEquals(element.getKarch())) {
94 kArchChanged = true;
95 } else
96 kArchChanged = false;
97
98 this.bspElem = element;
99 try {
100 if (kArchChanged) {
101 updateKernelValues(KERNEL_CHOICES, KERNEL_CHOICE);
102
103 if (propertyGroup != null) {
104 for (Control cntrl : propertyGroup.getChildren()) {
105 cntrl.dispose();
106 }
107 }
108
109 properties = YoctoJSONHelper.getProperties();
110
111 if (!properties.isEmpty()) {
112
113 if (!element.getQarch().isEmpty()) {
114 YoctoBspPropertyElement qarch_elem = new YoctoBspPropertyElement();
115 qarch_elem.setName(QARCH_NAME);
116 qarch_elem.setValue(element.getQarch());
117 properties.add(qarch_elem);
118 }
119
120 propertyControlMap = new Hashtable<YoctoBspPropertyElement, Control>();
121
122 ArrayList<YoctoBspPropertyElement> propertiesList = new ArrayList<YoctoBspPropertyElement>(properties);
123 Collections.sort(propertiesList, Collections.reverseOrder());
124
125 Iterator<YoctoBspPropertyElement> it = propertiesList.iterator();
126 Composite comp = new Composite(propertyGroup, SWT.FILL);
127 GridLayout layout = new GridLayout(2, false);
128 GridData data = new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1);
129 comp.setLayoutData(data);
130 comp.setLayout(layout);
131
132 while (it.hasNext()) {
133 // Get property
134 YoctoBspPropertyElement propElem = it.next();
135 String type = propElem.getType();
136 String name = propElem.getName();
137 if (type.contentEquals("edit")) {
138 new Label (propertyGroup, SWT.FILL).setText(name + ":");
139
140 Composite textContainer = new Composite(propertyGroup, SWT.NONE);
141 textContainer.setLayout(new GridLayout(1, false));
142 textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
143 Text text = new Text(textContainer, SWT.BORDER | SWT.SINGLE);
144 text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
145 propertyControlMap.put(propElem, text);
146
147 } else if (type.contentEquals("boolean")) {
148 String default_value = propElem.getDefaultValue();
149 Composite labelContainer = new Composite(propertyGroup, SWT.NONE);
150 labelContainer.setLayout(new GridLayout(2, false));
151 labelContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL, GridData.FILL_VERTICAL, true, false, 2, 1));
152 Button button = new Button(propertyGroup, SWT.CHECK);
153 button.setText(name);
154 if (default_value.equalsIgnoreCase("y")) {
155 button.setSelection(true);
156 } else
157 button.setSelection(false);
158 propertyControlMap.put(propElem, button);
159 } else if (type.contentEquals("choicelist")) {
160 new Label (propertyGroup, SWT.NONE).setText(name + ":");
161
162 Composite textContainer = new Composite(propertyGroup, SWT.NONE);
163 textContainer.setLayout(new GridLayout(1, false));
164 textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
165 Combo combo = new Combo(textContainer, SWT.READ_ONLY);
166 combo.setLayout(new GridLayout(2, false));
167 combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
168 combo.setItems(getBSPComboProperties(name));
169 propertyControlMap.put(propElem, combo);
170 }
171 }
172 }
173 composite.setMinSize(controlContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
174 composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
175 controlContainer.pack();
176 this.composite.layout(true, true);
177 }
178 } catch (Exception e) {
179 e.printStackTrace();
180 }
181
182
183 }
184
185
186 @Override
187 public void createControl(Composite parent) {
188 this.composite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
189 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
190 GridLayout layout = new GridLayout(2, true);
191 this.composite.setLayout(layout);
192
193 gd= new GridData(SWT.FILL, SWT.FILL, true, false);
194 gd.horizontalSpan = 2;
195 this.composite.setLayoutData(gd);
196
197 setControl(this.composite);
198
199 controlContainer = new Composite(composite, SWT.NONE);
200 controlContainer.setLayout(new GridLayout(1, true));
201 controlContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
202
203 kGroup = new Group(controlContainer, SWT.FILL);
204 kGroup.setLayout(new GridLayout(2, false));
205 GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
206 kGroup.setLayoutData(data);
207 kGroup.setText("Kernel Settings:");
208
209 new Label (kGroup, SWT.NONE).setText("Kernel:");
210 Composite textContainer = new Composite(kGroup, SWT.NONE);
211 textContainer.setLayout(new GridLayout(1, false));
212 textContainer.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1));
213
214 kernelCombo = new Combo(textContainer, SWT.READ_ONLY);
215 kernelCombo.setLayout(new GridLayout(2, false));
216 kernelCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
217
218 kernelCombo.addSelectionListener(new SelectionListener() {
219
220 @Override
221 public void widgetSelected(SelectionEvent e) {
222 controlChanged(e.widget);
223 }
224
225 @Override
226 public void widgetDefaultSelected(SelectionEvent e) {
227 }
228 });
229
230 kbGroup = new Group(kGroup, SWT.FILL);
231 kbGroup.setLayout(new GridLayout(2, true));
232 data = new GridData(SWT.FILL, SWT.FILL, true, false);
233 data.horizontalSpan = 2;
234 kbGroup.setLayoutData(data);
235 kbGroup.setText("Branch Settings:");
236
237 textContainer = new Composite(kbGroup, SWT.NONE);
238 textContainer.setLayout(new GridLayout(2, false));
239 textContainer.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
240
241 new Label(textContainer, SWT.NONE).setText("Kernel branch:");
242
243 branchesCombo = new Combo(textContainer, SWT.READ_ONLY);
244 branchesCombo.setLayout(new GridLayout(1, false));
245 branchesCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
246 branchesCombo.addSelectionListener(new SelectionListener() {
247
248 @Override
249 public void widgetSelected(SelectionEvent e) {
250 controlChanged(e.widget);
251 }
252
253 @Override
254 public void widgetDefaultSelected(SelectionEvent e) {
255 }
256 });
257 branchesCombo.setSize(200, 200);
258
259 newBranchButton = new Button(kbGroup, SWT.RADIO);
260 newBranchButton.setText("Create a new branch from an existing one");
261 newBranchButton.setSelection(true);
262 newBranchButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
263 SelectionListener listener = new SelectionListener() {
264 @Override
265 public void widgetDefaultSelected(SelectionEvent e) {}
266
267 @Override
268 public void widgetSelected(SelectionEvent e) {
269 controlChanged(e.widget);
270 }
271 };
272
273 newBranchButton.addSelectionListener(listener);
274
275 existingBranchButton = new Button(kbGroup, SWT.RADIO);
276 existingBranchButton.setText("Use existing branch");
277 existingBranchButton.setSelection(false);
278 existingBranchButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
279 existingBranchButton.addSelectionListener(listener);
280
281// otherSettingsGroup = new Group(controlContainer, SWT.FILL);
282// otherSettingsGroup.setLayout(new GridLayout(2, true));
283// data = new GridData(SWT.FILL, SWT.FILL, true, false);
284// data.horizontalSpan = 2;
285// otherSettingsGroup.setLayoutData(data);
286// otherSettingsGroup.setText("Other Settings:");
287
288 smpButton = new Button(kGroup, SWT.CHECK);
289 smpButton.setText("Enable SMP support");
290 smpButton.setSelection(true);
291
292 propertyGroup = new Group(controlContainer, SWT.NONE);
293 propertyGroup.setLayout(new GridLayout(2, false));
294 data = new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1);
295 propertyGroup.setLayoutData(data);
296 propertyGroup.setText("BSP specific settings:");
297
298 this.composite.layout(true, true);
299
300 composite.setContent(controlContainer);
301 composite.setExpandHorizontal(true);
302 composite.setExpandVertical(true);
303 composite.setMinSize(controlContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
304 controlContainer.pack();
305 composite.pack();
306 }
307
308 @Override
309 public boolean canFlipToNextPage() {
310 return false;
311 }
312
313 public HashSet<YoctoBspPropertyElement> getProperties() {
314 String kcSelection = kernelCombo.getText();
315 String kbSelection = branchesCombo.getText();
316 YoctoBspPropertyElement kcElement = new YoctoBspPropertyElement();
317 kcElement.setName(KERNEL_CHOICE);
318 kcElement.setValue(kcSelection);
319 properties.add(kcElement);
320 YoctoBspPropertyElement defaultElement = new YoctoBspPropertyElement();
321 defaultElement.setName(DEFAULT_KERNEL);
322 defaultElement.setValue("n");
323 properties.add(defaultElement);
324
325 YoctoBspPropertyElement smpElement = new YoctoBspPropertyElement();
326 smpElement.setName(SMP_NAME);
327 if (smpButton.getSelection())
328 smpElement.setValue("y");
329 else
330 smpElement.setValue("n");
331 properties.add(smpElement);
332
333 YoctoBspPropertyElement newKbElement = new YoctoBspPropertyElement();
334 YoctoBspPropertyElement kbElement = new YoctoBspPropertyElement();
335
336 newKbElement.setName(NEED_NEW_KBRANCH_NAME);
337 if (newBranchButton.getSelection()) {
338 newKbElement.setValue("y");
339 properties.add(newKbElement);
340 kbElement.setName(NEW_KBRANCH_NAME);
341 kbElement.setValue(kbSelection);
342 properties.add(kbElement);
343 } else {
344 newKbElement.setValue("n");
345 properties.add(newKbElement);
346 kbElement.setName(EXISTING_KBRANCH_NAME);
347 kbElement.setValue(kbSelection);
348 properties.add(kbElement);
349 }
350
351 return properties;
352 }
353
354 public boolean validatePage() {
355 if (kernelCombo == null)
356 return false;
357
358 if ((kernelCombo != null) && (branchesCombo != null)) {
359 String kcSelection = kernelCombo.getText();
360 String kbSelection = branchesCombo.getText();
361 if ((kcSelection == null) || (kbSelection == null) || (kcSelection.isEmpty()) || (kbSelection.isEmpty())) {
362 setErrorMessage("Please choose a kernel and a specific branch!");
363 return false;
364 }
365 }
366 if ((propertyControlMap != null)) {
367 if (!propertyControlMap.isEmpty()) {
368 Enumeration<YoctoBspPropertyElement> keys = propertyControlMap.keys();
369 while (keys.hasMoreElements()) {
370 YoctoBspPropertyElement key = keys.nextElement();
371 Control control = propertyControlMap.get(key);
372 String type = key.getType();
373
374 if (type.contentEquals("edit")) {
375 String text_value = ((Text)control).getText();
376 if (text_value == null) {
377 setErrorMessage("Field "+ key.getName() +" is not set. All of the field on this screen must be set!");
378 return false;
379 } else {
380 key.setValue(text_value);
381 }
382 } else if (type.contentEquals("choicelist")) {
383 String choice_value = ((Combo)control).getText();
384 if (choice_value == null) {
385 setErrorMessage("Field "+ key.getName() +" is not set. All of the field on this screen must be set!");
386 return false;
387 } else {
388 key.setValue(choice_value);
389 }
390 } else {
391 boolean button_select = ((Button)control).getSelection();
392 if (button_select)
393 key.setValue("y");
394 else
395 key.setValue("n");
396 }
397 updateProperties(key);
398 }
399 }
400 }
401 return true;
402 }
403
404 private void updateProperties(YoctoBspPropertyElement element) {
405 Iterator<YoctoBspPropertyElement> it = properties.iterator();
406
407 while (it.hasNext()) {
408 YoctoBspPropertyElement propElem = it.next();
409 if (propElem.getName().contentEquals(element.getName())) {
410 properties.remove(propElem);
411 properties.add(element);
412 break;
413 } else
414 continue;
415 }
416 }
417 private void controlChanged(Widget widget) {
418 setErrorMessage(null);
419
420 String kernel_choice = kernelCombo.getText();
421 if ((kernel_choice == null) || (kernel_choice.isEmpty())) {
422 setErrorMessage("Please choose kernel !");
423 return;
424 }
425 if (widget == kernelCombo) {
426 updateKernelValues(KERNEL_BRANCHES, "\\\"" + kernel_choice + "\\\"." + NEW_KBRANCH_NAME);
427 } else if (widget == branchesCombo) {
428 setErrorMessage(null);
429 branchesCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT);
430 } else if (widget == newBranchButton || widget == existingBranchButton) {
431 if (newBranchButton.getSelection()) {
432 updateKernelValues(KERNEL_BRANCHES, "\"" + kernel_choice + "\"." + NEW_KBRANCH_NAME);
433 } else {
434 updateKernelValues(KERNEL_BRANCHES, "\"" + kernel_choice + "\"." + EXISTING_KBRANCH_NAME);
435 }
436 branchesCombo.deselectAll();
437 }
438 canFlipToNextPage();
439 getWizard().getContainer().updateButtons();
440 this.composite.layout(true, true);
441 composite.pack();
442 }
443
444 private void updateKernelValues(final String value, String property) {
445 String build_dir = "";
446 if ((bspElem.getBuildLoc() == null) || bspElem.getBuildLoc().isEmpty())
447 build_dir = bspElem.getMetadataLoc()+"/build";
448 else
449 build_dir = bspElem.getBuildLoc();
450
451 String metadataLoc = bspElem.getMetadataLoc();
452 String valuesCmd = "source " + metadataLoc + "/oe-init-build-env;" + metadataLoc + "/scripts/" + VALUES_CMD_PREFIX + bspElem.getKarch() + VALUES_CMD_SURFIX + property;
453 BSPProgressDialog progressDialog = new BSPProgressDialog(getShell(), new KernelBranchesGetter(valuesCmd), "Loading Kernel " + value);
454 if (value.equals(KERNEL_CHOICES))
455 progressDialog.run(false);
456 else if (value.equals(KERNEL_BRANCHES))
457 progressDialog.run(true);
458
459 BSPAction action = progressDialog.getBspAction();
460 if (action.getItems() != null) {
461 if (value.equals(KERNEL_CHOICES)) {
462 kernelCombo.setItems(action.getItems());
463 kernelCombo.pack();
464 kernelCombo.deselectAll();
465 branchesCombo.setEnabled(false);
466 branchesCombo.deselectAll();
467 } else if (value.equals(KERNEL_BRANCHES)) {
468 branchesCombo.setItems(action.getItems());
469 branchesCombo.pack();
470 branchesCombo.setEnabled(true);
471 }
472 composite.setMinSize(controlContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
473 } else if (action.getMessage() != null)
474 MessageDialog.openError(getShell(), "Yocto-BSP", action.getMessage());
475 composite.setMinSize(controlContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
476 }
477
478 private String[] getBSPComboProperties(String property) {
479 String build_dir = "";
480 if ((bspElem.getBuildLoc() == null) || bspElem.getBuildLoc().isEmpty())
481 build_dir = bspElem.getMetadataLoc()+"/build";
482 else
483 build_dir = bspElem.getBuildLoc();
484
485 String valuesCmd = "export BUILDDIR=" + build_dir + ";" + bspElem.getMetadataLoc() + "/scripts/" + VALUES_CMD_PREFIX + bspElem.getKarch() + VALUES_CMD_SURFIX + property;
486 BSPProgressDialog progressDialog = new BSPProgressDialog(getShell(), new KernelBranchesGetter(valuesCmd), "Loading property " + property + "values");
487 progressDialog.run(false);
488 BSPAction action = progressDialog.getBspAction();
489
490 if (action.getItems() != null) {
491 return action.getItems();
492 } else if (action.getMessage() != null) {
493 MessageDialog.openError(getShell(), "Yocto-BSP", action.getMessage());
494 return new String[]{};
495 }
496 return new String[]{};
497 }
498}