Skip to content

Commit e4d4f45

Browse files
authored
Merge pull request #9 from JacobTrossing/Add-#2
(feat) #2 Adds pop-up asking for password at launch.
2 parents 4c06177 + cb3cac3 commit e4d4f45

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/main/java/org/jabref/gui/DialogService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import javafx.scene.control.ChoiceDialog;
1515
import javafx.scene.control.DialogPane;
1616
import javafx.scene.control.TextInputDialog;
17+
import org.controlsfx.control.textfield.CustomPasswordField;
1718

1819
import org.jabref.gui.util.BaseDialog;
1920
import org.jabref.gui.util.DirectoryDialogConfiguration;
@@ -161,6 +162,14 @@ boolean showConfirmationDialogWithOptOutAndWait(String title, String content,
161162
String okButtonLabel, String cancelButtonLabel,
162163
String optOutMessage, Consumer<Boolean> optOutAction);
163164

165+
/**
166+
* This will create and display new {@link CustomPasswordField} that doesn't show the text, and two buttons
167+
* one cancel and one ok.
168+
*
169+
* @return the entered password if pressed "OK", null otherwise
170+
*/
171+
Optional<String> showPasswordDialogAndWait(String title, String header, String content);
172+
164173
/**
165174
* Shows a custom dialog without returning any results.
166175
*

src/main/java/org/jabref/gui/JabRefDialogService.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import javafx.scene.control.DialogPane;
2727
import javafx.scene.control.Label;
2828
import javafx.scene.control.TextInputDialog;
29+
import javafx.scene.layout.HBox;
2930
import javafx.scene.layout.Pane;
3031
import javafx.scene.layout.Region;
3132
import javafx.scene.layout.VBox;
@@ -49,6 +50,7 @@
4950
import com.tobiasdiez.easybind.EasyBind;
5051
import org.controlsfx.control.Notifications;
5152
import org.controlsfx.control.TaskProgressView;
53+
import org.controlsfx.control.textfield.CustomPasswordField;
5254
import org.controlsfx.dialog.ExceptionDialog;
5355
import org.controlsfx.dialog.ProgressDialog;
5456
import org.slf4j.Logger;
@@ -270,6 +272,30 @@ public <R> Optional<R> showCustomDialogAndWait(javafx.scene.control.Dialog<R> di
270272
return dialog.showAndWait();
271273
}
272274

275+
@Override
276+
public Optional<String> showPasswordDialogAndWait(String title, String header, String content) {
277+
javafx.scene.control.Dialog<String> dialog = new javafx.scene.control.Dialog<>();
278+
dialog.setTitle(title);
279+
dialog.setHeaderText(header);
280+
281+
CustomPasswordField passwordField = new CustomPasswordField();
282+
283+
HBox box = new HBox();
284+
box.setSpacing(10);
285+
box.getChildren().addAll(new Label(content), passwordField);
286+
dialog.setTitle(title);
287+
dialog.getDialogPane().setContent(box);
288+
289+
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK);
290+
dialog.setResultConverter(dialogButton -> {
291+
if (dialogButton == ButtonType.OK) {
292+
return passwordField.getText();
293+
}
294+
return null;
295+
});
296+
return dialog.showAndWait();
297+
}
298+
273299
@Override
274300
public <V> void showProgressDialog(String title, String content, Task<V> task) {
275301
ProgressDialog progressDialog = new ProgressDialog(task);

src/main/java/org/jabref/gui/JabRefGUI.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.List;
77
import java.util.stream.Collectors;
88

9+
import com.airhacks.afterburner.injection.Injector;
910
import javafx.application.Platform;
1011
import javafx.scene.Scene;
1112
import javafx.scene.input.KeyEvent;
@@ -20,6 +21,7 @@
2021
import org.jabref.gui.shared.SharedDatabaseUIManager;
2122
import org.jabref.logic.importer.ParserResult;
2223
import org.jabref.logic.l10n.Localization;
24+
import org.jabref.logic.net.ProxyRegisterer;
2325
import org.jabref.logic.shared.DatabaseNotSupportedException;
2426
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
2527
import org.jabref.logic.shared.exception.NotASharedDatabaseException;
@@ -61,6 +63,15 @@ public JabRefGUI(Stage mainStage, List<ParserResult> databases, boolean isBlank,
6163
Globals.TASK_EXECUTOR,
6264
preferencesService.getInternalPreferences())
6365
.checkForNewVersionDelayed();
66+
67+
if (preferencesService.getProxyPreferences().shouldUseProxy() && preferencesService.getProxyPreferences().shouldUseAuthentication()){
68+
DialogService dialogService = Injector.instantiateModelOrService(DialogService.class);
69+
dialogService.showPasswordDialogAndWait("Proxy configuration", "Proxy requires password","Password")
70+
.ifPresent(newPassword -> {
71+
preferencesService.getProxyPreferences().setPassword(newPassword);
72+
ProxyRegisterer.register(preferencesService.getProxyPreferences());
73+
});
74+
}
6475
}
6576

6677
private void openWindow(Stage mainStage) {

0 commit comments

Comments
 (0)