From 41e86bdec5ae807b1200709c034b071285b2a809 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sun, 23 Aug 2020 22:29:13 +0200 Subject: [PATCH] Added nice error handling when creating groups insted of alert --- .../ui/controller/GroupCreationTab.java | 90 +++++++++++++++++-- client/src/main/resources/css/dark.css | 5 ++ .../main/resources/fxml/GroupCreationTab.fxml | 15 +++- 3 files changed, 98 insertions(+), 12 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java index f8d7259..f4ae707 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -8,6 +8,7 @@ import javafx.application.Platform; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.control.Alert.AlertType; +import javafx.scene.layout.HBox; import envoy.client.data.Chat; import envoy.client.data.LocalDB; @@ -44,15 +45,31 @@ public class GroupCreationTab { @FXML private Button createButton; + + @FXML + private Button cancelButton; @FXML private TextArea groupNameField; @FXML private ListView userList; + + @FXML + private Label errorMessageLabel; + + @FXML + private Button proceedDupButton; + + @FXML + private Button cancelDupButton; + + @FXML + private HBox errorProceedBox; private LocalDB localDB; + private String name; private static final EventBus eventBus = EventBus.getInstance(); @FXML @@ -103,20 +120,37 @@ public class GroupCreationTab { */ @FXML private void createButtonClicked() { - final var name = groupNameField.getText(); + name = groupNameField.getText(); if (!Bounds.isValidContactName(name)) { - new Alert(AlertType.ERROR, "The entered group name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait(); + errorMessageLabel.setPrefHeight(30); + errorMessageLabel.setMinHeight(30); + errorMessageLabel.setMaxHeight(30); + errorMessageLabel.setText("The group name is not valid!"); groupNameField.clear(); } else if (groupNameAlreadyPresent(name)) { - final var alert = new Alert(AlertType.WARNING, "You already have a group with that name.", ButtonType.OK, ButtonType.CANCEL); - alert.setTitle("Create Group?"); - alert.setHeaderText("Proceed?"); - alert.showAndWait().filter(btn -> btn == ButtonType.OK).ifPresent(btn -> createGroup(name)); + errorMessageLabel.setPrefHeight(30); + errorMessageLabel.setMinHeight(30); + errorMessageLabel.setMaxHeight(30); + errorMessageLabel.setText("Name does already exist! Proceed anyways?"); + proceedDupButton.setPrefHeight(30); + proceedDupButton.setMinHeight(30); + proceedDupButton.setMaxHeight(30); + cancelDupButton.setPrefHeight(30); + cancelDupButton.setMinHeight(30); + cancelDupButton.setMaxHeight(30); + errorProceedBox.setPrefHeight(30); + errorProceedBox.setMinHeight(30); + errorProceedBox.setMaxHeight(30); + createButton.setDisable(true); + cancelButton.setDisable(true); } else { - new Alert(AlertType.INFORMATION, String.format("Group '%s' successfully created.", name)).showAndWait(); createGroup(name); + eventBus.dispatch(new BackEvent()); + errorMessageLabel.setPrefHeight(0); + errorMessageLabel.setMinHeight(0); + errorMessageLabel.setMaxHeight(0); + groupNameField.clear(); } - eventBus.dispatch(new BackEvent()); } /** @@ -150,4 +184,44 @@ public class GroupCreationTab { @FXML private void backButtonClicked() { eventBus.dispatch(new BackEvent()); } + + @FXML + private void proceedOnNameDuplication() { + createButton.setDisable(false); + cancelButton.setDisable(false); + createGroup(name); + eventBus.dispatch(new BackEvent()); + errorMessageLabel.setPrefHeight(0); + errorMessageLabel.setMinHeight(0); + errorMessageLabel.setMaxHeight(0); + proceedDupButton.setPrefHeight(0); + proceedDupButton.setMinHeight(0); + proceedDupButton.setMaxHeight(0); + cancelDupButton.setPrefHeight(0); + cancelDupButton.setMinHeight(0); + cancelDupButton.setMaxHeight(0); + errorProceedBox.setPrefHeight(0); + errorProceedBox.setMinHeight(0); + errorProceedBox.setMaxHeight(0); + groupNameField.clear(); + } + + @FXML + private void cancelOnNameDuplication() { + createButton.setDisable(false); + cancelButton.setDisable(false); + errorMessageLabel.setPrefHeight(0); + errorMessageLabel.setMinHeight(0); + errorMessageLabel.setMaxHeight(0); + proceedDupButton.setPrefHeight(0); + proceedDupButton.setMinHeight(0); + proceedDupButton.setMaxHeight(0); + cancelDupButton.setPrefHeight(0); + cancelDupButton.setMinHeight(0); + cancelDupButton.setMaxHeight(0); + errorProceedBox.setPrefHeight(0); + errorProceedBox.setMinHeight(0); + errorProceedBox.setMaxHeight(0); + groupNameField.clear(); + } } diff --git a/client/src/main/resources/css/dark.css b/client/src/main/resources/css/dark.css index ca98909..de35c5a 100644 --- a/client/src/main/resources/css/dark.css +++ b/client/src/main/resources/css/dark.css @@ -82,3 +82,8 @@ -fx-background-insets : 4.0, 0.0, 0.0; -fx-background-radius : 2.0em; } + +#proceedButton { + -fx-text-fill: white; + -fx-background-color: transparent; +} diff --git a/client/src/main/resources/fxml/GroupCreationTab.fxml b/client/src/main/resources/fxml/GroupCreationTab.fxml index 68da2dd..bd7839b 100644 --- a/client/src/main/resources/fxml/GroupCreationTab.fxml +++ b/client/src/main/resources/fxml/GroupCreationTab.fxml @@ -37,16 +37,23 @@ +