80 lines
2.0 KiB
Java
80 lines
2.0 KiB
Java
package envoy.client.ui.controller;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import javafx.application.Platform;
|
|
import javafx.fxml.FXML;
|
|
import javafx.scene.control.*;
|
|
|
|
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;
|
|
|
|
/**
|
|
* Project: <strong>envoy-client</strong><br>
|
|
* File: <strong>ContactSearchSceneController.java</strong><br>
|
|
* Created: <strong>07.06.2020</strong><br>
|
|
*
|
|
* @author Maximilian Käfer
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public class GroupCreationScene {
|
|
|
|
@FXML
|
|
private Button backButton;
|
|
|
|
@FXML
|
|
private Button createButton;
|
|
|
|
@FXML
|
|
private TextField groupNameBar;
|
|
|
|
@FXML
|
|
private ListView<Contact> contactList;
|
|
|
|
private SceneContext sceneContext;
|
|
|
|
private static EventBus eventBus = EventBus.getInstance();
|
|
|
|
@FXML
|
|
private void initialize() {
|
|
contactList.setCellFactory(e -> new ContactListCell());
|
|
contactList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
|
}
|
|
|
|
/**
|
|
* @param sceneContext enables the user to return to the chat scene
|
|
* @param localDB the local database from which potential group members can
|
|
* be selected
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
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())));
|
|
}
|
|
|
|
/**
|
|
* Sends a {@link GroupCreation} to the server.
|
|
*
|
|
* @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()))));
|
|
}
|
|
|
|
@FXML
|
|
private void backButtonClicked() { sceneContext.pop(); }
|
|
}
|