Skip to content

Commit 5ac5f62

Browse files
committed
address open dialog delay issue
1 parent d8f9189 commit 5ac5f62

File tree

1 file changed

+7
-57
lines changed

1 file changed

+7
-57
lines changed

hdfview/src/main/java/hdf/view/HDFView.java

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,6 @@ public void widgetDisposed(DisposeEvent e)
515515

516516
log.info("Main Window created");
517517

518-
// Start background class warm-up for all platforms
519-
startBackgroundClassWarmup(shell);
520-
521518
return shell;
522519
}
523520

@@ -1104,71 +1101,24 @@ else if (id == SWT.ID_PREFERENCES) {
11041101
log.info("macOS application menu handlers configured");
11051102
}
11061103

1107-
/**
1108-
* Schedules background pre-creation of the User Options dialog on the UI thread.
1109-
* This eliminates the 2-3 second freeze when the user first clicks Preferences.
1110-
* The dialog is created in the background after startup, then cached for instant reuse.
1111-
*
1112-
* @param shell the main shell (used to access the Display and as parent for dialog)
1113-
*/
1114-
private void startBackgroundClassWarmup(final Shell shell)
1115-
{
1116-
final Display display = shell.getDisplay();
1117-
1118-
// Schedule dialog creation on the UI thread after a 2-second delay
1119-
// This delay ensures the UI is fully initialized and startup is complete
1120-
display.timerExec(2000, () -> {
1121-
if (shell.isDisposed()) {
1122-
return; // Don't run if the shell was closed during the delay
1123-
}
1124-
1125-
try {
1126-
log.debug("Pre-creating User Options dialog in background...");
1127-
1128-
// Pre-create the entire dialog structure (this is what takes 2-3 seconds)
1129-
// The dialog will be cached and reused when the user clicks Preferences
1130-
PreferenceManager mgr = new PreferenceManager();
1131-
1132-
UserOptionsNode generalNode = new UserOptionsNode("general", new UserOptionsGeneralPage());
1133-
UserOptionsNode hdfNode = new UserOptionsNode("hdf", new UserOptionsHDFPage());
1134-
UserOptionsNode modulesNode = new UserOptionsNode("modules", new UserOptionsViewModulesPage());
1135-
1136-
mgr.addToRoot(generalNode);
1137-
mgr.addToRoot(hdfNode);
1138-
mgr.addToRoot(modulesNode);
1139-
1140-
userOptionDialog = new UserOptionsDialog(shell, mgr, rootDir);
1141-
userOptionDialog.setPreferenceStore(props);
1142-
userOptionDialog.create(); // This creates all the SWT widgets (expensive!)
1143-
1144-
log.info("User Options dialog pre-created successfully - first open will be instant");
1145-
}
1146-
catch (Throwable t) {
1147-
// If pre-creation fails, the dialog will be created on-demand when user clicks
1148-
log.warn("Failed to pre-create User Options dialog (will create on-demand): {}",
1149-
t.getMessage());
1150-
userOptionDialog = null; // Ensure we don't keep a broken reference
1151-
}
1152-
});
1153-
1154-
log.debug("Background dialog pre-creation scheduled");
1155-
}
1156-
11571104
/**
11581105
* Opens the User Options dialog. Extracted to a separate method for reuse
11591106
* by both the Tools menu and the macOS Preferences menu item.
11601107
*
1108+
* The dialog is cached after first creation, making subsequent opens instant.
1109+
* First open takes 2-3 seconds (creates all widgets), later opens are instant.
1110+
*
11611111
* @param parentShell the parent shell for the dialog
11621112
*/
11631113
private void openUserOptionsDialog(Shell parentShell)
11641114
{
1165-
// Check if we have a pre-created dialog that's still valid
1115+
// Check if we have a cached dialog that's still valid
11661116
boolean needsCreation = (userOptionDialog == null) ||
11671117
(userOptionDialog.getShell() != null &&
11681118
userOptionDialog.getShell().isDisposed());
11691119

11701120
if (needsCreation) {
1171-
log.debug("Creating User Options dialog (first open or after disposal)...");
1121+
log.debug("Creating User Options dialog (first open or after disposal) - this takes ~2 seconds...");
11721122

11731123
// Create the preference manager
11741124
PreferenceManager mgr = new PreferenceManager();
@@ -1191,10 +1141,10 @@ private void openUserOptionsDialog(Shell parentShell)
11911141
userOptionDialog.create();
11921142
}
11931143
else {
1194-
log.debug("Reusing pre-created User Options dialog (instant open)");
1144+
log.debug("Reusing cached User Options dialog (instant open)");
11951145
}
11961146

1197-
// Open the dialog (instant if pre-created, or newly created if needed)
1147+
// Open the dialog (instant if cached, or newly created if needed)
11981148
userOptionDialog.open();
11991149

12001150
// TODO(HDFView) [2025-01]: TECHNICAL DEBT - Fix work directory change detection

0 commit comments

Comments
 (0)