diff --git a/src/main/java/org/jabref/gui/DialogService.java b/src/main/java/org/jabref/gui/DialogService.java index 26cf46c00a1..3be1432d54e 100644 --- a/src/main/java/org/jabref/gui/DialogService.java +++ b/src/main/java/org/jabref/gui/DialogService.java @@ -14,6 +14,7 @@ import javafx.scene.control.ChoiceDialog; import javafx.scene.control.DialogPane; import javafx.scene.control.TextInputDialog; +import org.controlsfx.control.textfield.CustomPasswordField; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.DirectoryDialogConfiguration; @@ -161,6 +162,14 @@ boolean showConfirmationDialogWithOptOutAndWait(String title, String content, String okButtonLabel, String cancelButtonLabel, String optOutMessage, Consumer optOutAction); + /** + * This will create and display new {@link CustomPasswordField} that doesn't show the text, and two buttons + * one cancel and one ok. + * + * @return the entered password if pressed "OK", null otherwise + */ + Optional showPasswordDialogAndWait(String title, String header, String content); + /** * Shows a custom dialog without returning any results. * diff --git a/src/main/java/org/jabref/gui/JabRefDialogService.java b/src/main/java/org/jabref/gui/JabRefDialogService.java index d21e0b3b9d9..9709223cc2b 100644 --- a/src/main/java/org/jabref/gui/JabRefDialogService.java +++ b/src/main/java/org/jabref/gui/JabRefDialogService.java @@ -26,6 +26,7 @@ import javafx.scene.control.DialogPane; import javafx.scene.control.Label; import javafx.scene.control.TextInputDialog; +import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.Region; import javafx.scene.layout.VBox; @@ -49,6 +50,7 @@ import com.tobiasdiez.easybind.EasyBind; import org.controlsfx.control.Notifications; import org.controlsfx.control.TaskProgressView; +import org.controlsfx.control.textfield.CustomPasswordField; import org.controlsfx.dialog.ExceptionDialog; import org.controlsfx.dialog.ProgressDialog; import org.slf4j.Logger; @@ -270,6 +272,30 @@ public Optional showCustomDialogAndWait(javafx.scene.control.Dialog di return dialog.showAndWait(); } + @Override + public Optional showPasswordDialogAndWait(String title, String header, String content) { + javafx.scene.control.Dialog dialog = new javafx.scene.control.Dialog<>(); + dialog.setTitle(title); + dialog.setHeaderText(header); + + CustomPasswordField passwordField = new CustomPasswordField(); + + HBox box = new HBox(); + box.setSpacing(10); + box.getChildren().addAll(new Label(content), passwordField); + dialog.setTitle(title); + dialog.getDialogPane().setContent(box); + + dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK); + dialog.setResultConverter(dialogButton -> { + if (dialogButton == ButtonType.OK) { + return passwordField.getText(); + } + return null; + }); + return dialog.showAndWait(); + } + @Override public void showProgressDialog(String title, String content, Task task) { ProgressDialog progressDialog = new ProgressDialog(task); diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index 4f5963945ea..5dda14310aa 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.stream.Collectors; +import com.airhacks.afterburner.injection.Injector; import javafx.application.Platform; import javafx.scene.Scene; import javafx.scene.input.KeyEvent; @@ -20,6 +21,7 @@ import org.jabref.gui.shared.SharedDatabaseUIManager; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.net.ProxyRegisterer; import org.jabref.logic.shared.DatabaseNotSupportedException; import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; import org.jabref.logic.shared.exception.NotASharedDatabaseException; @@ -61,6 +63,15 @@ public JabRefGUI(Stage mainStage, List databases, boolean isBlank, Globals.TASK_EXECUTOR, preferencesService.getInternalPreferences()) .checkForNewVersionDelayed(); + + if (preferencesService.getProxyPreferences().shouldUseProxy() && preferencesService.getProxyPreferences().shouldUseAuthentication()){ + DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); + dialogService.showPasswordDialogAndWait("Proxy configuration", "Proxy requires password","Password") + .ifPresent(newPassword -> { + preferencesService.getProxyPreferences().setPassword(newPassword); + ProxyRegisterer.register(preferencesService.getProxyPreferences()); + }); + } } private void openWindow(Stage mainStage) {