Merge pull request #160 from informatik-ag-ngl/b/user_name_validation
Contact Name Validation
This commit is contained in:
commit
5eea90ce68
@ -5,15 +5,16 @@ import java.util.stream.Collectors;
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.Alert.AlertType;
|
||||
|
||||
import envoy.client.data.LocalDB;
|
||||
import envoy.client.event.SendEvent;
|
||||
import envoy.client.ui.ContactListCell;
|
||||
import envoy.client.ui.SceneContext;
|
||||
import envoy.data.Contact;
|
||||
import envoy.data.User;
|
||||
import envoy.event.EventBus;
|
||||
import envoy.event.GroupCreation;
|
||||
import envoy.util.Bounds;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-client</strong><br>
|
||||
@ -25,21 +26,18 @@ import envoy.event.GroupCreation;
|
||||
*/
|
||||
public class GroupCreationScene {
|
||||
|
||||
@FXML
|
||||
private Button backButton;
|
||||
|
||||
@FXML
|
||||
private Button createButton;
|
||||
|
||||
@FXML
|
||||
private TextField groupNameBar;
|
||||
private TextField groupNameField;
|
||||
|
||||
@FXML
|
||||
private ListView<Contact> contactList;
|
||||
|
||||
private SceneContext sceneContext;
|
||||
|
||||
private static EventBus eventBus = EventBus.getInstance();
|
||||
private static final EventBus eventBus = EventBus.getInstance();
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
@ -56,22 +54,36 @@ public class GroupCreationScene {
|
||||
public void initializeData(SceneContext sceneContext, LocalDB localDB) {
|
||||
this.sceneContext = sceneContext;
|
||||
Platform.runLater(() -> contactList.getItems()
|
||||
.addAll(localDB.getUsers()
|
||||
.values()
|
||||
.stream()
|
||||
.filter(c -> c instanceof User && c.getID() != localDB.getUser().getID())
|
||||
.collect(Collectors.toList())));
|
||||
.addAll(localDB.getUsers().values().stream().filter(c -> c.getID() != localDB.getUser().getID()).collect(Collectors.toList())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a {@link GroupCreation} to the server.
|
||||
* Enables the {@code createButton} if at least one contact is selected.
|
||||
*
|
||||
* @since Envoy Client v0.1-beta
|
||||
*/
|
||||
@FXML
|
||||
private void contactListClicked() { createButton.setDisable(contactList.getSelectionModel().isEmpty()); }
|
||||
|
||||
/**
|
||||
* Sends a {@link GroupCreation} to the server and closes this scene.
|
||||
* <p>
|
||||
* If the given group name is not valid, an error is displayed instead.
|
||||
*
|
||||
* @since Envoy Client v0.1-beta
|
||||
*/
|
||||
@FXML
|
||||
private void sendGroupObject() {
|
||||
eventBus.dispatch(new SendEvent(new GroupCreation(groupNameBar.getText(),
|
||||
contactList.getSelectionModel().getSelectedItems().stream().map(Contact::getID).collect(Collectors.toSet()))));
|
||||
private void createButtonClicked() {
|
||||
final var name = groupNameField.getText();
|
||||
if (!Bounds.isValidContactName(name)) {
|
||||
new Alert(AlertType.ERROR, "The entered group name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait();
|
||||
groupNameField.clear();
|
||||
} else {
|
||||
eventBus.dispatch(new SendEvent(new GroupCreation(name,
|
||||
contactList.getSelectionModel().getSelectedItems().stream().map(Contact::getID).collect(Collectors.toSet()))));
|
||||
new Alert(AlertType.INFORMATION, String.format("Group '%s' successfully created.", name)).showAndWait();
|
||||
sceneContext.pop();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
@ -23,6 +23,7 @@ import envoy.event.EventBus;
|
||||
import envoy.event.HandshakeRejection;
|
||||
import envoy.event.MessageStatusChange;
|
||||
import envoy.exception.EnvoyException;
|
||||
import envoy.util.Bounds;
|
||||
import envoy.util.EnvoyLog;
|
||||
|
||||
/**
|
||||
@ -115,8 +116,11 @@ public final class LoginScene {
|
||||
if (registerCheckBox.isSelected() && !passwordField.getText().equals(repeatPasswordField.getText())) {
|
||||
new Alert(AlertType.ERROR, "The entered password is unequal to the repeated one").showAndWait();
|
||||
repeatPasswordField.clear();
|
||||
}
|
||||
else performHandshake(
|
||||
} else if (!Bounds.isValidContactName(userTextField.getText())) {
|
||||
new Alert(AlertType.ERROR, "The entered user name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait();
|
||||
userTextField.clear();
|
||||
} else
|
||||
performHandshake(
|
||||
new LoginCredentials(userTextField.getText(), passwordField.getText().toCharArray(), registerCheckBox.isSelected(), Startup.VERSION));
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
<children>
|
||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||
<children>
|
||||
<TextField fx:id="groupNameBar" prefColumnCount="22" promptText="Enter Group Name">
|
||||
<TextField fx:id="groupNameField" prefColumnCount="22" promptText="Enter Group Name">
|
||||
<HBox.margin>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</HBox.margin>
|
||||
@ -38,21 +38,21 @@
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</padding>
|
||||
</Label>
|
||||
<ListView fx:id="contactList" prefHeight="314.0" prefWidth="600.0">
|
||||
<ListView fx:id="contactList" onMouseClicked="#contactListClicked" prefHeight="314.0" prefWidth="600.0">
|
||||
<VBox.margin>
|
||||
<Insets bottom="5.0" left="10.0" right="10.0" top="5.0" />
|
||||
</VBox.margin>
|
||||
<padding>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</padding></ListView>
|
||||
<Button mnemonicParsing="false" onAction="#sendGroupObject" text="Create">
|
||||
<Button fx:id="createButton" defaultButton="true" disable="true" mnemonicParsing="false" onAction="#createButtonClicked" text="Create">
|
||||
<VBox.margin>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</VBox.margin>
|
||||
<padding>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</padding></Button>
|
||||
<Button fx:id="backButton" cancelButton="true" mnemonicParsing="true" onAction="#backButtonClicked" text="_Back">
|
||||
<Button cancelButton="true" mnemonicParsing="true" onAction="#backButtonClicked" text="_Back">
|
||||
<VBox.margin>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||
</VBox.margin>
|
||||
|
Reference in New Issue
Block a user