Search in sources :

Example 1 with SharedDatabasePreferences

use of org.jabref.shared.prefs.SharedDatabasePreferences in project jabref by JabRef.

the class ArgumentProcessor method resetPreferences.

private void resetPreferences(String value) {
    if ("all".equals(value.trim())) {
        try {
            System.out.println(Localization.lang("Setting all preferences to default values."));
            Globals.prefs.clear();
            new SharedDatabasePreferences().clear();
        } catch (BackingStoreException e) {
            System.err.println(Localization.lang("Unable to clear preferences."));
            LOGGER.error("Unable to clear preferences", e);
        }
    } else {
        String[] keys = value.split(",");
        for (String key : keys) {
            if (Globals.prefs.hasKey(key.trim())) {
                System.out.println(Localization.lang("Resetting preference key '%0'", key.trim()));
                Globals.prefs.clear(key.trim());
            } else {
                System.out.println(Localization.lang("Unknown preference key '%0'", key.trim()));
            }
        }
    }
}
Also used : SharedDatabasePreferences(org.jabref.shared.prefs.SharedDatabasePreferences) BackingStoreException(java.util.prefs.BackingStoreException)

Example 2 with SharedDatabasePreferences

use of org.jabref.shared.prefs.SharedDatabasePreferences 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 SharedDatabasePreferences

use of org.jabref.shared.prefs.SharedDatabasePreferences 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

SharedDatabasePreferences (org.jabref.shared.prefs.SharedDatabasePreferences)3 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)2 DBMSConnectionProperties (org.jabref.shared.DBMSConnectionProperties)2 IOException (java.io.IOException)1 BackingStoreException (java.util.prefs.BackingStoreException)1 JabRefFrame (org.jabref.gui.JabRefFrame)1 AutosaveUIManager (org.jabref.gui.autosaveandbackup.AutosaveUIManager)1 AutosaveManager (org.jabref.logic.autosaveandbackup.AutosaveManager)1 Defaults (org.jabref.model.Defaults)1 BibDatabaseMode (org.jabref.model.database.BibDatabaseMode)1 NotASharedDatabaseException (org.jabref.shared.exception.NotASharedDatabaseException)1