Commit 3d859c91 authored by Josselin ENET's avatar Josselin ENET

Created class to reserve with an agent #15

Created a class which handles the reservation of a travel by an agent.
parent c05dde3b
package fr.unantes.software.construction.ui;
import fr.unantes.software.construction.calendar.Calendar;
import fr.unantes.software.construction.calendar.MultipleReferenceToTravel;
import fr.unantes.software.construction.calendar.Travel;
import fr.unantes.software.construction.people.Agent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.util.Callback;
import java.util.List;
public class AgentBookedTravelsController extends SceneController {
public AgentBookedTravelsController(GUI gui) { super(gui); }
@Override
public Scene createScene() {
gui.setTitle("Booked Travels");
GridPane root = new GridPane();
//travels section title
Text travelsText = new Text("Travel Reservation");
travelsText.setUnderline(true);
travelsText.setFont(new Font(18));
//travels listview
ListView<Travel> travelsListView = new ListView<>();
updateListView(travelsListView);
Callback<ListView<Travel>, ListCell<Travel>> cellFactory = new Callback<ListView<Travel>, ListCell<Travel>>() {
@Override
public ListCell<Travel> call(ListView<Travel> l) {
return new ListCell<Travel>() {
@Override
protected void updateItem(Travel item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
} else {
setText(item.getFirstStep().getStartCity().getName()+" - "+item.getLastStep().getDestinationCity().getName());
}
}
} ;
}
};
travelsListView.setCellFactory(cellFactory);
// back button
Button backButton = new Button();
backButton.setText("Back");
backButton.setOnAction(event -> {
gui.setController(new AgentHomeController(gui));
});
root.add(travelsText,0, 0);
root.add(travelsListView, 0, 2);
root.add(backButton,0,4);
Scene result = new Scene(root,400,250);
return result;
}
private void updateListView(ListView<Travel> travelsListView) {
Agent currentUser = (Agent) gui.getCurrentUser();
Calendar userCalendar = currentUser.getCalendarAssociation().get();
MultipleReferenceToTravel userTravels = (MultipleReferenceToTravel) userCalendar.getTravelAssociation();
List<Travel> travelsList = userTravels.getAll();
ObservableListImplementation<Travel> travelsObservableList = new ObservableListImplementation<>(travelsList);
travelsListView.setItems(travelsObservableList);
}
}
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