Skip to content

Commit 7a67aca

Browse files
author
jantje
committed
#1273 still problems with multiple config
1 parent 5a2f2c7 commit 7a67aca

File tree

3 files changed

+58
-43
lines changed

3 files changed

+58
-43
lines changed

io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sloeber.core.api;
22

3+
import static io.sloeber.core.Messages.*;
34
import static io.sloeber.core.common.Common.*;
45
import static io.sloeber.core.common.Const.*;
56

@@ -22,7 +23,6 @@
2223
import org.eclipse.core.runtime.preferences.InstanceScope;
2324

2425
import io.sloeber.core.Activator;
25-
import io.sloeber.core.Messages;
2626
import io.sloeber.core.common.Common;
2727
import io.sloeber.core.common.ConfigurationPreferences;
2828
import io.sloeber.core.managers.ArduinoPlatform;
@@ -37,9 +37,6 @@
3737

3838
public class BoardDescription {
3939
// Important constants to avoid having to add the class
40-
private static final String TOOL_ID = Messages.TOOL;
41-
private static final String BOARD_ID = Messages.BOARD;
42-
private static final String FILE_ID = Messages.FILE;
4340
private static final String VendorArduino = ARDUINO;
4441

4542
/*
@@ -204,9 +201,9 @@ private void ParseSection() {
204201
myReferencedCorePlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, architecture);
205202
if (this.myReferencedCorePlatformPath == null) {
206203
Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID,
207-
Messages.Helpers_tool_reference_missing.replace(TOOL_ID, core)
208-
.replace(FILE_ID, getReferencingBoardsFile().toString())
209-
.replace(BOARD_ID, getBoardID())));
204+
Helpers_tool_reference_missing.replace(TOOL_TAG, core)
205+
.replace(FILE_TAG, getReferencingBoardsFile().toString())
206+
.replace(BOARD_TAG, getBoardID())));
210207
return;
211208
}
212209
} else if (valueSplit.length == 4) {
@@ -219,9 +216,9 @@ private void ParseSection() {
219216
refVersion);
220217
if (this.myReferencedCorePlatformPath == null) {
221218
Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID,
222-
Messages.Helpers_tool_reference_missing.replace(TOOL_ID, core)
223-
.replace(FILE_ID, getReferencingBoardsFile().toString())
224-
.replace(BOARD_ID, getBoardID())));
219+
Helpers_tool_reference_missing.replace(TOOL_TAG, core)
220+
.replace(FILE_TAG, getReferencingBoardsFile().toString())
221+
.replace(BOARD_TAG, getBoardID())));
225222
return;
226223
}
227224
} else {
@@ -238,9 +235,9 @@ private void ParseSection() {
238235
architecture);
239236
if (this.myReferencedBoardVariantPlatformPath == null) {
240237
Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID,
241-
Messages.Helpers_tool_reference_missing.replace(TOOL_ID, variant)
242-
.replace(FILE_ID, getReferencingBoardsFile().toString())
243-
.replace(BOARD_ID, getBoardID())));
238+
Helpers_tool_reference_missing.replace(TOOL_TAG, variant)
239+
.replace(FILE_TAG, getReferencingBoardsFile().toString())
240+
.replace(BOARD_TAG, getBoardID())));
244241
return;
245242
}
246243
} else if (valueSplit.length == 4) {
@@ -258,9 +255,9 @@ private void ParseSection() {
258255
}
259256
if (this.myReferencedBoardVariantPlatformPath == null) {
260257
Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID,
261-
Messages.Helpers_tool_reference_missing.replace(TOOL_ID, variant)
262-
.replace(FILE_ID, getReferencingBoardsFile().toString())
263-
.replace(BOARD_ID, getBoardID())));
258+
Helpers_tool_reference_missing.replace(TOOL_TAG, variant)
259+
.replace(FILE_TAG, getReferencingBoardsFile().toString())
260+
.replace(BOARD_TAG, getBoardID())));
264261
return;
265262
}
266263
} else {
@@ -277,9 +274,9 @@ private void ParseSection() {
277274
architecture);
278275
if (this.myReferencedUploadToolPlatformPath == null) {
279276
Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID,
280-
Messages.Helpers_tool_reference_missing.replace(TOOL_ID, upload)
281-
.replace(FILE_ID, getReferencingBoardsFile().toString())
282-
.replace(BOARD_ID, getBoardID())));
277+
Helpers_tool_reference_missing.replace(TOOL_TAG, upload)
278+
.replace(FILE_TAG, getReferencingBoardsFile().toString())
279+
.replace(BOARD_TAG, getBoardID())));
283280
return;
284281
}
285282
} else if (valueSplit.length == 4) {
@@ -292,9 +289,9 @@ private void ParseSection() {
292289
refArchitecture, refVersion);
293290
if (this.myReferencedUploadToolPlatformPath == null) {
294291
Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID,
295-
Messages.Helpers_tool_reference_missing.replace(TOOL_ID, upload)
296-
.replace(FILE_ID, getReferencingBoardsFile().toString())
297-
.replace(BOARD_ID, getBoardID())));
292+
Helpers_tool_reference_missing.replace(TOOL_TAG, upload)
293+
.replace(FILE_TAG, getReferencingBoardsFile().toString())
294+
.replace(BOARD_TAG, getBoardID())));
298295
return;
299296
}
300297
} else {
@@ -359,7 +356,7 @@ public BoardDescription(BoardDescription srcObject) {
359356
myBoardID = srcObject.myBoardID;
360357
myUploadPort = srcObject.myUploadPort;
361358
myProgrammer = srcObject.myProgrammer;
362-
myOptions = srcObject.myOptions;
359+
myOptions = new TreeMap<>(srcObject.myOptions);
363360
}
364361

365362

@@ -476,7 +473,7 @@ public void setreferencingBoardsFile(File boardsFile) {
476473
return;// ignore
477474
}
478475
/*
479-
* do not do this optimisation as workaround changes will not be captured if
476+
* do not do this optimization as workaround changes will not be captured if
480477
* (this.myreferencingBoardsFile.equals(resolvePathEnvironmentString(boardsFile)
481478
* )) { return; }
482479
*/
@@ -1013,7 +1010,7 @@ private Map<String, String> getEnvVarsPostProcessing(Map<String, String> vars) {
10131010

10141011
switch (recipeParts.length) {
10151012
case 0:
1016-
extraVars.put(recipeKey + DOT + '1', "echo no command for \"{KEY}\".".replace(Messages.KEY, recipeKey)); //$NON-NLS-1$
1013+
extraVars.put(recipeKey + DOT + '1', "echo no command for \"{KEY}\".".replace(KEY_TAG, recipeKey)); //$NON-NLS-1$
10171014
break;
10181015
case 1:
10191016
extraVars.put(recipeKey + DOT + '1', recipeParts[0]);

io.sloeber.core/src/io/sloeber/core/common/Const.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public class Const {
8080

8181
public static final String ENV_KEY_UPLOAD_USE_1200BPS_TOUCH = UPLOAD + DOT + "use_1200bps_touch";
8282
public static final String ENV_KEY_WAIT_FOR_UPLOAD_PORT = UPLOAD + DOT + "wait_for_upload_port";
83-
public static final String ENV_KEY_RESET_BEFORE_UPLOAD = UPLOAD + DOT + "force_reset_before_upload";
8483
public static final String ENV_KEY_NETWORK_PORT = NETWORK + DOT + PORT;
8584
public static final String ENV_KEY_NETWORK_AUTH = NETWORK + DOT + AUTH;
8685
public static final String ENV_KEY_NETWORK_PASSWORD = NETWORK + DOT + "password";

io.sloeber.ui/src/io/sloeber/ui/project/properties/BoardSelectionPage.java

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ public class BoardSelectionPage extends SloeberCpropertyTab {
6060
private File myCurrentLabelComboBoardFile = null;
6161
private String myCurrentOptionBoardID = null;
6262
private Listener myCompleteListener = null;
63+
private boolean disableListeners = false;
6364

6465
private Listener myBoardFileModifyListener = new Listener() {
6566
@Override
6667
public void handleEvent(Event e) {
68+
if (disableListeners) {
69+
return;
70+
}
6771
BoardDescription boardDesc = getBoardFromScreen();
6872

6973
/*
@@ -82,7 +86,7 @@ public void handleEvent(Event e) {
8286
myControlUploadProtocol.setText(Defaults.getDefaultUploadProtocol());
8387
}
8488

85-
setTheLabelCombos();
89+
setTheLabelCombos(getBoardFromScreen());
8690
genericListenerEnd();
8791
}
8892

@@ -91,19 +95,26 @@ public void handleEvent(Event e) {
9195
protected Listener myBoardModifyListener = new Listener() {
9296
@Override
9397
public void handleEvent(Event e) {
94-
setTheLabelCombos();
98+
if (disableListeners) {
99+
return;
100+
}
101+
setTheLabelCombos(getBoardFromScreen());
95102
genericListenerEnd();
96103
}
97104
};
98105
protected Listener myChangeListener = new Listener() {
99106
@Override
100107
public void handleEvent(Event e) {
108+
if (disableListeners) {
109+
return;
110+
}
101111
genericListenerEnd();
102112
}
103113
};
104114

105115

106116

117+
107118
@Override
108119
public void createControls(Composite parent, ICPropertyProvider provider) {
109120
super.createControls(parent, provider);
@@ -237,11 +248,18 @@ public boolean canBeVisible() {
237248
return true;
238249
}
239250

240-
private Map<String, String> getOptions() {
251+
/**
252+
* Get the options from screen you need the boarddescriptor to convert the menu
253+
* item name to menu item id
254+
*
255+
* @param boardDesc
256+
* @return a map containing menuid, menuitemid mapping with what is shown on
257+
* screen
258+
*/
259+
private Map<String, String> getOptions(BoardDescription boardDesc) {
241260
if (myBoardOptionCombos == null) {
242261
return null;
243262
}
244-
BoardDescription boardDesc = (BoardDescription) getDescription(getConfdesc());
245263
Map<String, String> options = new HashMap<>();
246264
for (Entry<String, LabelCombo> curOption : myBoardOptionCombos.entrySet()) {
247265
String MenuID = curOption.getKey();
@@ -254,6 +272,7 @@ private Map<String, String> getOptions() {
254272

255273
@Override
256274
protected void updateScreen() {
275+
disableListeners = true;
257276
BoardDescription boardDesc = (BoardDescription) getDescription(getConfdesc());
258277

259278
myControlBoardsTxtFile.setText(tidyUpLength(boardDesc.getReferencingBoardsFile().toString()));
@@ -271,7 +290,8 @@ protected void updateScreen() {
271290
}
272291

273292
myControlUploadPort.setText(boardDesc.getUploadPort());
274-
setTheLabelCombos();
293+
setTheLabelCombos(boardDesc);
294+
disableListeners = false;
275295
}
276296

277297
public BoardDescription getBoardFromScreen() {
@@ -281,7 +301,7 @@ public BoardDescription getBoardFromScreen() {
281301
boardDesc.setUploadPort(myControlUploadPort.getText());
282302
boardDesc.setProgrammer(myControlUploadProtocol.getText());
283303
boardDesc.setBoardName(mycontrolBoardName.getText());
284-
boardDesc.setOptions(getOptions());
304+
boardDesc.setOptions(getOptions(boardDesc));
285305
return boardDesc;
286306
}
287307

@@ -322,13 +342,12 @@ protected Object getnewDefaultObject() {
322342
}
323343

324344

325-
private void setTheLabelCombos() {
345+
private void setTheLabelCombos(BoardDescription boardDesc) {
326346

327347
saveUsedOptionValues();
328-
BoardDescription boardOnScreen = getBoardFromScreen();
329348

330-
File onScreenComboBoardFile = boardOnScreen.getReferencingBoardsFile();
331-
String onScreenBoardID = boardOnScreen.getBoardID();
349+
File onScreenComboBoardFile = boardDesc.getReferencingBoardsFile();
350+
String onScreenBoardID = boardDesc.getBoardID();
332351
boolean boardsFileChanged = !onScreenComboBoardFile.equals(myCurrentLabelComboBoardFile);
333352
boolean boardIDChanged = !onScreenBoardID.equals(myCurrentOptionBoardID);
334353
if (boardsFileChanged || boardIDChanged) {
@@ -341,23 +360,23 @@ private void setTheLabelCombos() {
341360
}
342361
myBoardOptionCombos.clear();
343362

344-
Map<String, String> menus = boardOnScreen.getAllMenus();
345-
Map<String, String> boardOptions = boardOnScreen.getOptions();
363+
Map<String, String> menus = boardDesc.getAllMenus();
364+
Map<String, String> boardOptions = boardDesc.getOptions();
346365

347366
for (Map.Entry<String, String> curMenu : menus.entrySet()) {
348367
String menuName = curMenu.getValue();
349368
String menuID = curMenu.getKey();
350-
String[] menuItemNames = boardOnScreen.getMenuItemNamesFromMenuID(menuID);
369+
String[] menuItemNames = boardDesc.getMenuItemNamesFromMenuID(menuID);
351370
if (menuItemNames.length > 0) {
352371
LabelCombo newLabelCombo = new LabelCombo(myComposite, menuName, 2, true);
353372
myBoardOptionCombos.put(menuID, newLabelCombo);
354373

355-
newLabelCombo.setItems(boardOnScreen.getMenuItemNamesFromMenuID(menuID));
374+
newLabelCombo.setItems(boardDesc.getMenuItemNamesFromMenuID(menuID));
356375
newLabelCombo.setLabel(menuName);
357376
String optionValue = boardOptions.get(menuID);
358377
if (optionValue != null) {
359378
// convert the ID to a name
360-
optionValue = boardOnScreen.getMenuItemNamedFromMenuItemID(optionValue, menuID);
379+
optionValue = boardDesc.getMenuItemNamedFromMenuItemID(optionValue, menuID);
361380
} else {
362381
// use last used name for this menu ID
363382
optionValue = myUsedOptionValues.get(menuID);
@@ -376,14 +395,14 @@ private void setTheLabelCombos() {
376395
myScrollComposite.setMinSize(point);
377396
}
378397
else {
379-
Map<String, String> boardOptions = boardOnScreen.getOptions();
398+
Map<String, String> boardOptions = boardDesc.getOptions();
380399
for (Entry<String, LabelCombo> curOptionCombo : myBoardOptionCombos.entrySet()) {
381400
String curMenuID = curOptionCombo.getKey();
382401
LabelCombo curLabelCombo = curOptionCombo.getValue();
383402
String optionValue = boardOptions.get(curMenuID);
384403
if (optionValue != null) {
385404
// convert the ID to a name
386-
optionValue = boardOnScreen.getMenuItemNamedFromMenuItemID(optionValue, curMenuID);
405+
optionValue = boardDesc.getMenuItemNamedFromMenuItemID(optionValue, curMenuID);
387406
} else {
388407
// use last used name for this menu ID
389408
optionValue = myUsedOptionValues.get(curMenuID);

0 commit comments

Comments
 (0)