GUI: ApplicationRunContext beim Datei-Öffnen proaktiv aufbauen
Bisher wurde der ApplicationRunContext nur beim --config-Startpfad erzeugt. Der auto-load-Pfad (letzte Konfiguration aus Preferences) baute keinen Kontext auf, was Scheduler und Batch-Vorinitialisierung blockierte. Neu: GuiApplicationContextInitializer-Callback, den Bootstrap für jeden GUI-Startpfad bereitstellt. openConfigurationFile() ruft ihn im Hintergrund-Thread auf; das Scheduler-Ergebnis wird via Platform.runLater() an GuiSchedulerTab.onSchedulerAvailable() übergeben. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+40
-10
@@ -21,6 +21,7 @@ import de.gecheckt.pdf.umbenenner.adapter.in.cli.SchedulerBatchCommand;
|
||||
import de.gecheckt.pdf.umbenenner.adapter.in.scheduler.FileChannelConfigurationAccessAdapter;
|
||||
import de.gecheckt.pdf.umbenenner.adapter.in.scheduler.ScheduledExecutorServiceSchedulerAdapter;
|
||||
import de.gecheckt.pdf.umbenenner.adapter.in.gui.GuiAdapter;
|
||||
import de.gecheckt.pdf.umbenenner.adapter.in.gui.GuiApplicationContextInitializer;
|
||||
import de.gecheckt.pdf.umbenenner.adapter.in.gui.GuiConfigurationFileLoader;
|
||||
import de.gecheckt.pdf.umbenenner.adapter.in.gui.GuiConfigurationFileWriter;
|
||||
import de.gecheckt.pdf.umbenenner.adapter.in.gui.GuiConfigurationLoadException;
|
||||
@@ -255,11 +256,13 @@ public class BootstrapRunner {
|
||||
* the resolved JDBC URL, so that batch runs and reset operations can skip the
|
||||
* migrate → load → validate → schema-init sequence for each call.
|
||||
* <p>
|
||||
* Written by {@link #initializeApplicationRunContext(Path)} during
|
||||
* {@link #buildGuiStartupContext(Optional)} and read by
|
||||
* Written by {@link #initializeApplicationRunContext(Path)} — either directly during
|
||||
* {@link #buildGuiStartupContext(Optional)} (when {@code --config} is supplied and valid),
|
||||
* or via the {@link GuiApplicationContextInitializer} callback that the workspace invokes
|
||||
* on a background thread after each successful file open. Read by
|
||||
* {@link #launchGuiBatchRun}, {@link #launchGuiMiniBatchRun}, and
|
||||
* {@link #resetDocumentStatusForGui}. {@code volatile} ensures visibility
|
||||
* across threads without explicit synchronisation on the happy path.
|
||||
* {@link #resetDocumentStatusForGui}. {@code volatile} ensures visibility across threads
|
||||
* without explicit synchronisation on the happy path.
|
||||
*/
|
||||
private volatile Optional<ApplicationRunContext> guiApplicationRunContext = Optional.empty();
|
||||
|
||||
@@ -771,8 +774,12 @@ public class BootstrapRunner {
|
||||
* during startup is treated as a hard GUI startup failure and mapped to exit code 1.
|
||||
* Normal termination (user closes the window) returns exit code 0.
|
||||
* <p>
|
||||
* The headless batch pipeline is not entered from this method. Configuration loading,
|
||||
* schema initialization, and all batch infrastructure are not initialized in the GUI path.
|
||||
* The headless batch pipeline is not entered from this method. When {@code --config} is
|
||||
* supplied and the file exists, configuration loading and schema initialisation run
|
||||
* immediately so the application run context is pre-built. For all other startup paths
|
||||
* (no {@code --config}, missing file, load failure) a {@link GuiApplicationContextInitializer}
|
||||
* callback is wired into the startup context; the workspace calls it on a background thread
|
||||
* each time a configuration file is successfully opened.
|
||||
*
|
||||
* @param configPathOverride the optional {@code --config} path string from startup arguments;
|
||||
* must not be {@code null}
|
||||
@@ -915,6 +922,20 @@ public class BootstrapRunner {
|
||||
// Versionsnummer aus dem MANIFEST.MF des gepackten JARs lesen; Fallback "dev" bei IDE-Start
|
||||
String applicationVersion = ApplicationVersionProvider.resolveVersion();
|
||||
|
||||
// Initializer that the workspace calls on a background thread after every successful
|
||||
// file open (auto-load at startup and manual open). Builds the ApplicationRunContext
|
||||
// and wires the scheduler for the newly loaded configuration file.
|
||||
GuiApplicationContextInitializer contextInitializer = configFilePath -> {
|
||||
stopGuiSchedulerIfActive();
|
||||
Optional<String> initError = initializeApplicationRunContext(configFilePath);
|
||||
if (initError.isEmpty()) {
|
||||
tryInitializeScheduler(configFilePath);
|
||||
}
|
||||
return new GuiApplicationContextInitializer.InitResult(
|
||||
initError,
|
||||
guiSchedulerUseCase.map(s -> (SchedulerControlUseCase) s));
|
||||
};
|
||||
|
||||
if (configPathOverride.isEmpty()) {
|
||||
return new GuiStartupContext(
|
||||
GuiConfigurationEditorStateFactory.createBlankStartState(),
|
||||
@@ -941,7 +962,10 @@ public class BootstrapRunner {
|
||||
deleteHistoryPort,
|
||||
this::buildGuiPromptEditorPort,
|
||||
createNewDatabasePort,
|
||||
Optional.empty());
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
contextInitializer);
|
||||
}
|
||||
|
||||
Path configPath = Paths.get(configPathOverride.get());
|
||||
@@ -974,7 +998,10 @@ public class BootstrapRunner {
|
||||
deleteHistoryPort,
|
||||
this::buildGuiPromptEditorPort,
|
||||
createNewDatabasePort,
|
||||
Optional.empty());
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
contextInitializer);
|
||||
}
|
||||
|
||||
LOG.info("GUI startup: configuration file confirmed at: {}", configPath.toAbsolutePath());
|
||||
@@ -997,7 +1024,7 @@ public class BootstrapRunner {
|
||||
historicalDocumentContextPort, applicationVersion, promptEditorPort,
|
||||
historyOverviewPort, historyDetailsPort, historyResetPort, deleteHistoryPort,
|
||||
this::buildGuiPromptEditorPort, createNewDatabasePort, contextError,
|
||||
schedulerUseCase, guiRunLockPort);
|
||||
schedulerUseCase, guiRunLockPort, contextInitializer);
|
||||
} catch (GuiConfigurationLoadException e) {
|
||||
LOG.error("GUI startup: configuration could not be loaded, starting without it: {}",
|
||||
e.getMessage(), e);
|
||||
@@ -1026,7 +1053,10 @@ public class BootstrapRunner {
|
||||
deleteHistoryPort,
|
||||
this::buildGuiPromptEditorPort,
|
||||
createNewDatabasePort,
|
||||
Optional.empty());
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
contextInitializer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user