feat: sort user list

This commit is contained in:
Arnaud Vergnet 2020-12-02 11:15:15 +01:00
parent 3485adfe7e
commit 657ab85915
2 changed files with 16 additions and 2 deletions

View file

@ -56,12 +56,21 @@ public class UserListController implements Initializable {
ObservableList<User> activeList = null;
try {
activeList = FXCollections.observableArrayList(
new PeerUser("Dodo"),
new ActiveUser("Coucou", InetAddress.getLocalHost())
new PeerUser("Dodo0"),
new PeerUser("Dodo3"),
new PeerUser("Dodo2"),
new ActiveUser("Coucou0", InetAddress.getLocalHost()),
new ActiveUser("Coucou1", InetAddress.getLocalHost()),
new ActiveUser("Coucou3", InetAddress.getLocalHost()),
new PeerUser("Dodo1"),
new ActiveUser("Coucou2", InetAddress.getLocalHost())
);
} catch (UnknownHostException e) {
e.printStackTrace();
}
if (activeList != null) {
activeList.sort(null);
}
userList.setItems(activeList);
userList.setCellFactory(listView -> {
final UserListItemCell cell = new UserListItemCell();

View file

@ -32,6 +32,11 @@ public class User implements Serializable, Comparable<User> {
@Override
public int compareTo(@NotNull User o) {
if ((o instanceof ActiveUser) && !(this instanceof ActiveUser)) {
return 1;
} else if (!(o instanceof ActiveUser) && (this instanceof ActiveUser)) {
return -1;
}
return username.compareTo(o.username);
}
}