-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved gui layout consistency Remove unused exception from shared db
- Loading branch information
1 parent
418aaad
commit 74ce5b9
Showing
11 changed files
with
218 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/org/jabref/logic/sharelatex/SharelatexConnectionProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.jabref.logic.sharelatex; | ||
|
||
import java.security.GeneralSecurityException; | ||
import java.util.Objects; | ||
|
||
import org.jabref.shared.security.Password; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class SharelatexConnectionProperties { | ||
|
||
private static final Log LOGGER = LogFactory.getLog(SharelatexConnectionProperties.class); | ||
|
||
private String user; | ||
private String password; | ||
private String url; | ||
private String project; | ||
|
||
public SharelatexConnectionProperties() { | ||
// no data | ||
} | ||
|
||
public SharelatexConnectionProperties(SharelatexPreferences prefs) { | ||
setFromPreferences(prefs); | ||
} | ||
|
||
public SharelatexConnectionProperties(String url, String user, String password, String project) { | ||
this.url = url; | ||
this.user = user; | ||
this.password = password; | ||
this.project = project; | ||
} | ||
|
||
public String getUser() { | ||
return user; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public String getProject() { | ||
return project; | ||
} | ||
|
||
public boolean isValid() { | ||
return Objects.nonNull(url) | ||
&& Objects.nonNull(user) | ||
&& Objects.nonNull(password) | ||
&& Objects.nonNull(project); | ||
} | ||
|
||
private void setFromPreferences(SharelatexPreferences prefs) { | ||
|
||
this.url = prefs.getSharelatexUrl(); | ||
prefs.getDefaultProject().ifPresent(proj -> this.project = proj); | ||
|
||
if (prefs.getUser().isPresent()) { | ||
this.user = prefs.getUser().get(); | ||
if (prefs.getPassword().isPresent()) { | ||
try { | ||
this.password = new Password(prefs.getPassword().get().toCharArray(), prefs.getUser().get()).decrypt(); | ||
} catch (GeneralSecurityException e) { | ||
LOGGER.error("Could not decrypt password", e); | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/org/jabref/logic/sharelatex/SharelatexPreferences.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.jabref.logic.sharelatex; | ||
|
||
import java.util.Optional; | ||
import java.util.prefs.BackingStoreException; | ||
import java.util.prefs.Preferences; | ||
|
||
import org.jabref.JabRefMain; | ||
|
||
public class SharelatexPreferences { | ||
|
||
private static final String DEFAULT_NODE = "default"; | ||
private static final String PARENT_NODE = "jabref-sharelatex"; | ||
|
||
private static final String SHARELATEX_URL = "sharelatexUrl"; | ||
private static final String SHARELATEX_USER = "sharelatexUser"; | ||
private static final String SHARELATEX_PASSWORD = "sharelatexPassword"; | ||
private static final String SHARELATEX_REMEMBER_PASSWORD = "sharelatexRememberPassword"; | ||
private static final String SHARELATEX_PROJECT = "sharelatexProject"; | ||
|
||
// This {@link Preferences} is used only for things which should not appear in real JabRefPreferences due to security reasons. | ||
private final Preferences internalPrefs; | ||
|
||
public SharelatexPreferences() { | ||
this(DEFAULT_NODE); | ||
|
||
} | ||
|
||
public SharelatexPreferences(String sharelatexId) { | ||
internalPrefs = Preferences.userNodeForPackage(JabRefMain.class).parent().node(PARENT_NODE).node(sharelatexId); | ||
} | ||
|
||
public String getSharelatexUrl() { | ||
return getOptionalValue(SHARELATEX_URL).orElse("https://www.sharelatex.com"); | ||
} | ||
|
||
public Optional<String> getUser() { | ||
return getOptionalValue(SHARELATEX_USER); | ||
} | ||
|
||
public Optional<String> getPassword() { | ||
return getOptionalValue(SHARELATEX_PASSWORD); | ||
} | ||
|
||
public Optional<String> getDefaultProject() { | ||
return getOptionalValue(SHARELATEX_PROJECT); | ||
} | ||
|
||
public void setSharelatexUrl(String url) { | ||
internalPrefs.put(SHARELATEX_URL, url); | ||
} | ||
|
||
public void setSharelatexUser(String user) { | ||
internalPrefs.put(SHARELATEX_USER, user); | ||
} | ||
|
||
public void setSharelatexPassword(String pwd) { | ||
internalPrefs.put(SHARELATEX_PASSWORD, pwd); | ||
} | ||
|
||
public void setSharelatexProject(String project) { | ||
internalPrefs.put(SHARELATEX_PROJECT, project); | ||
} | ||
|
||
public void setRememberPassword(boolean rememberPassword) { | ||
internalPrefs.putBoolean(SHARELATEX_REMEMBER_PASSWORD, rememberPassword); | ||
} | ||
|
||
public void clearPassword() { | ||
internalPrefs.remove(SHARELATEX_PASSWORD); | ||
} | ||
|
||
public void clear() throws BackingStoreException { | ||
internalPrefs.clear(); | ||
} | ||
|
||
private Optional<String> getOptionalValue(String key) { | ||
return Optional.ofNullable(internalPrefs.get(key, null)); | ||
} | ||
|
||
public static void clearAll() throws BackingStoreException { | ||
Preferences.userNodeForPackage(JabRefMain.class).parent().node(PARENT_NODE).clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 31 additions & 29 deletions
60
src/main/resources/org/jabref/gui/sharelatex/ShareLatexLoginDialog.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.ButtonBar?> | ||
<?import javafx.scene.control.DialogPane?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.PasswordField?> | ||
<?import javafx.scene.control.TextField?> | ||
<?import javafx.scene.layout.BorderPane?> | ||
<?import javafx.scene.layout.ColumnConstraints?> | ||
<?import javafx.scene.layout.GridPane?> | ||
<?import javafx.scene.layout.RowConstraints?> | ||
|
||
<DialogPane xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.sharelatex.ShareLatexLoginDialogController"> | ||
<DialogPane prefHeight="220.0" prefWidth="362.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.sharelatex.ShareLatexLoginDialogController"> | ||
<content> | ||
<GridPane alignment="CENTER" hgap="10.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="140.0" prefWidth="270.0" vgap="10.0"> | ||
<columnConstraints> | ||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="10.0" prefWidth="100.0" /> | ||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="100.0" /> | ||
</columnConstraints> | ||
<rowConstraints> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
</rowConstraints> | ||
<children> | ||
<Label text="Server Address" /> | ||
<TextField id="tbAddress" fx:id="tbAddress" GridPane.columnIndex="1" /> | ||
<TextField id="tbUsername" fx:id="tbUsername" GridPane.columnIndex="1" GridPane.rowIndex="1" /> | ||
<Label alignment="CENTER_RIGHT" text="%Username" GridPane.rowIndex="1" /> | ||
<Label text="%Password" GridPane.rowIndex="2" /> | ||
<PasswordField id="tbPassword" fx:id="pfPassword" GridPane.columnIndex="1" GridPane.rowIndex="2" /> | ||
<ButtonBar prefHeight="40.0" prefWidth="200.0" GridPane.columnSpan="2" GridPane.rowIndex="3"> | ||
<BorderPane prefHeight="200.0" prefWidth="402.0"> | ||
<center> | ||
<GridPane alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="140.0" prefWidth="270.0"> | ||
<columnConstraints> | ||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="10.0" prefWidth="100.0" /> | ||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="100.0" /> | ||
</columnConstraints> | ||
<rowConstraints> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> | ||
</rowConstraints> | ||
<children> | ||
<Label text="Server Address" /> | ||
<TextField id="tbAddress" fx:id="tbAddress" prefHeight="25.0" prefWidth="174.0" text="https://www.sharelatex.com" GridPane.columnIndex="1" /> | ||
<TextField id="tbUsername" fx:id="tbUsername" GridPane.columnIndex="1" GridPane.rowIndex="1" /> | ||
<Label alignment="CENTER_RIGHT" text="%Username" GridPane.rowIndex="1" /> | ||
<Label text="%Password" GridPane.rowIndex="2" /> | ||
<PasswordField id="tbPassword" fx:id="pfPassword" GridPane.columnIndex="1" GridPane.rowIndex="2" /> | ||
|
||
</children> | ||
</GridPane> | ||
</center> | ||
<bottom> | ||
<ButtonBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER"> | ||
<buttons> | ||
<Button id="btnCancel" cancelButton="true" mnemonicParsing="false" onAction="#closeDialog" text="%Cancel" /> | ||
<Button id="btnLogin" mnemonicParsing="false" onAction="#signIn" text="Login" /> | ||
<Button id="btnLogin" mnemonicParsing="false" onAction="#signIn" text="Login" ButtonBar.buttonData="OK_DONE" /> | ||
<Button id="btnCancel" cancelButton="true" mnemonicParsing="false" onAction="#closeDialog" text="%Cancel" ButtonBar.buttonData="CANCEL_CLOSE" /> | ||
</buttons> | ||
</ButtonBar> | ||
|
||
</children> | ||
<padding> | ||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" /> | ||
</padding> | ||
</GridPane> | ||
</bottom> | ||
</BorderPane> | ||
</content> | ||
</DialogPane> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.