Task 2.3 Step 1: Populate exam date, time, classroom in Course Schedule View

This commit is contained in:
Omnicscient
2025-12-16 22:02:15 +03:00
parent 09a95b271c
commit 6726f129a0

View File

@@ -8,82 +8,148 @@ import javafx.fxml.FXML;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import org.example.se302.model.Course; import org.example.se302.model.Course;
import org.example.se302.model.ExamAssignment;
import org.example.se302.model.ScheduleConfiguration;
import org.example.se302.service.DataManager; import org.example.se302.service.DataManager;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Map;
/** /**
* Controller for the Course Schedule view. * Controller for the Course Schedule view.
* Displays courses with their exam date, time, and assigned classroom.
*/ */
public class ScheduleCourseController { public class ScheduleCourseController {
@FXML private TableView<CourseScheduleEntry> courseScheduleTable; @FXML
@FXML private TableColumn<CourseScheduleEntry, String> courseCodeColumn; private TableView<CourseScheduleEntry> courseScheduleTable;
@FXML private TableColumn<CourseScheduleEntry, Number> enrolledColumn; @FXML
@FXML private TableColumn<CourseScheduleEntry, String> dateColumn; private TableColumn<CourseScheduleEntry, String> courseCodeColumn;
@FXML private TableColumn<CourseScheduleEntry, String> timeColumn; @FXML
@FXML private TableColumn<CourseScheduleEntry, String> classroomColumn; private TableColumn<CourseScheduleEntry, Number> enrolledColumn;
@FXML
private TableColumn<CourseScheduleEntry, String> dateColumn;
@FXML
private TableColumn<CourseScheduleEntry, String> timeColumn;
@FXML
private TableColumn<CourseScheduleEntry, String> classroomColumn;
private DataManager dataManager; private DataManager dataManager;
@FXML // Reference to the current schedule state (set by parent controller or loaded
public void initialize() { // from DB)
dataManager = DataManager.getInstance(); private Map<String, ExamAssignment> currentAssignments;
private ScheduleConfiguration configuration;
// Set up table columns @FXML
courseCodeColumn.setCellValueFactory(cellData -> public void initialize() {
new SimpleStringProperty(cellData.getValue().getCourseCode())); dataManager = DataManager.getInstance();
enrolledColumn.setCellValueFactory(cellData ->
new SimpleIntegerProperty(cellData.getValue().getEnrolledCount()));
dateColumn.setCellValueFactory(cellData ->
new SimpleStringProperty(cellData.getValue().getDate()));
timeColumn.setCellValueFactory(cellData ->
new SimpleStringProperty(cellData.getValue().getTime()));
classroomColumn.setCellValueFactory(cellData ->
new SimpleStringProperty(cellData.getValue().getClassroom()));
// Load data // Set up table columns
loadScheduleData(); courseCodeColumn.setCellValueFactory(
cellData -> new SimpleStringProperty(cellData.getValue().getCourseCode()));
enrolledColumn.setCellValueFactory(
cellData -> new SimpleIntegerProperty(cellData.getValue().getEnrolledCount()));
dateColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getDate()));
timeColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getTime()));
classroomColumn.setCellValueFactory(
cellData -> new SimpleStringProperty(cellData.getValue().getClassroom()));
// Listen for data changes // Load data
dataManager.getCourses().addListener( loadScheduleData();
(javafx.collections.ListChangeListener<Course>) c -> loadScheduleData());
}
private void loadScheduleData() { // Listen for data changes
ObservableList<CourseScheduleEntry> entries = FXCollections.observableArrayList(); dataManager.getCourses().addListener(
(javafx.collections.ListChangeListener<Course>) c -> loadScheduleData());
for (Course course : dataManager.getCourses()) {
entries.add(new CourseScheduleEntry(
course.getCourseCode(),
course.getEnrolledStudentsCount(),
"Not Scheduled",
"-",
"-"
));
} }
courseScheduleTable.setItems(entries); /**
} * Sets the current schedule assignments. Called by parent controller after
* schedule generation.
// Helper class for table entries */
public static class CourseScheduleEntry { public void setScheduleData(Map<String, ExamAssignment> assignments, ScheduleConfiguration config) {
private final String courseCode; this.currentAssignments = assignments;
private final int enrolledCount; this.configuration = config;
private final String date; loadScheduleData();
private final String time;
private final String classroom;
public CourseScheduleEntry(String courseCode, int enrolledCount, String date, String time, String classroom) {
this.courseCode = courseCode;
this.enrolledCount = enrolledCount;
this.date = date;
this.time = time;
this.classroom = classroom;
} }
public String getCourseCode() { return courseCode; } private void loadScheduleData() {
public int getEnrolledCount() { return enrolledCount; } ObservableList<CourseScheduleEntry> entries = FXCollections.observableArrayList();
public String getDate() { return date; }
public String getTime() { return time; } for (Course course : dataManager.getCourses()) {
public String getClassroom() { return classroom; } String courseCode = course.getCourseCode();
} int enrolled = course.getEnrolledStudentsCount();
String dateStr = "Not Scheduled";
String timeStr = "-";
String classroomStr = "-";
// Check if we have an assignment for this course
if (currentAssignments != null && currentAssignments.containsKey(courseCode)) {
ExamAssignment assignment = currentAssignments.get(courseCode);
if (assignment.isAssigned()) {
// Format date based on configuration start date + day offset
if (configuration != null && configuration.getStartDate() != null) {
LocalDate examDate = configuration.getStartDate()
.plusDays(assignment.getDay());
dateStr = examDate.format(
DateTimeFormatter.ofPattern("dd/MM/yyyy (EEEE)"));
} else {
dateStr = "Day " + (assignment.getDay() + 1);
}
// Format time slot
timeStr = "Slot " + (assignment.getTimeSlotIndex() + 1);
// Classroom
classroomStr = assignment.getClassroomId() != null ? assignment.getClassroomId()
: "-";
}
}
entries.add(new CourseScheduleEntry(courseCode, enrolled, dateStr, timeStr, classroomStr));
}
courseScheduleTable.setItems(entries);
}
// Helper class for table entries
public static class CourseScheduleEntry {
private final String courseCode;
private final int enrolledCount;
private final String date;
private final String time;
private final String classroom;
public CourseScheduleEntry(String courseCode, int enrolledCount, String date, String time,
String classroom) {
this.courseCode = courseCode;
this.enrolledCount = enrolledCount;
this.date = date;
this.time = time;
this.classroom = classroom;
}
public String getCourseCode() {
return courseCode;
}
public int getEnrolledCount() {
return enrolledCount;
}
public String getDate() {
return date;
}
public String getTime() {
return time;
}
public String getClassroom() {
return classroom;
}
}
} }