Skip to content

Commit

Permalink
add Stacktrace button to load error dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
zocker-160 committed Sep 17, 2022
1 parent 6cd5f24 commit 3fa10e4
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/main/java/EEmodders/gui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ private void loadFiles(List<DatFile> filesToLoad) {
.map(LoadThread::getDatFile)
.collect(Collectors.toList());

if (filesNotLoaded.size() > 0) {
showLoadError(filesNotLoaded);
final Map<DatFile, Throwable> mapNotLoaded = threads.stream()
.filter(LoadThread::isFailed)
.collect(Collectors.toMap(LoadThread::getDatFile, LoadThread::getError));

if (!mapNotLoaded.isEmpty()) {
showLoadError(mapNotLoaded);
return;
}

Expand All @@ -158,9 +162,9 @@ private void onLoadSucceed(Collection<DatFile> loaded) {
Core.getDbSelectorController().setDBButtons(loadedDBs);
}

private void showLoadError(Collection<DatFile> notLoaded) {
private void showLoadError(Map<DatFile, Throwable> notLoaded) {
var errorMessage = new Alert(Alert.AlertType.ERROR);
errorMessage.getDialogPane().setMinSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
errorMessage.getDialogPane().setMinSize(400, Region.USE_PREF_SIZE);
Util.setAlertIcon(errorMessage);
errorMessage.setTitle("ERROR");
errorMessage.setHeaderText("An error occurred during the loading of DAT files!");
Expand All @@ -176,23 +180,26 @@ private void showLoadError(Collection<DatFile> notLoaded) {
"------------------------------------------------ \n" +
"Following files failed to load: \n");

for (var dat : notLoaded) {
for (var dat : notLoaded.keySet())
coreMessage.append("- ").append(dat.getName()).append("\n");
}

errorMessage.setContentText(coreMessage.toString());

var btnEES = new ButtonType("Get EE Studio II");
var btnEES = new ButtonType("EE Studio II");
var btnTrace = new ButtonType("Stacktraces", ButtonBar.ButtonData.LEFT);
var btnClose = new ButtonType("Close", ButtonBar.ButtonData.NEXT_FORWARD);
var btnExit = new ButtonType("Exit", ButtonBar.ButtonData.LEFT);

errorMessage.getButtonTypes().setAll(btnExit, btnEES, btnClose);
errorMessage.getButtonTypes().setAll(btnExit, btnTrace, btnEES, btnClose);

var result = errorMessage.showAndWait();
var choice = result.get();

if (choice == btnEES) {
new Thread(Util::openEESUrl).start();
} else if (choice == btnTrace) {
for (var error : notLoaded.values())
Util.printException(null, error, false);
} else if (choice == btnExit) {
Core.exit();
}
Expand Down

0 comments on commit 3fa10e4

Please sign in to comment.