-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewCoursesController.java
More file actions
62 lines (49 loc) · 1.87 KB
/
ViewCoursesController.java
File metadata and controls
62 lines (49 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package s25.cs151.application.controller;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.stage.Stage;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.cell.PropertyValueFactory;
import s25.cs151.application.model.DataManager;
import s25.cs151.application.model.*;
public class ViewCoursesController {
@FXML
private TableView<Course> coursesTable;
@FXML
private TableColumn<Course, String> codeColumn;
@FXML
private TableColumn<Course, String> nameColumn;
@FXML
private TableColumn<Course, String> sectionColumn;
@FXML
private Button closeButton;
@FXML
private void initialize() {
// Configure table columns
codeColumn.setCellValueFactory(new PropertyValueFactory<>("courseCode"));
nameColumn.setCellValueFactory(new PropertyValueFactory<>("courseName"));
sectionColumn.setCellValueFactory(new PropertyValueFactory<>("sectionNumber"));
// Load and display data
loadCourses();
}
private void loadCourses() {
ObservableList<Course> tableData = FXCollections.observableArrayList(
DataManager.loadAllCourses()
);
// Sort by course code (descending) and then by section number (descending)
tableData.sort((c1, c2) -> {
// First compare course codes in descending order
int codeCompare = c2.getCourseCode().compareTo(c1.getCourseCode());
if (codeCompare != 0) return codeCompare;
// If course codes are equal, compare section numbers in descending order
return c2.getSectionNumber().compareTo(c1.getSectionNumber());
});
coursesTable.setItems(tableData);
}
@FXML
private void onClose() {
Stage stage = (Stage) closeButton.getScene().getWindow();
stage.close();
}
}