use of org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException in project jabref by JabRef.
the class OpenDatabaseAction method openTheFile.
/**
* @param file the file, may be null or not existing
*/
private void openTheFile(Path file, boolean raisePanel) {
Objects.requireNonNull(file);
if (Files.exists(file)) {
Path fileToLoad = file.toAbsolutePath();
frame.output(Localization.lang("Opening") + ": '" + file + "'");
String fileName = file.getFileName().toString();
Globals.prefs.put(JabRefPreferences.WORKING_DIRECTORY, fileToLoad.getParent().toString());
if (FileBasedLock.hasLockFile(file)) {
Optional<FileTime> modificationTime = FileBasedLock.getLockFileTimeStamp(file);
if ((modificationTime.isPresent()) && ((System.currentTimeMillis() - modificationTime.get().toMillis()) > FileBasedLock.LOCKFILE_CRITICAL_AGE)) {
// The lock file is fairly old, so we can offer to "steal" the file:
int answer = JOptionPane.showConfirmDialog(null, "<html>" + Localization.lang("Error opening file") + " '" + fileName + "'. " + Localization.lang("File is locked by another JabRef instance.") + "<p>" + Localization.lang("Do you want to override the file lock?"), Localization.lang("File locked"), JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.YES_OPTION) {
FileBasedLock.deleteLockFile(file);
} else {
return;
}
} else if (!FileBasedLock.waitForFileLock(file)) {
JOptionPane.showMessageDialog(null, Localization.lang("Error opening file") + " '" + fileName + "'. " + Localization.lang("File is locked by another JabRef instance."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
return;
}
}
if (BackupManager.checkForBackupFile(fileToLoad)) {
BackupUIManager.showRestoreBackupDialog(frame, fileToLoad);
}
ParserResult result;
result = OpenDatabase.loadDatabase(fileToLoad.toString(), Globals.prefs.getImportFormatPreferences());
if (result.getDatabase().isShared()) {
try {
new SharedDatabaseUIManager(frame).openSharedDatabaseFromParserResult(result);
} catch (SQLException | DatabaseNotSupportedException | InvalidDBMSConnectionPropertiesException | NotASharedDatabaseException e) {
// do not open the original file
result.getDatabaseContext().clearDatabaseFile();
result.getDatabase().clearSharedDatabaseID();
LOGGER.error("Connection error", e);
JOptionPane.showMessageDialog(frame, e.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."), Localization.lang("Connection error"), JOptionPane.WARNING_MESSAGE);
}
}
BasePanel panel = addNewDatabase(result, file, raisePanel);
// After adding the database, go through our list and see if
// any post open actions need to be done. For instance, checking
// if we found new entry types that can be imported, or checking
// if the database contents should be modified due to new features
// in this version of JabRef:
final ParserResult finalReferenceToResult = result;
SwingUtilities.invokeLater(() -> OpenDatabaseAction.performPostOpenActions(panel, finalReferenceToResult));
}
}
use of org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException in project jabref by JabRef.
the class ConnectToSharedDatabaseDialog method openSharedDatabase.
public void openSharedDatabase() {
if (isSharedDatabaseAlreadyPresent()) {
JOptionPane.showMessageDialog(ConnectToSharedDatabaseDialog.this, Localization.lang("You are already connected to a database using entered connection details."), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
return;
}
if (autosaveFile.isSelected()) {
Path localFilePath = Paths.get(fileLocationField.getText());
if (Files.exists(localFilePath) && !Files.isDirectory(localFilePath)) {
int answer = JOptionPane.showConfirmDialog(this, Localization.lang("'%0' exists. Overwrite file?", localFilePath.getFileName().toString()), Localization.lang("Existing file"), JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.NO_OPTION) {
fileLocationField.requestFocus();
return;
}
}
}
setLoadingConnectButtonText(true);
try {
BasePanel panel = new SharedDatabaseUIManager(frame).openNewSharedDatabaseTab(connectionProperties);
setPreferences();
dispose();
if (!fileLocationField.getText().isEmpty()) {
try {
new SaveDatabaseAction(panel, Paths.get(fileLocationField.getText())).runCommand();
} catch (Throwable e) {
LOGGER.error("Error while saving the database", e);
}
}
// setLoadingConnectButtonText(false) should not be reached regularly.
return;
} catch (SQLException | InvalidDBMSConnectionPropertiesException exception) {
JOptionPane.showMessageDialog(ConnectToSharedDatabaseDialog.this, exception.getMessage(), Localization.lang("Connection error"), JOptionPane.ERROR_MESSAGE);
} catch (DatabaseNotSupportedException exception) {
new MigrationHelpDialog(this).setVisible(true);
}
setLoadingConnectButtonText(false);
}
Aggregations