Data initialization in GroupCreationTab works at the right time

This commit is contained in:
Maximilian P. Käfer 2020-08-23 20:26:22 +02:00
parent 8909ae3061
commit 629e3437d1
3 changed files with 39 additions and 21 deletions

View File

@ -0,0 +1,24 @@
package envoy.client.event;
import envoy.client.data.LocalDB;
import envoy.event.Event;
/**
* Project: <strong>client</strong><br>
* File: <strong>LoadGroupCreationEvent.java</strong><br>
* Created: <strong>Aug 23, 2020</strong><br>
*
* @author Maximilian K&auml;fer
* @since Envoy Client v0.2-beta
*/
public class LoadGroupCreationEvent extends Event<LocalDB>{
private static final long serialVersionUID = 0L;
/**
* @param value the localDB
* @since Envoy Client v0.2-beta
*/
public LoadGroupCreationEvent(LocalDB value) { super(value); }
}

View File

@ -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);
}

View File

@ -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())));
});
}
/**