Search in sources :

Example 1 with DBMSConnectionProperties

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());
}
Also used : SaveDatabaseAction(org.jabref.gui.exporter.SaveDatabaseAction) AbstractAction(javax.swing.AbstractAction) HelpAction(org.jabref.gui.help.HelpAction) Action(javax.swing.Action) JabRefException(org.jabref.JabRefException) ActionEvent(java.awt.event.ActionEvent) DBMSType(org.jabref.shared.DBMSType) AbstractAction(javax.swing.AbstractAction) DBMSConnectionProperties(org.jabref.shared.DBMSConnectionProperties)

Example 2 with DBMSConnectionProperties

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();
}
Also used : SharedDatabasePreferences(org.jabref.shared.prefs.SharedDatabasePreferences) IOException(java.io.IOException) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) AutosaveManager(org.jabref.logic.autosaveandbackup.AutosaveManager) DBMSConnectionProperties(org.jabref.shared.DBMSConnectionProperties) AutosaveUIManager(org.jabref.gui.autosaveandbackup.AutosaveUIManager)

Example 3 with DBMSConnectionProperties

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()));
}
Also used : SharedDatabasePreferences(org.jabref.shared.prefs.SharedDatabasePreferences) JabRefFrame(org.jabref.gui.JabRefFrame) NotASharedDatabaseException(org.jabref.shared.exception.NotASharedDatabaseException) Defaults(org.jabref.model.Defaults) BibDatabaseMode(org.jabref.model.database.BibDatabaseMode) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) DBMSConnectionProperties(org.jabref.shared.DBMSConnectionProperties)

Aggregations

DBMSConnectionProperties (org.jabref.shared.DBMSConnectionProperties)3 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)2 SharedDatabasePreferences (org.jabref.shared.prefs.SharedDatabasePreferences)2 ActionEvent (java.awt.event.ActionEvent)1 IOException (java.io.IOException)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 JabRefException (org.jabref.JabRefException)1 JabRefFrame (org.jabref.gui.JabRefFrame)1 AutosaveUIManager (org.jabref.gui.autosaveandbackup.AutosaveUIManager)1 SaveDatabaseAction (org.jabref.gui.exporter.SaveDatabaseAction)1 HelpAction (org.jabref.gui.help.HelpAction)1 AutosaveManager (org.jabref.logic.autosaveandbackup.AutosaveManager)1 Defaults (org.jabref.model.Defaults)1 BibDatabaseMode (org.jabref.model.database.BibDatabaseMode)1 DBMSType (org.jabref.shared.DBMSType)1 NotASharedDatabaseException (org.jabref.shared.exception.NotASharedDatabaseException)1