Skip to content

Commit

Permalink
fix: exception when opening already opened files (JabRef#6114)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb authored Mar 13, 2020
1 parent 3c0c518 commit 8b7c374
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed

- We fixed an issue where opening a library from the recent libraries menu was not possible [#5939](https://github.com/JabRef/jabref/issues/5939)

### Removed

## [5.0] – 2020-03-06
Expand Down Expand Up @@ -47,7 +49,6 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where entries containing Unicode charaters were not parsed correctly [#5899](https://github.com/JabRef/jabref/issues/5899)
- We fixed an issue where an entry containing an external filename with curly braces could not be saved. Curly braces are now longer allowed in filenames. [#5899](https://github.com/JabRef/jabref/issues/5899)
- We fixed an issue where changing the type of an entry did not update the main table [#5906](https://github.com/JabRef/jabref/issues/5906)
- We fixed an issue where opening a library from the recent libraries menu was not possible [#5939](https://github.com/JabRef/jabref/issues/5939)
- We fixed an issue in the optics of the library properties, that cropped the dialog on scaled displays. [#5969](https://github.com/JabRef/jabref/issues/5969)
- We fixed an issue where changing the type of an entry did not update the main table. [#5906](https://github.com/JabRef/jabref/issues/5906)
- We fixed an issue where opening a library from the recent libraries menu was not possible. [#5939](https://github.com/JabRef/jabref/issues/5939)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -42,11 +43,11 @@ public class OpenDatabaseAction extends SimpleCommand {
// List of actions that may need to be called after opening the file. Such as
// upgrade actions etc. that may depend on the JabRef version that wrote the file:
private static final List<GUIPostOpenAction> POST_OPEN_ACTIONS = Arrays.asList(
// Migrations:
// Warning for migrating the Review into the Comment field
new MergeReviewIntoCommentAction(),
// Check for new custom entry types loaded from the BIB file:
new CheckForNewEntryTypesAction());
// Migrations:
// Warning for migrating the Review into the Comment field
new MergeReviewIntoCommentAction(),
// Check for new custom entry types loaded from the BIB file:
new CheckForNewEntryTypesAction());

private final JabRefFrame frame;
private final DialogService dialogService;
Expand Down Expand Up @@ -84,7 +85,6 @@ public void execute() {
}

/**
*
* @return Path of current panel database directory or the working directory
*/
private Path getInitialDirectory() {
Expand All @@ -102,7 +102,7 @@ private Path getInitialDirectory() {
* @param file the file, may be null or not existing
*/
public void openFile(Path file, boolean raisePanel) {
openFiles(Arrays.asList(file), raisePanel);
openFiles(new ArrayList<>(List.of(file)), raisePanel);
}

/**
Expand All @@ -116,12 +116,12 @@ public void openFiles(List<Path> filesToOpen, boolean raisePanel) {
int removed = 0;

// Check if any of the files are already open:
for (Iterator<Path> iterator = filesToOpen.iterator(); iterator.hasNext();) {
for (Iterator<Path> iterator = filesToOpen.iterator(); iterator.hasNext(); ) {
Path file = iterator.next();
for (int i = 0; i < frame.getTabbedPane().getTabs().size(); i++) {
BasePanel basePanel = frame.getBasePanelAt(i);
if ((basePanel.getBibDatabaseContext().getDatabasePath().isPresent())
&& basePanel.getBibDatabaseContext().getDatabasePath().get().equals(file)) {
&& basePanel.getBibDatabaseContext().getDatabasePath().get().equals(file)) {
iterator.remove();
removed++;
// See if we removed the final one. If so, we must perhaps
Expand Down Expand Up @@ -169,10 +169,9 @@ private void openTheFile(Path file, boolean raisePanel) {
OpenDatabaseAction.performPostOpenActions(panel, result);
})
.onFailure(ex -> dialogService.showErrorDialogAndWait(Localization.lang("Connection error"),
ex.getMessage() + "\n\n" + Localization.lang("A local copy will be opened.")))
ex.getMessage() + "\n\n" + Localization.lang("A local copy will be opened.")))
.executeWith(Globals.TASK_EXECUTOR);
}

}

private ParserResult loadDatabase(Path file) throws Exception {
Expand All @@ -187,23 +186,21 @@ private ParserResult loadDatabase(Path file) throws Exception {
}

ParserResult result = OpenDatabase.loadDatabase(fileToLoad.toString(),
Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());

if (result.getDatabase().isShared()) {
try {
new SharedDatabaseUIManager(frame).openSharedDatabaseFromParserResult(result);
} catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException |
NotASharedDatabaseException e) {
NotASharedDatabaseException e) {
result.getDatabaseContext().clearDatabaseFile(); // do not open the original file
result.getDatabase().clearSharedDatabaseID();
LOGGER.error("Connection error", e);

throw e;

}
}
return result;

}

private BasePanel addNewDatabase(ParserResult result, final Path file, boolean raisePanel) {
Expand All @@ -214,6 +211,5 @@ private BasePanel addNewDatabase(ParserResult result, final Path file, boolean r
BasePanel basePanel = new BasePanel(frame, BasePanelPreferences.from(Globals.prefs), result.getDatabaseContext(), ExternalFileTypes.getInstance());
frame.addTab(basePanel, raisePanel);
return basePanel;

}
}

0 comments on commit 8b7c374

Please sign in to comment.