Added nice error handling when creating groups insted of alert
This commit is contained in:
@ -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<User> 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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user