3
3
import java .io .File ;
4
4
import java .util .HashMap ;
5
5
import java .util .Map ;
6
+ import java .util .Map .Entry ;
6
7
import java .util .TreeMap ;
7
8
8
9
import org .eclipse .cdt .core .parser .util .ArrayUtil ;
30
31
import org .eclipse .swt .widgets .Listener ;
31
32
import org .eclipse .swt .widgets .Text ;
32
33
33
- import io .sloeber .core .api .SloeberProject ;
34
34
import io .sloeber .core .api .BoardDescription ;
35
35
import io .sloeber .core .api .Defaults ;
36
36
import io .sloeber .core .api .PackageManager ;
37
37
import io .sloeber .core .api .PasswordManager ;
38
38
import io .sloeber .core .api .SerialManager ;
39
+ import io .sloeber .core .api .SloeberProject ;
39
40
import io .sloeber .ui .Activator ;
40
41
import io .sloeber .ui .LabelCombo ;
41
42
import io .sloeber .ui .Messages ;
@@ -59,13 +60,14 @@ public class BoardSelectionPage extends AbstractCPropertyTab {
59
60
public Text myFeedbackControl ;
60
61
61
62
// GUI elements
62
- protected LabelCombo myControlBoardsTxtFile ;
63
- protected LabelCombo mycontrolBoardName ;
64
- protected LabelCombo myControlUploadProtocol ;
65
- protected LabelCombo myControlUploadPort ;
66
- protected LabelCombo [] myBoardOptionCombos = null ;
67
- protected Listener myBoardSelectionChangedListener = null ;
68
- protected BoardDescription myBoardID = null ;
63
+ private LabelCombo myControlBoardsTxtFile ;
64
+ private LabelCombo mycontrolBoardName ;
65
+ private LabelCombo myControlUploadProtocol ;
66
+ private LabelCombo myControlUploadPort ;
67
+ private LabelCombo [] myBoardOptionCombos = null ;
68
+ private Listener myBoardSelectionChangedListener = null ;
69
+ private Map <String , BoardDescription > myBoardDescs = new HashMap <>();
70
+ private BoardDescription myActiveBoardDesc = null ;
69
71
private Composite myComposite ;
70
72
private TreeMap <String , File > myAllBoardsFiles = new TreeMap <>(String .CASE_INSENSITIVE_ORDER );
71
73
private org .eclipse .swt .widgets .Button myPasswordButton ;
@@ -87,25 +89,27 @@ public ICConfigurationDescription getConfdesc() {
87
89
@ Override
88
90
public void handleEvent (Event e ) {
89
91
92
+ getBoardDescription ();
90
93
File boardFile = getSelectedBoardsFile ();
91
- myBoardID .setreferencingBoardsFile (boardFile );
94
+ String curBoard = myActiveBoardDesc .getBoardName ();
95
+ String curProgrammer = myActiveBoardDesc .getProgrammer ();
96
+ myActiveBoardDesc .setreferencingBoardsFile (boardFile );
92
97
93
98
/*
94
99
* Change the list of available boards
95
100
*/
96
- String CurrentBoard = getBoardName ();
97
- mycontrolBoardName .setItems (myBoardID .getCompatibleBoards ());
98
- mycontrolBoardName .setText (CurrentBoard );
101
+
102
+ mycontrolBoardName .setItems (myActiveBoardDesc .getCompatibleBoards ());
103
+ mycontrolBoardName .setText (curBoard );
99
104
100
105
/*
101
106
* Change the list of available upload protocols
102
107
*/
103
- String CurrentUploadProtocol = getUpLoadProtocol ();
104
- myControlUploadProtocol .setItems (myBoardID .getUploadProtocols ());
105
- myControlUploadProtocol .setText (CurrentUploadProtocol );
108
+ myControlUploadProtocol .setItems (myActiveBoardDesc .getUploadProtocols ());
109
+ myControlUploadProtocol .setText (curProgrammer );
106
110
107
111
if (myControlUploadProtocol .getText ().isEmpty ()) {
108
- myBoardID . setUploadProtocol (Defaults .getDefaultUploadProtocol ());
112
+ myActiveBoardDesc . setProgrammer (Defaults .getDefaultUploadProtocol ());
109
113
myControlUploadProtocol .setText (Defaults .getDefaultUploadProtocol ());
110
114
}
111
115
@@ -118,11 +122,12 @@ public void handleEvent(Event e) {
118
122
@ Override
119
123
public void handleEvent (Event e ) {
120
124
121
- myBoardID .setBoardName (getBoardName ());
125
+ getBoardDescription ();
126
+ myActiveBoardDesc .setBoardName (getBoardName ());
122
127
123
128
for (LabelCombo curLabelCombo : myBoardOptionCombos ) {
124
- curLabelCombo .setItems (myBoardID .getMenuItemNamesFromMenuID (curLabelCombo .getID ()));
125
- curLabelCombo .setLabel (myBoardID .getMenuNameFromMenuID (curLabelCombo .getID ()));
129
+ curLabelCombo .setItems (myActiveBoardDesc .getMenuItemNamesFromMenuID (curLabelCombo .getID ()));
130
+ curLabelCombo .setLabel (myActiveBoardDesc .getMenuNameFromMenuID (curLabelCombo .getID ()));
126
131
}
127
132
128
133
isPageComplete ();
@@ -138,6 +143,8 @@ public void handleEvent(Event e) {
138
143
139
144
private ScrolledComposite myScrolledComposite ;
140
145
146
+ private SloeberProject myArduinoProject = null ;
147
+
141
148
@ Override
142
149
public void createControls (Composite parent , ICPropertyProvider provider ) {
143
150
super .createControls (parent , provider );
@@ -163,11 +170,11 @@ public void draw(Composite parent) {
163
170
myScrolledComposite .setExpandHorizontal (true );
164
171
165
172
myComposite = new Composite (myScrolledComposite , SWT .NONE );
166
- myBoardID = getBoardID ();
167
- if (myBoardID .getActualCoreCodePath () == null ) {
168
- Activator .log (
169
- new Status (IStatus .ERROR , Activator .getId (), Messages .BoardSelectionPage_failed_to_find_platform
170
- .replace (Messages .PLATFORM , myBoardID .getReferencingPlatformFile ().toString ())));
173
+ getBoardDescription ();
174
+ if (myActiveBoardDesc .getActualCoreCodePath () == null ) {
175
+ Activator .log (
176
+ new Status (IStatus .ERROR , Activator .getId (), Messages .BoardSelectionPage_failed_to_find_platform
177
+ .replace (Messages .PLATFORM , myActiveBoardDesc .getReferencingPlatformFile ().toString ())));
171
178
}
172
179
173
180
File [] allBoardsFileNames = PackageManager .getAllBoardsFiles ();
@@ -312,9 +319,9 @@ protected void performDefaults() {
312
319
313
320
@ Override
314
321
protected void updateData (ICResourceDescription cfg ) {
315
- // myBoardID.saveUserSelection ();
316
- // myBoardID = new BoardDescription (cfg.getConfiguration());
317
- // setValues();
322
+ getValues ();
323
+ myActiveBoardDesc = myBoardDescs . get (cfg .getConfiguration (). getId ());
324
+ setValues ();
318
325
}
319
326
320
327
@ Override
@@ -324,33 +331,35 @@ protected void updateButtons() {
324
331
}
325
332
326
333
private void setValues () {
327
-
328
- myControlBoardsTxtFile .setText (tidyUpLength (myBoardID .getReferencingBoardsFile ().toString ()));
329
- mycontrolBoardName .setItems (myBoardID .getCompatibleBoards ());
330
- mycontrolBoardName .setText (myBoardID .getBoardName ());
334
+ getBoardDescription ();
335
+ myControlBoardsTxtFile .setText (tidyUpLength (myActiveBoardDesc .getReferencingBoardsFile ().toString ()));
336
+ mycontrolBoardName .setItems (myActiveBoardDesc .getCompatibleBoards ());
337
+ mycontrolBoardName .setText (myActiveBoardDesc .getBoardName ());
331
338
332
339
String CurrentUploadProtocol = getUpLoadProtocol ();
333
- myControlUploadProtocol .setItems (myBoardID .getUploadProtocols ());
340
+ myControlUploadProtocol .setItems (myActiveBoardDesc .getUploadProtocols ());
334
341
myControlUploadProtocol .setText (CurrentUploadProtocol );
335
342
if (getUpLoadProtocol ().isEmpty ()) {
336
- myControlUploadProtocol .setText (myBoardID .getProgrammer ());
343
+ myControlUploadProtocol .setText (myActiveBoardDesc .getProgrammer ());
337
344
if (myControlUploadProtocol .getText ().isEmpty ()) {
338
345
myControlUploadProtocol .setText (Defaults .getDefaultUploadProtocol ());
339
346
}
340
347
}
341
348
342
- myControlUploadPort .setValue (myBoardID .getUploadPort ());
349
+ myControlUploadPort .setValue (myActiveBoardDesc .getUploadPort ());
343
350
344
351
// set the options in the combo boxes before setting the value
345
- Map <String , String > options = myBoardID .getOptions ();
352
+ Map <String , String > options = myActiveBoardDesc .getOptions ();
346
353
347
354
for (LabelCombo curLabelCombo : myBoardOptionCombos ) {
348
- curLabelCombo .setItems (myBoardID .getMenuItemNamesFromMenuID (curLabelCombo .getID ()));
355
+ curLabelCombo .setItems (myActiveBoardDesc .getMenuItemNamesFromMenuID (curLabelCombo .getID ()));
349
356
if (options != null ) {
350
357
String value = options .get (curLabelCombo .getID ());
351
358
if (value != null ) {
352
359
try {
353
- curLabelCombo .setValue (myBoardID .getMenuItemNamedFromMenuItemID (value , curLabelCombo .getID ()));
360
+ curLabelCombo
361
+ .setValue (
362
+ myActiveBoardDesc .getMenuItemNamedFromMenuItemID (value , curLabelCombo .getID ()));
354
363
} catch (@ SuppressWarnings ("unused" ) Exception e ) {
355
364
// When this fails no default value will be set
356
365
// so nothing to do here
@@ -371,24 +380,39 @@ protected void performApply(ICResourceDescription src, ICResourceDescription dst
371
380
doOK ();
372
381
}
373
382
383
+ private void getValues () {
384
+ myActiveBoardDesc .setreferencingBoardsFile (getSelectedBoardsFile ());
385
+ myActiveBoardDesc .setUploadPort (getUpLoadPort ());
386
+ myActiveBoardDesc .setProgrammer (getUpLoadProtocol ());
387
+ myActiveBoardDesc .setBoardName (getBoardName ());
388
+ myActiveBoardDesc .setOptions (getOptions ());
389
+
390
+ }
391
+
374
392
private void doOK () {
375
- myBoardID .setreferencingBoardsFile (getSelectedBoardsFile ());
376
- myBoardID .setUploadPort (getUpLoadPort ());
377
- myBoardID .setUploadProtocol (getUpLoadProtocol ());
378
- myBoardID .setBoardName (getBoardName ());
379
- myBoardID .setOptions (getOptions ());
393
+ myActiveBoardDesc .saveUserSelection ();
394
+ getValues ();
380
395
ICConfigurationDescription confdesc = getConfdesc ();
381
-
396
+ ICProjectDescription projDesc = confdesc . getProjectDescription ();
382
397
try {
383
- IProject project = confdesc . getProjectDescription (). getProject ();
384
- SloeberProject arduinoProject = SloeberProject . getSloeberProject ( project );
385
- arduinoProject .setBoardDescription (confdesc , myBoardID );
386
-
398
+ for ( Entry < String , BoardDescription > curEntry : myBoardDescs . entrySet ()) {
399
+ ICConfigurationDescription curConfDesc = projDesc . getConfigurationById ( curEntry . getKey () );
400
+ getSloeberProject () .setBoardDescription (curConfDesc , curEntry . getValue () );
401
+ }
387
402
} catch (Exception e ) {
388
403
Activator .log (new Status (IStatus .ERROR , Activator .getId (), Messages .error_adding_arduino_code , e ));
389
404
}
390
405
}
391
406
407
+ private SloeberProject getSloeberProject () {
408
+ if (myArduinoProject == null ) {
409
+ ICConfigurationDescription confdesc = getConfdesc ();
410
+ IProject project = confdesc .getProjectDescription ().getProject ();
411
+ myArduinoProject = SloeberProject .getSloeberProject (project );
412
+ }
413
+ return myArduinoProject ;
414
+
415
+ }
392
416
393
417
private class ArduinoSelectionPageListener implements Listener {
394
418
private AbstractPage myPage ;
@@ -416,7 +440,7 @@ protected File getSelectedBoardsFile() {
416
440
return null ;
417
441
}
418
442
String selectedText = myControlBoardsTxtFile .getText ().trim ();
419
- return myAllBoardsFiles .get (selectedText );
443
+ return myAllBoardsFiles .get (selectedText );
420
444
}
421
445
422
446
public String getUpLoadPort () {
@@ -444,36 +468,37 @@ private Map<String, String> getOptions() {
444
468
if (myBoardOptionCombos == null ) {
445
469
return null ;
446
470
}
471
+ getBoardDescription ();
447
472
Map <String , String > options = new HashMap <>();
448
473
for (LabelCombo curLabelCombo : myBoardOptionCombos ) {
449
474
if (curLabelCombo .isVisible ()) {
450
475
options .put (curLabelCombo .getID (),
451
- myBoardID .getMenuItemIDFromMenuItemName (curLabelCombo .getValue (), curLabelCombo .getID ()));
476
+ myActiveBoardDesc .getMenuItemIDFromMenuItemName (curLabelCombo .getValue (),
477
+ curLabelCombo .getID ()));
452
478
}
453
479
}
454
480
return options ;
455
481
}
456
482
457
- public BoardDescription getBoardID () {
458
- if (myBoardID == null ) {
483
+ public BoardDescription getBoardDescription () {
484
+ if (myActiveBoardDesc == null ) {
459
485
// myBoardID = new BoardDescription(getConfdesc());
460
- ICProjectDescription confDesc = getConfdesc ().getProjectDescription ();
461
- IProject project = confDesc .getProject ();
462
- SloeberProject arduinoProject = SloeberProject .getSloeberProject (project );
463
- myBoardID = arduinoProject .getBoardDescription (confDesc .getActiveConfiguration ());
464
- if (myBoardID == null ) {
465
- myBoardID = new BoardDescription ();
486
+ ICConfigurationDescription activeConfDesc = getConfdesc ();
487
+ if (activeConfDesc == null ) {
488
+ myActiveBoardDesc = new BoardDescription ();
489
+ } else {
490
+ ICProjectDescription projDesc = getConfdesc ().getProjectDescription ();
491
+ for (ICConfigurationDescription curConfDesc : projDesc .getConfigurations ()) {
492
+ myBoardDescs .put (curConfDesc .getId (), getSloeberProject ().getBoardDescription (curConfDesc ));
493
+ }
494
+ myActiveBoardDesc = myBoardDescs .get (activeConfDesc .getId ());
495
+ if (myActiveBoardDesc == null ) {
496
+ myActiveBoardDesc = new BoardDescription ();
497
+ }
466
498
}
467
499
}
468
- if (myBoardOptionCombos != null ) {// only update the values if the
469
- // page has been drawn
470
- myBoardID .setreferencingBoardsFile (getSelectedBoardsFile ());
471
- myBoardID .setBoardName (getBoardName ());
472
- myBoardID .setOptions (getOptions ());
473
- myBoardID .setUploadPort (getUpLoadPort ());
474
- myBoardID .setUploadProtocol (getUpLoadProtocol ());
475
- }
476
- return myBoardID ;
500
+
501
+ return myActiveBoardDesc ;
477
502
}
478
503
479
504
}
0 commit comments