Task 2.4 Step 1: Show actual exam assignments per classroom

This commit is contained in:
Omnicscient
2025-12-16 23:27:12 +03:00
parent 9e082c6cac
commit 67dc3f0dd1

View File

@@ -10,25 +10,45 @@ import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import org.example.se302.model.Classroom;
import org.example.se302.model.ExamAssignment;
import org.example.se302.model.ScheduleConfiguration;
import org.example.se302.service.DataManager;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Map;
/**
* Controller for the Classroom Schedule view.
* Shows exam assignments for each classroom.
*/
public class ScheduleClassroomController {
@FXML private ComboBox<Classroom> classroomComboBox;
@FXML private Label selectedClassroomLabel;
@FXML private TableView<ClassroomSlotEntry> scheduleTable;
@FXML private TableColumn<ClassroomSlotEntry, String> dateColumn;
@FXML private TableColumn<ClassroomSlotEntry, String> timeColumn;
@FXML private TableColumn<ClassroomSlotEntry, String> courseColumn;
@FXML private TableColumn<ClassroomSlotEntry, Number> studentsColumn;
@FXML private TableColumn<ClassroomSlotEntry, String> utilizationColumn;
@FXML private Label utilizationLabel;
@FXML
private ComboBox<Classroom> classroomComboBox;
@FXML
private Label selectedClassroomLabel;
@FXML
private TableView<ClassroomSlotEntry> scheduleTable;
@FXML
private TableColumn<ClassroomSlotEntry, String> dateColumn;
@FXML
private TableColumn<ClassroomSlotEntry, String> timeColumn;
@FXML
private TableColumn<ClassroomSlotEntry, String> courseColumn;
@FXML
private TableColumn<ClassroomSlotEntry, Number> studentsColumn;
@FXML
private TableColumn<ClassroomSlotEntry, String> utilizationColumn;
@FXML
private Label utilizationLabel;
private DataManager dataManager;
// Reference to the current schedule state (set by parent controller)
private Map<String, ExamAssignment> currentAssignments;
private ScheduleConfiguration configuration;
@FXML
public void initialize() {
dataManager = DataManager.getInstance();
@@ -37,31 +57,63 @@ public class ScheduleClassroomController {
classroomComboBox.setItems(dataManager.getClassrooms());
// Set up table columns
dateColumn.setCellValueFactory(cellData ->
new SimpleStringProperty(cellData.getValue().getDate()));
timeColumn.setCellValueFactory(cellData ->
new SimpleStringProperty(cellData.getValue().getTime()));
courseColumn.setCellValueFactory(cellData ->
new SimpleStringProperty(cellData.getValue().getCourse()));
studentsColumn.setCellValueFactory(cellData ->
new SimpleIntegerProperty(cellData.getValue().getStudentCount()));
utilizationColumn.setCellValueFactory(cellData ->
new SimpleStringProperty(cellData.getValue().getUtilization()));
dateColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getDate()));
timeColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getTime()));
courseColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getCourse()));
studentsColumn.setCellValueFactory(
cellData -> new SimpleIntegerProperty(cellData.getValue().getStudentCount()));
utilizationColumn.setCellValueFactory(
cellData -> new SimpleStringProperty(cellData.getValue().getUtilization()));
}
/**
* Sets the current schedule assignments. Called by parent controller after
* schedule generation.
*/
public void setScheduleData(Map<String, ExamAssignment> assignments, ScheduleConfiguration config) {
this.currentAssignments = assignments;
this.configuration = config;
}
@FXML
private void onShowSchedule() {
Classroom selected = classroomComboBox.getValue();
if (selected == null) return;
if (selected == null)
return;
selectedClassroomLabel.setText("Schedule for: " + selected.getClassroomId() +
" (Capacity: " + selected.getCapacity() + ")");
// For demo: show empty schedule
ObservableList<ClassroomSlotEntry> entries = FXCollections.observableArrayList();
scheduleTable.setItems(entries);
utilizationLabel.setText("Overall Utilization: 0% (No exams scheduled)");
// If we have assignments, filter by this classroom
if (currentAssignments != null && !currentAssignments.isEmpty()) {
for (ExamAssignment assignment : currentAssignments.values()) {
if (assignment.isAssigned() &&
selected.getClassroomId().equals(assignment.getClassroomId())) {
// Format date
String dateStr;
if (configuration != null && configuration.getStartDate() != null) {
LocalDate examDate = configuration.getStartDate()
.plusDays(assignment.getDay());
dateStr = examDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
} else {
dateStr = "Day " + (assignment.getDay() + 1);
}
// Format time
String timeStr = "Slot " + (assignment.getTimeSlotIndex() + 1);
entries.add(new ClassroomSlotEntry(
dateStr, timeStr, assignment.getCourseCode(),
assignment.getStudentCount(), "-"));
}
}
}
scheduleTable.setItems(entries);
utilizationLabel.setText("Exams shown: " + entries.size());
}
// Helper class for table entries
@@ -72,7 +124,8 @@ public class ScheduleClassroomController {
private final int studentCount;
private final String utilization;
public ClassroomSlotEntry(String date, String time, String course, int studentCount, String utilization) {
public ClassroomSlotEntry(String date, String time, String course, int studentCount,
String utilization) {
this.date = date;
this.time = time;
this.course = course;
@@ -80,10 +133,24 @@ public class ScheduleClassroomController {
this.utilization = utilization;
}
public String getDate() { return date; }
public String getTime() { return time; }
public String getCourse() { return course; }
public int getStudentCount() { return studentCount; }
public String getUtilization() { return utilization; }
public String getDate() {
return date;
}
public String getTime() {
return time;
}
public String getCourse() {
return course;
}
public int getStudentCount() {
return studentCount;
}
public String getUtilization() {
return utilization;
}
}
}