-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix GroupTree wrongly displayed #9451
Changes from 5 commits
f1f8d30
c9ac62b
f9b8f4d
bb2b4cb
b4c083a
955844a
5e9681d
4ae8864
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
import java.nio.file.Path; | ||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -178,9 +177,7 @@ private void openTheFile(Path file) { | |
} | ||
|
||
BackgroundTask<ParserResult> backgroundTask = BackgroundTask.wrap(() -> loadDatabase(file)); | ||
koppor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
LibraryTab.Factory libraryTabFactory = new LibraryTab.Factory(); | ||
LibraryTab newTab = libraryTabFactory.createLibraryTab(frame, preferencesService, stateManager, themeManager, file, backgroundTask, Globals.IMPORT_FORMAT_READER); | ||
|
||
LibraryTab newTab = LibraryTab.createLibraryTab(frame, preferencesService, stateManager, themeManager, file, backgroundTask, Globals.IMPORT_FORMAT_READER); | ||
backgroundTask.onFinished(() -> trackOpenNewDatabase(newTab)); | ||
} | ||
|
||
|
@@ -195,49 +192,51 @@ private ParserResult loadDatabase(Path file) throws Exception { | |
|
||
preferencesService.getFilePreferences().setWorkingDirectory(fileToLoad.getParent()); | ||
|
||
ParserResult result = null; | ||
ParserResult parserResult = null; | ||
if (BackupManager.backupFileDiffers(fileToLoad)) { | ||
result = BackupUIManager.showRestoreBackupDialog(dialogService, fileToLoad, preferencesService).orElse(null); | ||
// In case the backup differs, ask the user what to do. | ||
// In case the user opted for restoring a backup, the content of the backup is contained in parserResult. | ||
parserResult = BackupUIManager.showRestoreBackupDialog(dialogService, fileToLoad, preferencesService).orElse(null); | ||
} | ||
|
||
try { | ||
if (result == null) { | ||
result = OpenDatabase.loadDatabase(fileToLoad, | ||
if (parserResult == null) { | ||
// No backup was restored, do the "normal" loading | ||
Comment on lines
+199
to
+205
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well done for including the comments. I wrote that, but if I had to read it again in a year, I wouldn't know what is going on. I guess comments aren't useless after all. |
||
parserResult = OpenDatabase.loadDatabase(fileToLoad, | ||
preferencesService.getImportFormatPreferences(), | ||
Globals.getFileUpdateMonitor()); | ||
} | ||
|
||
if (result.hasWarnings()) { | ||
if (parserResult.hasWarnings()) { | ||
String content = Localization.lang("Please check your library file for wrong syntax.") | ||
+ "\n\n" + result.getErrorMessage(); | ||
+ "\n\n" + parserResult.getErrorMessage(); | ||
DefaultTaskExecutor.runInJavaFXThread(() -> | ||
dialogService.showWarningDialogAndWait(Localization.lang("Open library error"), content)); | ||
} | ||
} catch (IOException e) { | ||
result = ParserResult.fromError(e); | ||
parserResult = ParserResult.fromError(e); | ||
LOGGER.error("Error opening file '{}'", fileToLoad, e); | ||
} | ||
|
||
if (result.getDatabase().isShared()) { | ||
if (parserResult.getDatabase().isShared()) { | ||
try { | ||
new SharedDatabaseUIManager(frame, preferencesService).openSharedDatabaseFromParserResult(result); | ||
new SharedDatabaseUIManager(frame, preferencesService).openSharedDatabaseFromParserResult(parserResult); | ||
} catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException | | ||
NotASharedDatabaseException e) { | ||
result.getDatabaseContext().clearDatabasePath(); // do not open the original file | ||
result.getDatabase().clearSharedDatabaseID(); | ||
parserResult.getDatabaseContext().clearDatabasePath(); // do not open the original file | ||
parserResult.getDatabase().clearSharedDatabaseID(); | ||
LOGGER.error("Connection error", e); | ||
|
||
throw e; | ||
} | ||
} | ||
return result; | ||
return parserResult; | ||
} | ||
|
||
private void trackOpenNewDatabase(LibraryTab libraryTab) { | ||
Map<String, String> properties = new HashMap<>(); | ||
Map<String, Double> measurements = new HashMap<>(); | ||
measurements.put("NumberOfEntries", (double) libraryTab.getBibDatabaseContext().getDatabase().getEntryCount()); | ||
|
||
Globals.getTelemetryClient().ifPresent(client -> client.trackEvent("OpenNewDatabase", properties, measurements)); | ||
Globals.getTelemetryClient().ifPresent(client -> client.trackEvent( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though we currently don't do any telemetry, I think this method needs to be added inside the LibraryTab to the BackgroundTask otherwise it's not excuted If I remember that correctly from my debug session There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user is still asked to provide his OK for telemetry. I only changed the code to a lambda function (which I found more readable). The method is connected to the backgroudntask on line 181:
Thus, I do not see any need to change something here 😇 |
||
"OpenNewDatabase", | ||
Map.of(), | ||
Map.of("NumberOfEntries", (double) libraryTab.getBibDatabaseContext().getDatabase().getEntryCount()))); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@calixtus prevented me from using
frame.getCurrentLibraryTab().equals(this)
, because he wants to get rid offrame
. Fixed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I did and I'm not even ashamed of it.