Search in sources :

Example 21 with Defaults

use of org.jabref.model.Defaults in project jabref by JabRef.

the class Benchmarks method init.

@Setup
public void init() throws Exception {
    Globals.prefs = JabRefPreferences.getInstance();
    Random randomizer = new Random();
    for (int i = 0; i < 1000; i++) {
        BibEntry entry = new BibEntry();
        entry.setCiteKey("id" + i);
        entry.setField("title", "This is my title " + i);
        entry.setField("author", "Firstname Lastname and FirstnameA LastnameA and FirstnameB LastnameB" + i);
        entry.setField("journal", "Journal Title " + i);
        entry.setField("keyword", "testkeyword");
        entry.setField("year", "1" + i);
        entry.setField("rnd", "2" + randomizer.nextInt());
        database.insertEntry(entry);
    }
    BibtexDatabaseWriter<StringSaveSession> databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new);
    StringSaveSession saveSession = databaseWriter.savePartOfDatabase(new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries(), new SavePreferences());
    bibtexString = saveSession.getStringValue();
    latexConversionString = "{A} \\textbf{bold} approach {\\it to} ${{\\Sigma}}{\\Delta}$ modulator \\textsuperscript{2} \\$";
    htmlConversionString = "<b>&Ouml;sterreich</b> &#8211; &amp; characters &#x2aa2; <i>italic</i>";
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) Defaults(org.jabref.model.Defaults) Random(java.util.Random) BibtexDatabaseWriter(org.jabref.logic.exporter.BibtexDatabaseWriter) MetaData(org.jabref.model.metadata.MetaData) SavePreferences(org.jabref.logic.exporter.SavePreferences) StringSaveSession(org.jabref.logic.exporter.StringSaveSession) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) Setup(org.openjdk.jmh.annotations.Setup)

Example 22 with Defaults

use of org.jabref.model.Defaults in project jabref by JabRef.

the class NewDatabaseAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    // Create a new, empty, database.
    BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(BibDatabaseMode.BIBTEX));
    bibDatabaseContext.setMode(mode);
    jabRefFrame.addTab(bibDatabaseContext, true);
    jabRefFrame.output(Localization.lang("New %0 library created.", mode.getFormattedName()));
}
Also used : Defaults(org.jabref.model.Defaults) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext)

Example 23 with Defaults

use of org.jabref.model.Defaults in project jabref by JabRef.

the class NewSubDatabaseAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    // Create a new, empty, database.
    FromAuxDialog dialog = new FromAuxDialog(jabRefFrame, "", true, jabRefFrame.getTabbedPane());
    dialog.setLocationRelativeTo(jabRefFrame);
    dialog.setVisible(true);
    if (dialog.generatePressed()) {
        Defaults defaults = new Defaults(Globals.prefs.getDefaultBibDatabaseMode());
        BasePanel bp = new BasePanel(jabRefFrame, new BibDatabaseContext(dialog.getGenerateDB(), defaults));
        jabRefFrame.addTab(bp, true);
        jabRefFrame.output(Localization.lang("New library created."));
    }
}
Also used : FromAuxDialog(org.jabref.gui.auximport.FromAuxDialog) BasePanel(org.jabref.gui.BasePanel) Defaults(org.jabref.model.Defaults) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext)

Example 24 with Defaults

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

Defaults (org.jabref.model.Defaults)24 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)24 BibDatabase (org.jabref.model.database.BibDatabase)9 ParserResult (org.jabref.logic.importer.ParserResult)8 BibEntry (org.jabref.model.entry.BibEntry)7 Test (org.junit.Test)7 Charset (java.nio.charset.Charset)6 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)6 MetaData (org.jabref.model.metadata.MetaData)6 Path (java.nio.file.Path)5 Scanner (java.util.Scanner)5 BibtexDatabaseWriter (org.jabref.logic.exporter.BibtexDatabaseWriter)5 SavePreferences (org.jabref.logic.exporter.SavePreferences)5 Before (org.junit.Before)5 FileSaveSession (org.jabref.logic.exporter.FileSaveSession)3 SaveException (org.jabref.logic.exporter.SaveException)3 SaveSession (org.jabref.logic.exporter.SaveSession)3 FileDirectoryPreferences (org.jabref.model.metadata.FileDirectoryPreferences)3 IOException (java.io.IOException)2 JabRefFrame (org.jabref.gui.JabRefFrame)2