Search in sources :

Example 11 with BibDatabaseContext

use of org.jabref.model.database.BibDatabaseContext 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 12 with BibDatabaseContext

use of org.jabref.model.database.BibDatabaseContext in project jabref by JabRef.

the class CleanupWorkerTest method setUp.

@Before
public void setUp() throws IOException {
    pdfFolder = bibFolder.newFolder();
    MetaData metaData = new MetaData();
    metaData.setDefaultFileDirectory(pdfFolder.getAbsolutePath());
    BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(), metaData, new Defaults());
    context.setDatabaseFile(bibFolder.newFile("test.bib"));
    FileDirectoryPreferences fileDirPrefs = mock(FileDirectoryPreferences.class);
    //Biblocation as Primary overwrites all other dirs
    when(fileDirPrefs.isBibLocationAsPrimary()).thenReturn(true);
    worker = new CleanupWorker(context, new CleanupPreferences("\\bibtexkey", //empty fileDirPattern for backwards compatibility
    "", mock(LayoutFormatterPreferences.class), fileDirPrefs));
}
Also used : FileDirectoryPreferences(org.jabref.model.metadata.FileDirectoryPreferences) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) Defaults(org.jabref.model.Defaults) MetaData(org.jabref.model.metadata.MetaData) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) BibDatabase(org.jabref.model.database.BibDatabase) Before(org.junit.Before)

Example 13 with BibDatabaseContext

use of org.jabref.model.database.BibDatabaseContext in project jabref by JabRef.

the class RenamePdfCleanupTest method setUp.

@Before
public void setUp() throws Exception {
    MetaData metaData = new MetaData();
    context = new BibDatabaseContext(new BibDatabase(), metaData, new Defaults());
    context.setDatabaseFile(testFolder.newFile("test.bib"));
    fileDirPrefs = mock(FileDirectoryPreferences.class);
    //Set Biblocation as Primary Directory, otherwise the tmp folders won't be cleaned up correctly
    when(fileDirPrefs.isBibLocationAsPrimary()).thenReturn(true);
    entry = new BibEntry();
    entry.setCiteKey("Toot");
    layoutFormatterPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS);
}
Also used : FileDirectoryPreferences(org.jabref.model.metadata.FileDirectoryPreferences) BibEntry(org.jabref.model.entry.BibEntry) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) Defaults(org.jabref.model.Defaults) MetaData(org.jabref.model.metadata.MetaData) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) BibDatabase(org.jabref.model.database.BibDatabase) Before(org.junit.Before)

Example 14 with BibDatabaseContext

use of org.jabref.model.database.BibDatabaseContext in project jabref by JabRef.

the class BibTeXMLExporterTestFiles method setUp.

@Before
public void setUp() throws Exception {
    resourceDir = Paths.get(BibTeXMLExporterTestFiles.class.getResource("").toURI());
    databaseContext = new BibDatabaseContext();
    charset = StandardCharsets.UTF_8;
    bibtexmlExportFormat = new BibTeXMLExportFormat();
    tempFile = testFolder.newFile();
    testImporter = new BibtexImporter(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS));
}
Also used : BibtexImporter(org.jabref.logic.importer.fileformat.BibtexImporter) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) Before(org.junit.Before)

Example 15 with BibDatabaseContext

use of org.jabref.model.database.BibDatabaseContext in project jabref by JabRef.

the class MoveFilesCleanupTest method setUp.

@Before
public void setUp() throws IOException {
    MetaData metaData = new MetaData();
    pdfFolder = bibFolder.newFolder();
    metaData.setDefaultFileDirectory(pdfFolder.getAbsolutePath());
    databaseContext = new BibDatabaseContext(new BibDatabase(), metaData, new Defaults());
    databaseContext.setDatabaseFile(bibFolder.newFile("test.bib"));
    entry = new BibEntry();
    entry.setCiteKey("Toot");
    entry.setField("title", "test title");
    fileDirPrefs = mock(FileDirectoryPreferences.class);
    //Biblocation as Primary overwrites all other dirs, therefore we set it to false here
    when(fileDirPrefs.isBibLocationAsPrimary()).thenReturn(false);
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) FileDirectoryPreferences(org.jabref.model.metadata.FileDirectoryPreferences) Defaults(org.jabref.model.Defaults) MetaData(org.jabref.model.metadata.MetaData) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) BibDatabase(org.jabref.model.database.BibDatabase) Before(org.junit.Before)

Aggregations

BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)48 Defaults (org.jabref.model.Defaults)24 Before (org.junit.Before)16 BibDatabase (org.jabref.model.database.BibDatabase)15 Test (org.junit.Test)13 BibEntry (org.jabref.model.entry.BibEntry)11 ParserResult (org.jabref.logic.importer.ParserResult)9 MetaData (org.jabref.model.metadata.MetaData)8 Charset (java.nio.charset.Charset)6 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)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 IOException (java.io.IOException)4 SaveException (org.jabref.logic.exporter.SaveException)4 BibtexImporter (org.jabref.logic.importer.fileformat.BibtexImporter)4 LayoutFormatterPreferences (org.jabref.logic.layout.LayoutFormatterPreferences)4 FileSaveSession (org.jabref.logic.exporter.FileSaveSession)3 SaveSession (org.jabref.logic.exporter.SaveSession)3