Search in sources :

Example 6 with BibDatabaseMode

use of org.jabref.model.database.BibDatabaseMode 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

BibDatabaseMode (org.jabref.model.database.BibDatabaseMode)6 JabRefFrame (org.jabref.gui.JabRefFrame)3 EntryType (org.jabref.model.entry.EntryType)3 JButton (javax.swing.JButton)2 JPanel (javax.swing.JPanel)2 CustomEntryType (org.jabref.model.entry.CustomEntryType)2 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)1 BorderLayout (java.awt.BorderLayout)1 Container (java.awt.Container)1 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 GridLayout (java.awt.GridLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1