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();
}
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));
}
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);
}
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));
}
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);
}
Aggregations