From 629e3437d10b0434210bc6e2acac9b09c4ae20b1 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sun, 23 Aug 2020 20:26:22 +0200 Subject: [PATCH] Data initialization in GroupCreationTab works at the right time --- .../client/event/LoadGroupCreationEvent.java | 24 +++++++++++++++ .../envoy/client/ui/controller/ChatScene.java | 6 ++-- .../ui/controller/GroupCreationTab.java | 30 ++++++++----------- 3 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 client/src/main/java/envoy/client/event/LoadGroupCreationEvent.java diff --git a/client/src/main/java/envoy/client/event/LoadGroupCreationEvent.java b/client/src/main/java/envoy/client/event/LoadGroupCreationEvent.java new file mode 100644 index 0000000..676e883 --- /dev/null +++ b/client/src/main/java/envoy/client/event/LoadGroupCreationEvent.java @@ -0,0 +1,24 @@ +package envoy.client.event; + +import envoy.client.data.LocalDB; +import envoy.event.Event; + +/** + * Project: client
+ * File: LoadGroupCreationEvent.java
+ * Created: Aug 23, 2020
+ * + * @author Maximilian Käfer + * @since Envoy Client v0.2-beta + */ +public class LoadGroupCreationEvent extends Event{ + + private static final long serialVersionUID = 0L; + + /** + * @param value the localDB + * @since Envoy Client v0.2-beta + */ + public LoadGroupCreationEvent(LocalDB value) { super(value); } + +} diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 4beb30a..0167b3d 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -40,9 +40,7 @@ import envoy.client.data.*; import envoy.client.data.audio.AudioRecorder; import envoy.client.data.commands.SystemCommandBuilder; import envoy.client.data.commands.SystemCommandsMap; -import envoy.client.event.BackEvent; -import envoy.client.event.MessageCreationEvent; -import envoy.client.event.SendEvent; +import envoy.client.event.*; import envoy.client.net.Client; import envoy.client.net.WriteProxy; import envoy.client.ui.*; @@ -407,7 +405,7 @@ public final class ChatScene implements Restorable { @FXML private void groupCreationButtonClicked() { - //TODO: initialize Data + eventBus.dispatch(new LoadGroupCreationEvent(localDB)); tabPane.getSelectionModel().select(2); } 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 47dc5af..0d6bdf5 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -12,6 +12,7 @@ import javafx.scene.control.Alert.AlertType; import envoy.client.data.Chat; import envoy.client.data.LocalDB; import envoy.client.event.BackEvent; +import envoy.client.event.LoadGroupCreationEvent; import envoy.client.event.SendEvent; import envoy.client.ui.SceneContext; import envoy.client.ui.listcell.ContactControl; @@ -58,23 +59,18 @@ public class GroupCreationTab { private void initialize() { userList.setCellFactory(new ListCellFactory<>(ContactControl::new)); userList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); - } - - /** - * @param localDB the local database from which potential group members can - * be selected - * @since Envoy Client v0.1-beta - */ - public void initializeData(LocalDB localDB) { - this.localDB = localDB; - Platform.runLater(() -> userList.getItems() - .addAll(localDB.getChats() - .stream() - .map(Chat::getRecipient) - .filter(User.class::isInstance) - .filter(not(localDB.getUser()::equals)) - .map(User.class::cast) - .collect(Collectors.toList()))); + + eventBus.register(LoadGroupCreationEvent.class, e -> { + this.localDB = e.get(); + Platform.runLater(() -> userList.getItems() + .addAll(localDB.getChats() + .stream() + .map(Chat::getRecipient) + .filter(User.class::isInstance) + .filter(not(localDB.getUser()::equals)) + .map(User.class::cast) + .collect(Collectors.toList()))); + }); } /**