Skip to content

Commit

Permalink
Merge branch 'sharelatex' of github.com:JabRef/jabref into sharelatex
Browse files Browse the repository at this point in the history
* 'sharelatex' of github.com:JabRef/jabref:
  Refactor ShareLatexPreferences
  • Loading branch information
Siedlerchr committed Feb 7, 2018
2 parents 10f1bad + 4920b9f commit 3eadbfb
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;

import org.jabref.Globals;
import org.jabref.JabRefGUI;
import org.jabref.gui.AbstractController;
import org.jabref.gui.DialogService;
import org.jabref.gui.FXDialog;
import org.jabref.gui.FXDialogService;
import org.jabref.logic.sharelatex.ShareLatexManager;
import org.jabref.logic.sharelatex.SharelatexConnectionProperties;
import org.jabref.logic.sharelatex.SharelatexPreferences;
import org.jabref.logic.sharelatex.ShareLatexPreferences;

public class ShareLatexLoginDialogController extends AbstractController<ShareLatexLoginDialogViewModel> {

Expand Down Expand Up @@ -49,7 +50,7 @@ private void signIn() {
} else {
//TODO: Wait until pdf + injection stuff gets merged

props = new SharelatexConnectionProperties(new SharelatexPreferences("default"));
props = new SharelatexConnectionProperties(Globals.prefs.getShareLatexPreferences());
props.setUrl(tbAddress.getText());
props.setUser(tbUsername.getText());
props.setPassword(tbPassword.getText());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.jabref.logic.sharelatex;

import java.util.Optional;
import java.util.prefs.BackingStoreException;

public class ShareLatexPreferences {

private String defaultNode;
private String parentNode;
private String sharelatexUser;
private String shareLatexUrl;
private String shareLatexPassword;
private boolean shareLatexRememberPassword;
private String shareLatexProject;

public ShareLatexPreferences(String defaultNode, String parentNode, String getSharelatexUser, String shareLatexUrl, String shareLatexPassword, boolean shareLatexRememberPassword, String shareLatexProject) {
this.defaultNode = defaultNode;
this.parentNode = parentNode;
this.sharelatexUser = getSharelatexUser;
this.shareLatexUrl = shareLatexUrl;
this.shareLatexPassword = shareLatexPassword;
this.shareLatexRememberPassword = shareLatexRememberPassword;
this.shareLatexProject = shareLatexProject;
}

public String getSharelatexUrl() {
return getOptionalValue(shareLatexUrl).orElse("https://www.sharelatex.com");
}

public Optional<String> getUser() {
return getOptionalValue(sharelatexUser);
}

public Optional<String> getPassword() {
return getOptionalValue(shareLatexPassword);
}

public Optional<String> getDefaultProject() {
return getOptionalValue(shareLatexProject);
}


public String getDefaultNode() {
return defaultNode;
}

public String getParentNode() {
return parentNode;
}

public boolean getShareLatexRememberPassword() {
return shareLatexRememberPassword;
}


public void setSharelatexUrl(String url) {
this.shareLatexUrl = url;
}

public void setSharelatexUser(String user) {
this.sharelatexUser = user;
}

public void setSharelatexPassword(String pwd) {
this.shareLatexPassword = pwd;
}

public void setSharelatexProject(String project) {
this.shareLatexProject = project;
}

public void setRememberPassword(boolean rememberPassword) {
this.shareLatexRememberPassword = rememberPassword;
}


public void clear() throws BackingStoreException {
}

private Optional<String> getOptionalValue(String key) {
return Optional.ofNullable(key);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public SharelatexConnectionProperties() {
// no data
}

public SharelatexConnectionProperties(SharelatexPreferences prefs) {
public SharelatexConnectionProperties(ShareLatexPreferences prefs) {
setFromPreferences(prefs);
}

Expand Down Expand Up @@ -71,7 +71,7 @@ public boolean isValid() {
&& Objects.nonNull(project);
}

private void setFromPreferences(SharelatexPreferences prefs) {
private void setFromPreferences(ShareLatexPreferences prefs) {

this.url = prefs.getSharelatexUrl();
prefs.getDefaultProject().ifPresent(proj -> this.project = proj);
Expand Down

This file was deleted.

30 changes: 30 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.logic.protectedterms.ProtectedTermsPreferences;
import org.jabref.logic.remote.RemotePreferences;
import org.jabref.logic.sharelatex.ShareLatexPreferences;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.UpdateFieldPreferences;
import org.jabref.logic.util.Version;
Expand Down Expand Up @@ -243,6 +244,15 @@ public class JabRefPreferences implements PreferencesService {
public static final String TIME_STAMP_FORMAT = "timeStampFormat";
public static final String OVERWRITE_TIME_STAMP = "overwriteTimeStamp";

// Sharelatex preferences
public static final String DEFAULT_NODE = "default";
public static final String PARENT_NODE = "jabref-sharelatex";
public static final String SHARELATEX_URL = "sharelatexUrl";
public static final String SHARELATEX_USER = "sharelatexUser";
public static final String SHARELATEX_PASSWORD = "sharelatexPassword";
public static final String SHARELATEX_REMEMBER_PASSWORD = "sharelatexRememberPassword";
public static final String SHARELATEX_PROJECT = "sharelatexProject";

public static final String WARN_ABOUT_DUPLICATES_IN_INSPECTION = "warnAboutDuplicatesInInspection";
public static final String UNMARK_ALL_ENTRIES_BEFORE_IMPORTING = "unmarkAllEntriesBeforeImporting";
public static final String MARK_IMPORTED_ENTRIES = "markImportedEntries";
Expand Down Expand Up @@ -1423,6 +1433,26 @@ public TimestampPreferences getTimestampPreferences() {
return new TimestampPreferences(getBoolean(USE_TIME_STAMP), getBoolean(UPDATE_TIMESTAMP), get(TIME_STAMP_FIELD), get(TIME_STAMP_FORMAT), getBoolean(OVERWRITE_TIME_STAMP));
}

public ShareLatexPreferences getShareLatexPreferences() {
return new ShareLatexPreferences(get(DEFAULT_NODE), get(PARENT_NODE), get(SHARELATEX_USER), get(SHARELATEX_URL), get(SHARELATEX_PASSWORD), getBoolean(SHARELATEX_REMEMBER_PASSWORD), get(SHARELATEX_PROJECT));
}

public void storeShareLatexPreferences(ShareLatexPreferences sharelatexPreferences) {
put(JabRefPreferences.DEFAULT_NODE, sharelatexPreferences.getDefaultNode());
put(JabRefPreferences.PARENT_NODE, sharelatexPreferences.getParentNode());
sharelatexPreferences.getUser().ifPresent(
user -> put(JabRefPreferences.SHARELATEX_USER, user)
);
put(JabRefPreferences.SHARELATEX_URL, sharelatexPreferences.getSharelatexUrl());
sharelatexPreferences.getPassword().ifPresent(
password -> put(JabRefPreferences.SHARELATEX_PASSWORD, password)
);
putBoolean(JabRefPreferences.SHARELATEX_REMEMBER_PASSWORD, sharelatexPreferences.getShareLatexRememberPassword());
sharelatexPreferences.getDefaultProject().ifPresent(
project -> put(JabRefPreferences.SHARELATEX_PROJECT, project)
);
}

public LayoutFormatterPreferences getLayoutFormatterPreferences(
JournalAbbreviationLoader journalAbbreviationLoader) {
Objects.requireNonNull(journalAbbreviationLoader);
Expand Down

0 comments on commit 3eadbfb

Please sign in to comment.