|
1 | 1 | package org.jabref.gui.preferences;
|
2 | 2 |
|
| 3 | +import java.net.MalformedURLException; |
3 | 4 | import java.util.ArrayList;
|
4 | 5 | import java.util.List;
|
5 | 6 | import java.util.Optional;
|
|
9 | 10 | import javafx.beans.property.SimpleStringProperty;
|
10 | 11 | import javafx.beans.property.StringProperty;
|
11 | 12 |
|
| 13 | +import javafx.scene.control.ButtonType; |
| 14 | +import javafx.scene.control.DialogPane; |
| 15 | +import javafx.scene.control.Label; |
| 16 | +import javafx.scene.control.TextField; |
| 17 | +import javafx.scene.layout.GridPane; |
| 18 | +import kong.unirest.UnirestException; |
12 | 19 | import org.jabref.Globals;
|
13 | 20 | import org.jabref.gui.DialogService;
|
14 | 21 | import org.jabref.gui.remote.JabRefMessageHandler;
|
15 | 22 | import org.jabref.logic.l10n.Localization;
|
16 | 23 | import org.jabref.logic.net.ProxyPreferences;
|
17 | 24 | import org.jabref.logic.net.ProxyRegisterer;
|
| 25 | +import org.jabref.logic.net.URLDownload; |
18 | 26 | import org.jabref.logic.remote.RemotePreferences;
|
19 | 27 | import org.jabref.logic.remote.RemoteUtil;
|
20 | 28 | import org.jabref.model.strings.StringUtil;
|
@@ -215,6 +223,52 @@ public boolean validateSettings() {
|
215 | 223 | return true;
|
216 | 224 | }
|
217 | 225 |
|
| 226 | + public void checkConnection() { |
| 227 | + DialogPane dialogPane = new DialogPane(); |
| 228 | + GridPane settingsPane = new GridPane(); |
| 229 | + settingsPane.setHgap(4.0); |
| 230 | + settingsPane.setVgap(4.0); |
| 231 | + |
| 232 | + Label messageLabel = new Label(); |
| 233 | + messageLabel.setText(Localization.lang("Warning: your settings will be saved.\nEnter any URL to check connection to:")); |
| 234 | + |
| 235 | + TextField url = new TextField(); |
| 236 | + url.setText("http://"); |
| 237 | + |
| 238 | + settingsPane.add(messageLabel, 1, 0); |
| 239 | + |
| 240 | + settingsPane.add(url, 1, 1); |
| 241 | + dialogPane.setContent(settingsPane); |
| 242 | + String title = Localization.lang("Check Proxy Setting"); |
| 243 | + dialogService.showCustomDialogAndWait( |
| 244 | + title, |
| 245 | + dialogPane, |
| 246 | + ButtonType.OK, ButtonType.CANCEL) |
| 247 | + .ifPresent(btn -> { |
| 248 | + if (btn == ButtonType.OK) { |
| 249 | + String connectionProblemText = Localization.lang("Problem with connection: "); |
| 250 | + String connectionSuccessText = Localization.lang("Connection Successful!"); |
| 251 | + storeProxySettings(); |
| 252 | + System.out.println(url.getText()); |
| 253 | + URLDownload dl; |
| 254 | + try { |
| 255 | + dl = new URLDownload(url.getText()); |
| 256 | + int connectionStatus = dl.checkConnection(); |
| 257 | + if (connectionStatus == 200) { |
| 258 | + dialogService.showInformationDialogAndWait(title, connectionSuccessText); |
| 259 | + } else { |
| 260 | + dialogService.showErrorDialogAndWait(title, connectionProblemText + Localization.lang("Request failed with status code ") + connectionStatus); |
| 261 | + } |
| 262 | + } catch (MalformedURLException e) { |
| 263 | + dialogService.showErrorDialogAndWait(title, connectionProblemText + e.getMessage()); |
| 264 | + } catch (UnirestException e) { |
| 265 | + dialogService.showErrorDialogAndWait(title, connectionProblemText + e.getMessage()); |
| 266 | + } |
| 267 | + } |
| 268 | + } |
| 269 | + ); |
| 270 | + } |
| 271 | + |
218 | 272 | @Override
|
219 | 273 | public List<String> getRestartWarnings() {
|
220 | 274 | return restartWarning;
|
|
0 commit comments