Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue201/port-je-obsadeny-dialog #292

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package digital.slovensko.autogram.core.errors;

public class PortIsUsedException extends AutogramException {
public PortIsUsedException() {
super("Port is used", "Port is used", "Port is used");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.sun.net.httpserver.HttpsServer;

import digital.slovensko.autogram.core.Autogram;
import digital.slovensko.autogram.core.errors.PortIsUsedException;
import digital.slovensko.autogram.server.filters.AutogramCorsFilter;

public class AutogramServer {
Expand Down Expand Up @@ -89,7 +90,7 @@ public void configure(HttpsParameters params) {
return server;

} catch (BindException e) {
throw new RuntimeException("error.launchFailed.header port is already in use", e); // TODO
throw new PortIsUsedException();

} catch (Exception e) {
throw new RuntimeException("error.serverNotCreated", e); // TODO
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package digital.slovensko.autogram.ui.gui;

import digital.slovensko.autogram.core.Autogram;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class ErrorBeforeMainMenuController implements SuppressedFocusController {
private final GUI gui;
private final Stage widowStage;
private final Autogram autogram;
private final int portNumber;

@FXML
VBox mainBox;

@FXML
Text textField;

public ErrorBeforeMainMenuController(GUI gui, Stage widowStage, Autogram autogram, int portNumber) {
this.gui = gui;
this.autogram = autogram;
this.widowStage = widowStage;
this.portNumber = portNumber;
}

public void initialize() {
textField.setText("Nepodarilo sa spojiť so serverom. Port: " + portNumber + " sa už používa.");
}

public void onContinueAction() {
((Stage) mainBox.getScene().getWindow()).close();
gui.showMainMenu(widowStage, autogram);
}

public void onCancelAction() {
widowStage.fireEvent(new WindowEvent(widowStage, WindowEvent.WINDOW_CLOSE_REQUEST));
}

@Override
public Node getNodeForLoosingFocus() {
return mainBox;
}
}
34 changes: 29 additions & 5 deletions src/main/java/digital/slovensko/autogram/ui/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
import java.util.WeakHashMap;
import java.util.function.Consumer;

import digital.slovensko.autogram.core.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import digital.slovensko.autogram.core.Autogram;
import digital.slovensko.autogram.core.Batch;
import digital.slovensko.autogram.core.SigningJob;
import digital.slovensko.autogram.core.SigningKey;
import digital.slovensko.autogram.core.ValidationReports;
import digital.slovensko.autogram.core.errors.AutogramException;
import digital.slovensko.autogram.core.errors.NoDriversDetectedException;
import digital.slovensko.autogram.core.errors.NoKeysDetectedException;
Expand Down Expand Up @@ -212,6 +208,34 @@ public void showError(AutogramException e) {
stage.show();
}

public void showErrorPortInUse(Stage stage, Autogram autogram, int portNumber, AutogramException e) {
celuchmarek marked this conversation as resolved.
Show resolved Hide resolved
logger.debug("GUI showing error", e);
var controller = new ErrorBeforeMainMenuController(this ,stage, autogram, portNumber);
var root = GUIUtils.loadFXML(controller, "port-in-use-dialog.fxml");

stage.setTitle(e.getHeading());

stage.setScene(new Scene(root));

stage.sizeToScene();
stage.setResizable(false);
GUIUtils.suppressDefaultFocus(stage, controller);

stage.show();
}

public void showMainMenu(Stage stage, Autogram autogram){
var controller = new MainMenuController(autogram);
var root = GUIUtils.loadFXML(controller, "main-menu.fxml");
var scene = new Scene(root);

GUIUtils.suppressDefaultFocus(stage, controller);
stage.setTitle("Autogram");
stage.setScene(scene);
stage.setResizable(false);
stage.show();
}

@Override
public void onUpdateAvailable() {
var controller = new UpdateController(hostServices);
Expand Down
32 changes: 15 additions & 17 deletions src/main/java/digital/slovensko/autogram/ui/gui/GUIApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import digital.slovensko.autogram.core.Autogram;
import digital.slovensko.autogram.core.LaunchParameters;
import digital.slovensko.autogram.core.errors.PortIsUsedException;
import digital.slovensko.autogram.server.AutogramServer;
import javafx.application.Application;
import javafx.application.Platform;
Expand All @@ -27,30 +28,27 @@ public void start(Stage windowStage) throws Exception {

setUserAgentStylesheet(getClass().getResource("idsk.css").toExternalForm());

var controller = new MainMenuController(autogram);
var root = GUIUtils.loadFXML(controller, "main-menu.fxml");
var params = LaunchParameters.fromParameters(getParameters());

var scene = new Scene(root);
try {
var server = new AutogramServer(autogram, params.getHost(), params.getPort(), params.isProtocolHttps(), cachedExecutorService);
server.start();

var params = LaunchParameters.fromParameters(getParameters());
var server = new AutogramServer(autogram, params.getHost(), params.getPort(), params.isProtocolHttps(), cachedExecutorService);
windowStage.setOnHidden(event -> {
new Thread(server::stop).start();
});

server.start();
if (!params.isStandaloneMode())
GUIUtils.startIconified(windowStage);

windowStage.setOnCloseRequest(event -> {
new Thread(server::stop).start();
ui.showMainMenu(windowStage, autogram);
} catch (PortIsUsedException e) {
ui.showErrorPortInUse(windowStage, autogram, params.getPort(), new PortIsUsedException());
}

windowStage.setOnCloseRequest(event -> {
Platform.exit();
});

if (!params.isStandaloneMode())
GUIUtils.startIconified(windowStage);

GUIUtils.suppressDefaultFocus(windowStage, controller);
windowStage.setTitle("Autogram");
windowStage.setScene(scene);
windowStage.setResizable(false);
windowStage.show();
celuchmarek marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
celuchmarek marked this conversation as resolved.
Show resolved Hide resolved

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<?import javafx.scene.text.Text?>
<?import javafx.scene.text.TextFlow?>
<?import javafx.scene.shape.SVGPath?>

<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
prefWidth="500" minWidth="450"
fx:id="mainBox">

<VBox styleClass="autogram-warning-summary">
<HBox>
<SVGPath styleClass="autogram-icon"
content="M14.992 22.5001C15.5308 22.5001 15.9724 22.3361 16.3168 22.0083C16.6613 21.6804 16.8335 21.247 16.8335 20.7083C16.8335 20.1695 16.664 19.7223 16.325 19.3667C15.986 19.0112 15.5471 18.8334 15.0084 18.8334C14.4696 18.8334 14.0279 19.011 13.6835 19.3661C13.3391 19.7213 13.1668 20.1683 13.1668 20.7071C13.1668 21.2459 13.3363 21.6794 13.6753 22.0077C14.0143 22.3359 14.4532 22.5001 14.992 22.5001ZM13.5335 16.6001H16.6668V7.60005H13.5335V16.6001ZM15.0136 29.1667C13.0387 29.1667 11.1929 28.7991 9.47613 28.0639C7.75937 27.3287 6.25734 26.3175 4.97003 25.0302C3.68272 23.7429 2.67147 22.2416 1.9363 20.5262C1.2011 18.8109 0.833496 16.9648 0.833496 14.988C0.833496 13.0112 1.2011 11.1636 1.9363 9.44515C2.67147 7.72675 3.68097 6.22887 4.9648 4.95152C6.24862 3.67414 7.74902 2.66288 9.466 1.91775C11.183 1.17262 13.0308 0.800049 15.0095 0.800049C16.9881 0.800049 18.838 1.17176 20.559 1.91518C22.28 2.65858 23.7784 3.66749 25.0541 4.94192C26.3298 6.21634 27.3398 7.71497 28.0839 9.43782C28.8281 11.1606 29.2002 13.0118 29.2002 14.9912C29.2002 16.9692 28.8276 18.8164 28.0825 20.5328C27.3373 22.2491 26.3261 23.7476 25.0487 25.0281C23.7713 26.3086 22.2732 27.3185 20.5543 28.0578C18.8355 28.7971 16.9886 29.1667 15.0136 29.1667Z" />
<TextFlow styleClass="autogram-warning-summary__title">
<Text fx:id="textField" />
</TextFlow>
</HBox>

<TextFlow styleClass="autogram-warning-summary__description"><Text>Chcete pokračovať v obmedzenom režime ?</Text></TextFlow>
</VBox>

<HBox styleClass="autogram-actions">
<Button fx:id="cancelButton" styleClass="autogram-button,autogram-button--warning" text="Zatvoriť" onAction="#onCancelAction" />
<Button fx:id="continueButton" styleClass="autogram-button,autogram-button--secondary" text="Pokračovať" onAction="#onContinueAction" />
</HBox>
</VBox>