|
6 | 6 |
|
7 | 7 | import java.util.List; |
8 | 8 | import java.util.concurrent.CompletableFuture; |
| 9 | +import java.util.concurrent.Executors; |
9 | 10 |
|
| 11 | +import org.eclipse.core.runtime.IProgressMonitor; |
| 12 | +import org.eclipse.core.runtime.IStatus; |
| 13 | +import org.eclipse.core.runtime.Status; |
| 14 | +import org.eclipse.core.runtime.jobs.Job; |
10 | 15 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
11 | 16 | import org.eclipse.core.runtime.preferences.InstanceScope; |
12 | 17 | import org.eclipse.jface.layout.TableColumnLayout; |
@@ -81,16 +86,14 @@ private record IdfRow(IdfInstalled original, boolean isActive, String version, S |
81 | 86 | private EimJson eimJson; |
82 | 87 |
|
83 | 88 | private final EimIdfConfiguratinParser configParser; |
84 | | - private final ToolInitializer toolInitializer; |
85 | | - |
86 | 89 | private final IDFConsole idfConsole = new IDFConsole(); |
87 | 90 | private IdfInstalled currentInstallingNode = null; |
88 | 91 |
|
89 | 92 | public ESPIDFMainTablePage(EimJson eimJson) |
90 | 93 | { |
91 | 94 | this.eimJson = eimJson; |
92 | 95 | this.configParser = new EimIdfConfiguratinParser(); |
93 | | - this.toolInitializer = new ToolInitializer(InstanceScope.INSTANCE.getNode(UIPlugin.PLUGIN_ID)); |
| 96 | + new ToolInitializer(InstanceScope.INSTANCE.getNode(UIPlugin.PLUGIN_ID)); |
94 | 97 | } |
95 | 98 |
|
96 | 99 | public Composite createPage(Composite parent) |
@@ -423,44 +426,62 @@ public void refreshEditorUI() |
423 | 426 | if (container == null || container.isDisposed()) |
424 | 427 | return; |
425 | 428 |
|
426 | | - CompletableFuture.supplyAsync(() -> { |
427 | | - try |
| 429 | + Job refreshJob = new Job(Messages.ESPIDFMainTablePage_RefreshingIdfJobName) |
| 430 | + { |
| 431 | + @Override |
| 432 | + protected IStatus run(IProgressMonitor monitor) |
428 | 433 | { |
429 | | - var newJson = configParser.getEimJson(true); |
430 | | - if (newJson != null && newJson.getIdfInstalled() != null) |
| 434 | + monitor.beginTask(Messages.ESPIDFMainTablePage_ScanningProcessTaskName, IProgressMonitor.UNKNOWN); |
| 435 | + |
| 436 | + try |
431 | 437 | { |
432 | | - var gitPath = newJson.getGitPath(); |
433 | | - return newJson.getIdfInstalled().stream() |
434 | | - .map(idf -> new IdfRow(idf, ToolsUtility.isIdfInstalledActive(idf), |
435 | | - ToolsUtility.getIdfVersion(idf, gitPath), idf.getName(), idf.getPath())) |
436 | | - .toList(); |
| 438 | + var newJson = configParser.getEimJson(true); |
| 439 | + List<IdfRow> rows = List.of(); |
| 440 | + |
| 441 | + if (newJson != null && newJson.getIdfInstalled() != null) |
| 442 | + { |
| 443 | + var gitPath = newJson.getGitPath(); |
| 444 | + |
| 445 | + monitor.subTask(Messages.ESPIDFMainTablePage_DetectingEspIdfSubTaskName); |
| 446 | + |
| 447 | + try (var executor = Executors.newVirtualThreadPerTaskExecutor()) |
| 448 | + { |
| 449 | + var futures = newJson.getIdfInstalled().stream().map(idf -> CompletableFuture.supplyAsync( |
| 450 | + () -> new IdfRow(idf, ToolsUtility.isIdfInstalledActive(idf), |
| 451 | + ToolsUtility.getIdfVersion(idf, gitPath), idf.getName(), idf.getPath()), |
| 452 | + executor)).toList(); |
| 453 | + |
| 454 | + rows = futures.stream().map(CompletableFuture::join).toList(); |
| 455 | + } |
| 456 | + } |
| 457 | + |
| 458 | + final List<IdfRow> finalRows = rows; |
| 459 | + |
| 460 | + Display.getDefault().asyncExec(() -> { |
| 461 | + if (container.isDisposed()) |
| 462 | + return; |
| 463 | + |
| 464 | + var currentSelection = tableViewer.getSelection(); |
| 465 | + currentInstallingNode = null; |
| 466 | + |
| 467 | + tableViewer.setInput(finalRows); |
| 468 | + tableViewer.setSelection(currentSelection); |
| 469 | + updateButtonState(); |
| 470 | + }); |
| 471 | + |
| 472 | + return Status.OK_STATUS; |
| 473 | + } |
| 474 | + catch (Exception e) |
| 475 | + { |
| 476 | + Logger.log(e); |
| 477 | + return new Status(IStatus.ERROR, UIPlugin.PLUGIN_ID, Messages.ESPIDFMainTablePage_FailderRefreshMsg, e); |
| 478 | + } finally |
| 479 | + { |
| 480 | + monitor.done(); |
437 | 481 | } |
438 | | - return List.<IdfRow>of(); |
439 | | - } |
440 | | - catch (Exception e) |
441 | | - { |
442 | | - throw new RuntimeException(e); |
443 | | - } |
444 | | - }).thenAcceptAsync(rows -> { |
445 | | - if (container.isDisposed()) |
446 | | - return; |
447 | | - var currentSelection = tableViewer.getSelection(); |
448 | | - this.currentInstallingNode = null; |
449 | | - try |
450 | | - { |
451 | | - this.eimJson = configParser.getEimJson(false); |
452 | | - } |
453 | | - catch (Exception e) |
454 | | - { |
455 | | - Logger.log(e.toString()); |
456 | 482 | } |
457 | | - tableViewer.setInput(rows); |
458 | | - tableViewer.setSelection(currentSelection); |
459 | | - updateButtonState(); |
460 | | - }, Display.getDefault()::asyncExec).exceptionally(ex -> { |
461 | | - Logger.log(ex.getCause() != null ? ex.getCause().toString() : ex.toString()); |
462 | | - return null; |
463 | | - }); |
| 483 | + }; |
| 484 | + refreshJob.schedule(); |
464 | 485 | } |
465 | 486 |
|
466 | 487 | public void setupInitialEspIdf() |
|
0 commit comments