package envoy.client.ui.controller; import static java.util.function.Predicate.not; 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.Chat; import envoy.client.data.LocalDB; import envoy.client.event.SendEvent; import envoy.client.ui.ClearableTextField; import envoy.client.ui.SceneContext; import envoy.client.ui.listcell.ContactListCellFactory; import envoy.data.User; import envoy.event.EventBus; import envoy.event.GroupCreation; import envoy.util.Bounds; /** * Provides a group creation interface. A group name can be entered in the text * field at the top. Available users (local chat recipients) are displayed * inside a list and can be selected (multiple selection available). *
* When the group creation button is pressed, a {@link GroupCreation} is sent to * the server. This controller enforces a valid group name and a non-empty * member list (excluding the client user). *
* Project: envoy-client
* If the given group name is not valid, an error is displayed instead.
*
* @since Envoy Client v0.1-beta
*/
@FXML
private void createButtonClicked() {
final var name = groupNameField.getTextField().getText();
if (!Bounds.isValidContactName(name)) {
new Alert(AlertType.ERROR, "The entered group name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait();
groupNameField.getTextField().clear();
} else {
eventBus.dispatch(new SendEvent(
new GroupCreation(name, userList.getSelectionModel().getSelectedItems().stream().map(User::getID).collect(Collectors.toSet()))));
new Alert(AlertType.INFORMATION, String.format("Group '%s' successfully created.", name)).showAndWait();
sceneContext.pop();
}
}
@FXML
private void backButtonClicked() { sceneContext.pop(); }
}
* File: GroupCreationScene.java
* Created: 07.06.2020
*
* @author Maximilian Käfer
* @since Envoy Client v0.1-beta
*/
public class GroupCreationScene {
@FXML
private Button createButton;
@FXML
private ClearableTextField groupNameField;
@FXML
private ListView