Modal overlay fixes

This commit is contained in:
crschnick
2026-06-18 11:51:53 +00:00
parent 7e9522b8e9
commit 8e8a34f2c5
4 changed files with 15 additions and 22 deletions
@@ -98,6 +98,6 @@ public class ModalOverlay {
}
public void close() {
AppDialog.closeDialog(this);
AppDialog.hide(this);
}
}
@@ -30,22 +30,12 @@ public class ModalOverlayStackComp extends SimpleRegionBuilder {
}
private BaseRegionBuilder<?, ?> buildModalOverlay(BaseRegionBuilder<?, ?> current, int index) {
AtomicInteger currentIndex = new AtomicInteger(index);
var prop = new SimpleObjectProperty<>(modalOverlay.size() > index ? modalOverlay.get(index) : null);
modalOverlay.addListener((ListChangeListener<? super ModalOverlay>) c -> {
var ex = prop.get();
// Don't shift just for an index change
if (ex != null && c.getList().contains(ex)) {
currentIndex.set(c.getList().indexOf(ex));
return;
} else {
currentIndex.set(index);
}
prop.set(modalOverlay.size() > index ? modalOverlay.get(index) : null);
});
prop.addListener((observable, oldValue, newValue) -> {
if (newValue == null && modalOverlay.indexOf(oldValue) == currentIndex.get()) {
if (newValue == null) {
modalOverlay.remove(oldValue);
}
});
@@ -37,14 +37,6 @@ public class AppDialog {
return Optional.of(modalOverlays.getLast());
}
public static void closeDialog(ModalOverlay overlay) {
PlatformThread.runLaterIfNeeded(() -> {
synchronized (modalOverlays) {
modalOverlays.remove(overlay);
}
});
}
public static void waitForAllDialogsClose() {
while (!modalOverlays.isEmpty()) {
ThreadHelper.sleep(10);
@@ -63,7 +55,18 @@ public class AppDialog {
public static void hide(ModalOverlay o) {
PlatformThread.runLaterIfNeeded(() -> {
modalOverlays.remove(o);
var firstElement = o.equals(modalOverlays.stream()
.filter(modalOverlay -> modalOverlay != null)
.findFirst().orElse(null));
var lastElement = modalOverlays.getLast().equals(o);
// Prevent indices from being moved when closing a modal in the back
if (firstElement && !lastElement) {
modalOverlays.set(modalOverlays.indexOf(o), null);
} else if (firstElement && lastElement) {
modalOverlays.clear();
} else {
modalOverlays.remove(o);
}
});
}
@@ -32,7 +32,7 @@ public class ErrorHandlerDialog {
try {
var modal = new AtomicReference<ModalOverlay>();
var comp = new ErrorHandlerComp(event, () -> {
AppDialog.closeDialog(modal.get());
AppDialog.hide(modal.get());
});
comp.prefWidth(event.getThrowable() != null ? 600 : 500);
var headerId = event.isTerminal() ? "terminalErrorOccured" : "errorOccured";