Commit 5bdbbe14 authored by William Sha's avatar William Sha
Browse files

Merge branch 'fix/v2/taskUsersList' into 'int/v2'

Delegate update usersList in a task

See merge request !51
parents bd827059 8ed31434
package main.java.client.main.controller;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
......@@ -59,33 +61,52 @@ public class FXHome {
}
public void updateData() {
homeListViewUsersOnlineData.clear();
for (int i = 0; i < this.model.getUsersList().size(); i++) {
homeListViewUsersOnlineData.add(this.model.getUsersList().get(i));
}
homeListViewUsersOnline.setItems(homeListViewUsersOnlineData);
homeListViewUsersOnline.setCellFactory((list) -> {
return new ListCell<UserLight>() {
@Override
protected void updateItem(UserLight item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
} else {
setText(item.getFirstName() + " " + item.getLastName());
}
}
};
});
final ListView<String> group = new ListView ();
Task<Void> task = new Task<Void>() {
// Handle ListView selection changes.
homeListViewUsersOnline.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("ListView Selection Changed (selected: " + newValue.toString() + ")");
});
@Override protected Void call() throws Exception {
homeListViewUsersOnline.getItems().clear();
for (int i = 0; i < model.getUsersList().size(); i++) {
int finalI = i;
Platform.runLater(new Runnable() {
@Override public void run() {
homeListViewUsersOnlineData.add(model.getUsersList().get(finalI));
}
});
}
homeListViewUsersOnline.refresh();
homeListViewUsersOnline.setItems(homeListViewUsersOnlineData);
homeListViewUsersOnline.setCellFactory((list) -> {
return new ListCell<UserLight>() {
@Override
protected void updateItem(UserLight item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
} else {
setText(item.getFirstName() + " " + item.getLastName());
}
}
};
});
// Handle ListView selection changes.
homeListViewUsersOnline.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("ListView Selection Changed (selected: " + newValue.toString() + ")");
});
homeListViewUsersOnline.refresh();
return null;
}
};
task.run();
}
@FXML
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment