Skip to content

Commit ed5861a

Browse files
authored
IEP-1602 Prevent Exception When EIM Closes Before eim.json Is Created (#1273)
1 parent dba491a commit ed5861a

File tree

2 files changed

+71
-65
lines changed

2 files changed

+71
-65
lines changed

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/EimIdfConfiguratinParser.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ private void load() throws IOException
4242

4343
public EimJson getEimJson(boolean reload) throws IOException
4444
{
45-
if (reload)
46-
{
47-
load();
48-
}
49-
50-
if (eimJson == null)
45+
if (reload || eimJson == null)
5146
{
5247
load();
5348
}

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/manager/pages/ESPIDFMainTablePage.java

Lines changed: 70 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
/**
5454
* Main UI class for all listing and interacting with the tools
55+
*
5556
* @author Ali Azam Rana
5657
*
5758
*/
@@ -66,37 +67,37 @@ public class ESPIDFMainTablePage
6667
private TableViewerColumn removeColumn;
6768
private TableViewerColumn nameColumn;
6869
private Button eimLaunchBtn;
69-
70+
7071
private TableColumnLayout tableColumnLayout;
7172
private Composite tableComposite;
7273
private List<IdfInstalled> idfInstalledList;
7374
private static EimJson eimJson;
7475
private EimIdfConfiguratinParser eimIdfConfiguratinParser;
7576
private ToolInitializer toolInitializer;
76-
77+
7778
private static final String RELOAD_ICON = "icons/tools/reload.png"; //$NON-NLS-1$
7879
private static final String IDF_TOOL_SET_BTN_KEY = "IDFToolSet"; //$NON-NLS-1$
79-
80+
8081
private static ESPIDFMainTablePage espidfMainTablePage;
81-
82+
8283
private ESPIDFMainTablePage()
8384
{
8485
eimIdfConfiguratinParser = new EimIdfConfiguratinParser();
85-
toolInitializer = new ToolInitializer(org.eclipse.core.runtime.preferences.InstanceScope.INSTANCE
86-
.getNode(UIPlugin.PLUGIN_ID));
86+
toolInitializer = new ToolInitializer(
87+
org.eclipse.core.runtime.preferences.InstanceScope.INSTANCE.getNode(UIPlugin.PLUGIN_ID));
8788
}
88-
89+
8990
public static ESPIDFMainTablePage getInstance(EimJson eimJson)
9091
{
9192
if (espidfMainTablePage == null)
9293
{
9394
espidfMainTablePage = new ESPIDFMainTablePage();
9495
}
95-
96+
9697
ESPIDFMainTablePage.eimJson = eimJson;
9798
return espidfMainTablePage;
9899
}
99-
100+
100101
public Composite createPage(Composite composite)
101102
{
102103
idfInstalledList = eimJson != null ? eimJson.getIdfInstalled() : null;
@@ -108,7 +109,7 @@ public Composite createPage(Composite composite)
108109
createIdfTable(container);
109110
return container;
110111
}
111-
112+
112113
private void createButtonAndGuideLink(Composite composite)
113114
{
114115
Link guideLink = new Link(composite, SWT.WRAP);
@@ -117,20 +118,22 @@ private void createButtonAndGuideLink(Composite composite)
117118
guideLink.addListener(SWT.Selection, e -> {
118119
try
119120
{
120-
java.awt.Desktop.getDesktop().browse(new java.net.URI(
121-
"https://dl.espressif.com/dl/esp-idf/support-periods.svg"));
121+
java.awt.Desktop.getDesktop()
122+
.browse(new java.net.URI("https://dl.espressif.com/dl/esp-idf/support-periods.svg")); //$NON-NLS-1$
122123
}
123124
catch (Exception ex)
124125
{
125126
Logger.log(ex);
126127
}
127128
});
128-
129+
129130
eimLaunchBtn = new Button(composite, SWT.PUSH);
130-
eimLaunchBtn.setText(!toolInitializer.isEimInstalled() ? Messages.EIMButtonDownloadText : Messages.EIMButtonLaunchText);
131-
eimLaunchBtn.addSelectionListener(new EimButtonLaunchListener(espidfMainTablePage, Display.getDefault(), getConsoleStream(false), getConsoleStream(true)));
131+
eimLaunchBtn.setText(
132+
!toolInitializer.isEimInstalled() ? Messages.EIMButtonDownloadText : Messages.EIMButtonLaunchText);
133+
eimLaunchBtn.addSelectionListener(new EimButtonLaunchListener(espidfMainTablePage, Display.getDefault(),
134+
getConsoleStream(false), getConsoleStream(true)));
132135
}
133-
136+
134137
public void setupInitialEspIdf()
135138
{
136139
if (idfInstalledList != null && idfInstalledList.size() == 1)
@@ -155,8 +158,8 @@ public void refreshEditorUI()
155158
return;
156159
for (TableItem item : tableViewer.getTable().getItems())
157160
{
158-
String EDITOR_KEY = "action_editor";
159-
String EDITOR_KEY_LAST = "action_editor_last";
161+
String EDITOR_KEY = "action_editor"; //$NON-NLS-1$
162+
String EDITOR_KEY_LAST = "action_editor_last"; //$NON-NLS-1$
160163
TableEditor editorFirst = (TableEditor) item.getData(EDITOR_KEY);
161164
TableEditor editorLast = (TableEditor) item.getData(EDITOR_KEY_LAST);
162165
if (editorFirst != null)
@@ -168,40 +171,46 @@ public void refreshEditorUI()
168171
editorFirst.dispose(); // Dispose the editor itself
169172
item.setData(EDITOR_KEY, null); // Clear the stored editor reference
170173
}
171-
174+
172175
if (editorLast != null)
173176
{
174177
if (editorLast.getEditor() != null && !editorLast.getEditor().isDisposed())
175178
{
176179
editorLast.getEditor().dispose();
177180
}
178-
181+
179182
editorLast.dispose();
180183
item.setData(EDITOR_KEY_LAST, null);
181184
}
182185
}
183186
try
184187
{
185188
eimJson = eimIdfConfiguratinParser.getEimJson(true);
189+
// eimJson is null if EIM was closed before tool installation completed
190+
if (eimJson == null)
191+
{
192+
return;
193+
}
186194
}
187195
catch (IOException e)
188196
{
189197
Logger.log(e);
190198
}
191-
199+
192200
idfInstalledList = eimJson.getIdfInstalled();
193201
setupColumns();
194202
tableViewer.setInput(idfInstalledList);
195203
tableViewer.getControl().requestLayout();
196204
tableViewer.refresh();
197-
eimLaunchBtn.setText(!toolInitializer.isEimInstalled() ? Messages.EIMButtonDownloadText : Messages.EIMButtonLaunchText);
205+
eimLaunchBtn.setText(
206+
!toolInitializer.isEimInstalled() ? Messages.EIMButtonDownloadText : Messages.EIMButtonLaunchText);
198207
container.redraw();
199208
}
200209

201210
private Composite createIdfTable(Composite parent)
202211
{
203212
Group idfToolsGroup = new Group(parent, SWT.SHADOW_ETCHED_IN);
204-
idfToolsGroup.setText("IDF Tools");
213+
idfToolsGroup.setText("IDF Tools"); //$NON-NLS-1$
205214
idfToolsGroup.setLayout(new GridLayout(2, false));
206215
idfToolsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
207216

@@ -212,13 +221,13 @@ private Composite createIdfTable(Composite parent)
212221
tableComposite.setLayout(tableColumnLayout);
213222
tableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.H_SCROLL);
214223
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
215-
224+
216225
Table table = tableViewer.getTable();
217226
table.setHeaderVisible(true);
218227
table.setLinesVisible(true);
219228
table.addListener(SWT.MeasureItem, event -> {
220-
event.height = 25;
221-
});
229+
event.height = 25;
230+
});
222231
comparator = new ColumnViewerComparator();
223232
tableViewer.setComparator(comparator);
224233
setupColumns();
@@ -229,37 +238,37 @@ private Composite createIdfTable(Composite parent)
229238
tableViewer.setInput(idfInstalledList);
230239
table.layout();
231240
// Composite for the "Add" button
232-
Composite buttonComposite = new Composite(idfToolsGroup, SWT.NONE);
233-
GridData buttonCompositeGridData = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
234-
buttonCompositeGridData.verticalAlignment = SWT.TOP; // Aligns the button composite at the top
235-
buttonComposite.setLayoutData(buttonCompositeGridData);
236-
buttonComposite.setLayout(new GridLayout(1, true));
237-
241+
Composite buttonComposite = new Composite(idfToolsGroup, SWT.NONE);
242+
GridData buttonCompositeGridData = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
243+
buttonCompositeGridData.verticalAlignment = SWT.TOP; // Aligns the button composite at the top
244+
buttonComposite.setLayoutData(buttonCompositeGridData);
245+
buttonComposite.setLayout(new GridLayout(1, true));
246+
238247
return idfToolsGroup;
239248
}
240-
249+
241250
private void disposeColumns()
242251
{
243252
if (activateColumn != null && activateColumn.getColumn() != null)
244253
{
245254
activateColumn.getColumn().dispose();
246255
}
247-
256+
248257
if (versionColumn != null && versionColumn.getColumn() != null)
249258
{
250259
versionColumn.getColumn().dispose();
251260
}
252-
261+
253262
if (locationColumn != null && locationColumn.getColumn() != null)
254263
{
255264
locationColumn.getColumn().dispose();
256265
}
257-
266+
258267
if (removeColumn != null && removeColumn.getColumn() != null)
259268
{
260269
removeColumn.getColumn().dispose();
261270
}
262-
271+
263272
if (nameColumn != null && nameColumn.getColumn() != null)
264273
{
265274
nameColumn.getColumn().dispose();
@@ -270,18 +279,18 @@ private void setupColumns()
270279
{
271280
disposeColumns();
272281
int colIndex = 0;
273-
282+
274283
activateColumn = new TableViewerColumn(tableViewer, SWT.NONE);
275284
activateColumn.getColumn().setText(Messages.EspIdfManagerActivateCol);
276285
activateColumn.setLabelProvider(new IdfManagerTableColumnLabelProvider());
277286
tableColumnLayout.setColumnData(activateColumn.getColumn(), new ColumnWeightData(2, 5, true));
278-
287+
279288
versionColumn = new TableViewerColumn(tableViewer, SWT.NONE);
280289
versionColumn.getColumn().setText(Messages.EspIdfManagerVersionCol);
281290
versionColumn.setLabelProvider(new IdfManagerTableColumnLabelProvider());
282291
setComparatorForCols(versionColumn, colIndex++);
283292
tableColumnLayout.setColumnData(versionColumn.getColumn(), new ColumnWeightData(3, 50, true));
284-
293+
285294
nameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
286295
nameColumn.getColumn().setText(Messages.EspIdfManagerNameCol);
287296
nameColumn.setLabelProvider(new IdfManagerTableColumnLabelProvider());
@@ -293,7 +302,7 @@ private void setupColumns()
293302
locationColumn.setLabelProvider(new IdfManagerTableColumnLabelProvider());
294303
setComparatorForCols(locationColumn, colIndex++);
295304
tableColumnLayout.setColumnData(locationColumn.getColumn(), new ColumnWeightData(10, 100, true));
296-
305+
297306
removeColumn = new TableViewerColumn(tableViewer, SWT.NONE);
298307
removeColumn.setLabelProvider(new IdfManagerTableColumnLabelProvider());
299308
tableColumnLayout.setColumnData(removeColumn.getColumn(), new ColumnWeightData(3, 100, true));
@@ -328,13 +337,13 @@ public void widgetSelected(SelectionEvent e)
328337
private class IdfManagerTableColumnLabelProvider extends ColumnLabelProvider
329338
{
330339
private Color activeBackgroundColor;
331-
340+
332341
private IdfManagerTableColumnLabelProvider()
333342
{
334343
super();
335344
this.activeBackgroundColor = new Color(Display.getCurrent(), 144, 238, 144);
336345
}
337-
346+
338347
@Override
339348
public Color getBackground(Object element)
340349
{
@@ -368,7 +377,7 @@ else if (isLastCol)
368377
{
369378
updateDataIntoCells(cell);
370379
}
371-
380+
372381
Color color = getBackground(cell.getElement());
373382
if (color != null)
374383
{
@@ -409,9 +418,9 @@ private String getIdfVersion(IdfInstalled idfInstalled)
409418
private void createButtonsForFirstCol(ViewerCell cell)
410419
{
411420
TableItem item = (TableItem) cell.getItem();
412-
421+
413422
// using a unique key to store the editor to avoid creating multiple editors for the same cell
414-
String EDITOR_KEY = "action_editor";
423+
String EDITOR_KEY = "action_editor"; //$NON-NLS-1$
415424
if (item.getData(EDITOR_KEY) != null)
416425
{
417426
return; // This cell already has an editor
@@ -426,9 +435,10 @@ private void createButtonsForFirstCol(ViewerCell cell)
426435
setActiveButton.setData(IDF_TOOL_SET_BTN_KEY, idfInstalled);
427436
setActiveButton.addListener(SWT.Selection, e -> {
428437
Button btn = (Button) e.widget;
429-
SetupToolsInIde setupToolsInIde = new SetupToolsInIde(idfInstalled, eimJson, getConsoleStream(true), getConsoleStream(false));
430-
SetupToolsJobListener toolsActivationJobListener = new SetupToolsJobListener(
431-
ESPIDFMainTablePage.this, setupToolsInIde);
438+
SetupToolsInIde setupToolsInIde = new SetupToolsInIde(idfInstalled, eimJson, getConsoleStream(true),
439+
getConsoleStream(false));
440+
SetupToolsJobListener toolsActivationJobListener = new SetupToolsJobListener(ESPIDFMainTablePage.this,
441+
setupToolsInIde);
432442
setupToolsInIde.addJobChangeListener(toolsActivationJobListener);
433443
setupToolsInIde.schedule();
434444
btn.setEnabled(false);
@@ -437,13 +447,13 @@ private void createButtonsForFirstCol(ViewerCell cell)
437447
editor.grabHorizontal = true;
438448
editor.setEditor(buttonComposite, item, cell.getColumnIndex());
439449
}
440-
450+
441451
private void createButtonsForLastCol(ViewerCell cell)
442452
{
443453
TableItem item = (TableItem) cell.getItem();
444454
Rectangle cellBounds = cell.getBounds();
445455
// using a unique key to store the editor to avoid creating multiple editors for the same cell
446-
String EDITOR_KEY = "action_editor_last";
456+
String EDITOR_KEY = "action_editor_last"; //$NON-NLS-1$
447457
if (item.getData(EDITOR_KEY) != null)
448458
{
449459
return; // This cell already has an editor
@@ -455,9 +465,9 @@ private void createButtonsForLastCol(ViewerCell cell)
455465
buttonComposite.redraw();
456466
item.setData(EDITOR_KEY, editor);
457467
IdfInstalled idfInstalled = (IdfInstalled) cell.getElement();
458-
468+
459469
int buttonHeight = Math.min(cellBounds.height - 6, 30);
460-
470+
461471
if (ToolsUtility.isIdfInstalledActive(idfInstalled))
462472
{
463473
Button reloadButton = new Button(buttonComposite, SWT.PUSH | SWT.FLAT);
@@ -468,15 +478,16 @@ private void createButtonsForLastCol(ViewerCell cell)
468478
reloadButton.addListener(SWT.Selection, e -> {
469479
Button btn = (Button) e.widget;
470480
IdfInstalled selectedToolSet = (IdfInstalled) btn.getData(IDF_TOOL_SET_BTN_KEY);
471-
SetupToolsInIde setupToolsInIde = new SetupToolsInIde(selectedToolSet, eimJson, getConsoleStream(true), getConsoleStream(false));
481+
SetupToolsInIde setupToolsInIde = new SetupToolsInIde(selectedToolSet, eimJson,
482+
getConsoleStream(true), getConsoleStream(false));
472483
SetupToolsJobListener toolsActivationJobListener = new SetupToolsJobListener(
473484
ESPIDFMainTablePage.this, setupToolsInIde);
474485
setupToolsInIde.addJobChangeListener(toolsActivationJobListener);
475486
setupToolsInIde.schedule();
476487
});
477-
488+
478489
reloadButton.setSize(cellBounds.width, buttonHeight);
479-
reloadButton.addListener(SWT.Paint, e-> e.gc.drawRectangle(reloadButton.getBounds()));
490+
reloadButton.addListener(SWT.Paint, e -> e.gc.drawRectangle(reloadButton.getBounds()));
480491
reloadButton.redraw();
481492
}
482493

@@ -488,9 +499,9 @@ private void createButtonsForLastCol(ViewerCell cell)
488499
buttonComposite.layout(true, true);
489500
buttonComposite.redraw();
490501
editor.layout();
491-
tableViewer.getTable().layout(true, true);
502+
tableViewer.getTable().layout(true, true);
492503
}
493-
504+
494505
@Override
495506
public void dispose()
496507
{
@@ -501,7 +512,7 @@ public void dispose()
501512
super.dispose();
502513
}
503514
}
504-
515+
505516
private MessageConsoleStream getConsoleStream(boolean errorStream)
506517
{
507518
IDFConsole idfConsole = new IDFConsole();

0 commit comments

Comments
 (0)