Wrapping data into ObservableList instances instead of copying it

This commit is contained in:
Kai S. K. Engelbart 2020-03-30 21:27:07 +02:00
parent dbf944b5cb
commit 94dbf0481b
2 changed files with 4 additions and 8 deletions

View File

@ -95,7 +95,7 @@ public final class ChatSceneController {
this.writeProxy = writeProxy;
// TODO: handle offline mode
userList.getItems().addAll(client.getContacts().getContacts());
userList.setItems(FXCollections.observableList(client.getContacts().getContacts()));
// userList.getItems().addAll(localDB.getChats().stream().map(Chat::getRecipient).collect(Collectors.toList()));
}
@ -105,12 +105,6 @@ public final class ChatSceneController {
if (user != null && (currentChat == null || user.getID() != currentChat.getRecipient().getID())) {
contactLabel.setText(user.getName());
// Swap observable list
if (currentChat != null) {
currentChat.getMessages().clear();
currentChat.getMessages().addAll(messageList.getItems());
}
// LEON: JFC <===> JAVA FRIED CHICKEN <=/=> Java Foundation Classes
// Load the chat or create a new one and add it to the LocalDB
@ -119,7 +113,8 @@ public final class ChatSceneController {
.filter(c -> c.getRecipient().getID() == user.getID())
.findAny()
.orElseGet(() -> { var chat = new Chat(user); localDB.getChats().add(chat); return chat; });
messageList.setItems(FXCollections.observableArrayList(currentChat.getMessages()));
messageList.setItems(FXCollections.observableList(currentChat.getMessages()));
}
}

View File

@ -16,6 +16,7 @@ module envoy {
requires transitive java.prefs;
requires javafx.controls;
requires javafx.fxml;
requires javafx.base;
opens envoy.client.ui to javafx.graphics, javafx.fxml;
}