Commit 14d93961 authored by William Sha's avatar William Sha Committed by Thomas Lecluse
Browse files

Feature/main/display users list

parent 49f9b22b
package main.java.client.main;
import main.java.client.ClientApp;
import main.java.client.main.controller.MainCore;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.UserHeavy;
import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.client.IDataToMain;
import ch.qos.logback.core.net.server.Client;
import java.util.List;
import java.util.UUID;
......@@ -52,11 +50,11 @@ public class DataToMainImpl implements IDataToMain {
@Override
public void sendLists(List<UserLight> usrList, List<GameLight> gameList) {
for (UserLight user : usrList){
ClientApp.mainCore.getFX().getModel().getUsersList().add(user);
this.getController().getFX().getModel().addUserInList(user);
}
for (GameLight game : gameList){
ClientApp.mainCore.getFX().getModel().getGamesList().add(game);
this.getController().getFX().getModel().addGameInList(game);
}
}
......@@ -67,6 +65,6 @@ public class DataToMainImpl implements IDataToMain {
@Override
public void sendUserInfo(UserLight userLight, UserHeavy userHeavy){
ClientApp.mainCore.getFX().getModel().setUserLight(userLight);
this.getController().getFX().getModel().setUserLight(userLight);
};
}
......@@ -17,7 +17,6 @@ import javafx.stage.Stage;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
......@@ -73,7 +72,6 @@ public class FXConnection {
}
public void initialize(String fxmlResource, Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(getClass()
.getResource(fxmlResource));
BorderPane root = (BorderPane) fxmlLoader.load();
......
package main.java.client.main.controller;
import javafx.scene.layout.Border;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import main.java.client.ClientApp;
import main.java.client.main.model.MainApplicationModel;
import main.java.common.dataModel.UserHeavy;
import main.java.common.dataModel.UserLight;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
......@@ -16,12 +16,10 @@ import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.scene.control.ListView;
import javafx.scene.control.ListCell;
import javafx.util.Callback;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
public class FXHome {
private MainApplicationModel model;
......@@ -32,10 +30,12 @@ public class FXHome {
@FXML
private ListView<UserLight> homeListViewUsersOnline;
private ObservableList<UserLight> homeListViewUsersOnlineData = FXCollections.observableArrayList();
public FXHome(){
this.model = ClientApp.mainCore.getFX().getModel();
this.model.setFxHome(this);
stage = new Stage();
}
......@@ -44,7 +44,6 @@ public class FXHome {
}
public void initialize(String fxmlResource, Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(getClass()
.getResource(fxmlResource));
BorderPane root = (BorderPane) fxmlLoader.load();
......@@ -58,6 +57,40 @@ public class FXHome {
stage.show();
}
public void updateData(){
// TODO : remove mock when real data update is possible
System.out.println("updateUsersListWithMock");
// Add some sample data.
homeListViewUsersOnlineData.add(new UserLight(null, "PseudoMock", "LastNameMock", "FirstNameMock", new Date(), 0, 0, 0));
homeListViewUsersOnlineData.add(new UserLight(null, "PseudoMock2", "LastNameMock", "FirstNameMock", new Date(), 0, 0, 0));
homeListViewUsersOnlineData.add(new UserLight(null, "PseudoMock3", "LastNameMock", "FirstNameMock", new Date(), 0, 0, 0));
homeListViewUsersOnlineData.add(new UserLight(null, "PseudoMock4", "LastNameMock", "FirstNameMock", new Date(), 0, 0, 0));
// Init ListView.
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();
}
@FXML
private void handleButtonClick(MouseEvent e) throws IOException {
String buttonSource = ((Button) e.getSource()).getId();
......@@ -82,17 +115,6 @@ public class FXHome {
}
}
// private Scene createScene(String sceneName) throws IOException {
// switch (sceneName){
// case "homeButtonMyProfile":
// return MyProfileScene();
//
// default:
// System.out.println("An scene attempt was proceeded, but it was not recognised.");
// return null;
// }
// }
private Scene setNewScene(FXMLLoader loader, Pane root){
FXHome controller = loader.getController();
controller.setStage(stage);
......
......@@ -36,7 +36,7 @@
<Font size="14.0" />
</font>
</Text>
<ListView fx:id="homeListViewUsersOnline" layoutX="45.0" layoutY="71.0" prefHeight="200.0" prefWidth="200.0" />
<ListView fx:id="homeListViewUsersOnline" editable="true" layoutX="45.0" layoutY="71.0" prefHeight="200.0" prefWidth="200.0" />
</children></Pane>
<Pane prefHeight="200.0" prefWidth="290.0" />
<Pane prefHeight="200.0" prefWidth="290.0" />
......
package main.java.client.main.model;
import main.java.client.main.controller.FXHome;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.UserLight;
......@@ -11,6 +12,7 @@ public class MainApplicationModel {
private UserLight userLight;
private List<UserLight> usersList;
private List<GameLight> gamesList;
private FXHome fxHome;
public MainApplicationModel() {
this.userLight = null;
......@@ -23,6 +25,7 @@ public class MainApplicationModel {
public void setUserLight(UserLight userLight) {
this.userLight = userLight;
this.notifyControllers();
}
public List<UserLight> getUsersList() {
......@@ -33,4 +36,33 @@ public class MainApplicationModel {
return gamesList;
}
public void addUserInList(UserLight user){
this.getUsersList().add(user);
this.notifyControllers();
}
public void addGameInList(GameLight game){
this.getGamesList().add(game);
this.notifyControllers();
}
public UserLight removeUserInList(){
UserLight userRemoved = this.getUsersList().remove(this.getUsersList().size()-1);
this.notifyControllers();
return userRemoved;
}
public FXHome getFxHome() {
return fxHome;
}
public void setFxHome(FXHome fxHome) {
this.fxHome = fxHome;
}
public void notifyControllers(){
if (this.fxHome != null){
this.fxHome.updateData();
}
}
}
Supports Markdown
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