feat: sort user list
This commit is contained in:
parent
3485adfe7e
commit
657ab85915
2 changed files with 16 additions and 2 deletions
|
@ -56,12 +56,21 @@ public class UserListController implements Initializable {
|
||||||
ObservableList<User> activeList = null;
|
ObservableList<User> activeList = null;
|
||||||
try {
|
try {
|
||||||
activeList = FXCollections.observableArrayList(
|
activeList = FXCollections.observableArrayList(
|
||||||
new PeerUser("Dodo"),
|
new PeerUser("Dodo0"),
|
||||||
new ActiveUser("Coucou", InetAddress.getLocalHost())
|
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) {
|
} catch (UnknownHostException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
if (activeList != null) {
|
||||||
|
activeList.sort(null);
|
||||||
|
}
|
||||||
userList.setItems(activeList);
|
userList.setItems(activeList);
|
||||||
userList.setCellFactory(listView -> {
|
userList.setCellFactory(listView -> {
|
||||||
final UserListItemCell cell = new UserListItemCell();
|
final UserListItemCell cell = new UserListItemCell();
|
||||||
|
|
|
@ -32,6 +32,11 @@ public class User implements Serializable, Comparable<User> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(@NotNull User o) {
|
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);
|
return username.compareTo(o.username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue