use of org.jabref.shared.DBMSConnectionProperties in project jabref by JabRef.
the class ConnectToSharedDatabaseDialog method setupActions.
/**
* Defines and sets the different actions up.
*/
private void setupActions() {
Action openAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
checkFields();
connectionProperties = new DBMSConnectionProperties();
connectionProperties.setType((DBMSType) dbmsTypeDropDown.getSelectedItem());
connectionProperties.setHost(hostField.getText());
connectionProperties.setPort(Integer.parseInt(portField.getText()));
connectionProperties.setDatabase(databaseField.getText());
connectionProperties.setUser(userField.getText());
//JPasswordField.getPassword() does not return a String, but a char array.
connectionProperties.setPassword(new String(passwordField.getPassword()));
openSharedDatabase();
} catch (JabRefException exception) {
JOptionPane.showMessageDialog(ConnectToSharedDatabaseDialog.this, exception.getMessage(), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
}
}
};
connectButton.addActionListener(openAction);
cancelButton.addActionListener(e -> dispose());
/**
* Set up a listener which updates the default port number once the selection in dbmsTypeDropDown has changed.
*/
Action dbmsTypeDropDownAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
portField.setText(Integer.toString(((DBMSType) dbmsTypeDropDown.getSelectedItem()).getDefaultPort()));
}
};
dbmsTypeDropDown.addActionListener(dbmsTypeDropDownAction);
// Add enter button action listener
connectButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter_pressed");
connectButton.getActionMap().put("Enter_pressed", openAction);
browseButton.addActionListener(e -> showFileChooser());
autosaveFile.addActionListener(e -> updateEnableState());
}
use of org.jabref.shared.DBMSConnectionProperties in project jabref by JabRef.
the class SaveDatabaseAction method saveAs.
/**
* Run the "Save as" operation. This method offloads the actual save operation to a background thread, but
* still runs synchronously using Spin (the method returns only after completing the operation).
*/
public void saveAs(File file) throws Exception {
BibDatabaseContext context = panel.getBibDatabaseContext();
if (context.getLocation() == DatabaseLocation.SHARED) {
// Save all properties dependent on the ID. This makes it possible to restore them.
DBMSConnectionProperties properties = context.getDBMSSynchronizer().getDBProcessor().getDBMSConnectionProperties();
new SharedDatabasePreferences(context.getDatabase().generateSharedDatabaseID()).putAllDBMSConnectionProperties(properties);
}
context.setDatabaseFile(file);
if (file.getParent() != null) {
Globals.prefs.put(JabRefPreferences.WORKING_DIRECTORY, file.getParent());
}
runCommand();
// If the operation failed, revert the file field and return:
if (!success) {
return;
}
try {
panel.setFileMonitorHandle(Globals.getFileUpdateMonitor().addUpdateListener(panel, context.getDatabaseFile().orElse(null)));
} catch (IOException ex) {
LOGGER.error("Problem registering file change notifications", ex);
}
if (readyForAutosave(context)) {
AutosaveManager autosaver = AutosaveManager.start(context);
autosaver.registerListener(new AutosaveUIManager(panel));
}
if (readyForBackup(context)) {
BackupManager.start(context);
}
context.getDatabaseFile().ifPresent(presentFile -> frame.getFileHistory().newFile(presentFile.getPath()));
frame.updateEnabledState();
}
use of org.jabref.shared.DBMSConnectionProperties in project jabref by JabRef.
the class SharedDatabaseUIManager method openSharedDatabaseFromParserResult.
public void openSharedDatabaseFromParserResult(ParserResult parserResult) throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException, NotASharedDatabaseException {
Optional<String> sharedDatabaseIDOptional = parserResult.getDatabase().getSharedDatabaseID();
if (!sharedDatabaseIDOptional.isPresent()) {
throw new NotASharedDatabaseException();
}
String sharedDatabaseID = sharedDatabaseIDOptional.get();
DBMSConnectionProperties dbmsConnectionProperties = new DBMSConnectionProperties(new SharedDatabasePreferences(sharedDatabaseID));
JabRefFrame frame = JabRefGUI.getMainFrame();
BibDatabaseMode selectedMode = Globals.prefs.getDefaultBibDatabaseMode();
BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode), DatabaseLocation.SHARED, Globals.prefs.getKeywordDelimiter(), Globals.prefs.getKeyPattern());
bibDatabaseContext.getDatabase().setSharedDatabaseID(sharedDatabaseID);
bibDatabaseContext.setDatabaseFile(parserResult.getDatabaseContext().getDatabaseFile().orElse(null));
dbmsSynchronizer = bibDatabaseContext.getDBMSSynchronizer();
dbmsSynchronizer.openSharedDatabase(dbmsConnectionProperties);
dbmsSynchronizer.registerListener(this);
parserResult.setDatabaseContext(bibDatabaseContext);
frame.output(Localization.lang("Connection_to_%0_server_established.", dbmsConnectionProperties.getType().toString()));
}
Aggregations