Skip to content

Commit

Permalink
Merge pull request #9 from JacobTrossing/Add-#2
Browse files Browse the repository at this point in the history
(feat) #2 Adds pop-up asking for password at launch.
  • Loading branch information
Darpos authored Mar 6, 2023
2 parents 4c06177 + cb3cac3 commit e4d4f45
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/org/jabref/gui/DialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -161,6 +162,14 @@ boolean showConfirmationDialogWithOptOutAndWait(String title, String content,
String okButtonLabel, String cancelButtonLabel,
String optOutMessage, Consumer<Boolean> 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<String> showPasswordDialogAndWait(String title, String header, String content);

/**
* Shows a custom dialog without returning any results.
*
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -270,6 +272,30 @@ public <R> Optional<R> showCustomDialogAndWait(javafx.scene.control.Dialog<R> di
return dialog.showAndWait();
}

@Override
public Optional<String> showPasswordDialogAndWait(String title, String header, String content) {
javafx.scene.control.Dialog<String> 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 <V> void showProgressDialog(String title, String content, Task<V> task) {
ProgressDialog progressDialog = new ProgressDialog(task);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -61,6 +63,15 @@ public JabRefGUI(Stage mainStage, List<ParserResult> 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) {
Expand Down

0 comments on commit e4d4f45

Please sign in to comment.