/
evernotenkai
/
DataBaseXJavaProject
Обзор
Документация
Войти
/
evernotenkai
/
DataBaseXJavaProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/app/ui/student/StudentCourseHubView.java
112 строк
5 KB
Makson4ik
Весь проект с src db и прочим делом
12 май 2026, 22:43
12 май 2026, 22:43
431f4aa
Код
Авторство
О чём код?
package app.ui.student; import java.util.List; import app.model.AssignmentItem; import app.model.CourseItem; import app.service.LmsService; import app.ui.components.PageHeader; import app.ui.components.UiKit; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Insets; import javafx.scene.control.ComboBox; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.control.SplitPane; import javafx.scene.layout.VBox; public class StudentCourseHubView extends VBox { private final LmsService service; private final int studentId; private final ObservableList<CourseItem> courses = FXCollections.observableArrayList(); private final ObservableList<AssignmentItem> assignments = FXCollections.observableArrayList(); private final ComboBox<CourseItem> courseBox = new ComboBox<CourseItem>(); private final TableView<CourseItem> courseTable = new TableView<CourseItem>(); private final TableView<AssignmentItem> assignmentTable = new TableView<AssignmentItem>(); public StudentCourseHubView(LmsService service, int studentId) { this.service = service; this.studentId = studentId; getStyleClass().add("content-root"); setSpacing(16); getChildren().add(new PageHeader("Курсы и дедлайны", "Выбирай курс и сразу видь актуальные задания.")); courseBox.setPromptText("Выберите курс"); UiKit.configureTable(courseTable); TableColumn<CourseItem, String> c1 = new TableColumn<CourseItem, String>("Название"); c1.setCellValueFactory(v -> new SimpleStringProperty(v.getValue().getName())); TableColumn<CourseItem, String> c2 = new TableColumn<CourseItem, String>("Преподаватель"); c2.setCellValueFactory(v -> new SimpleStringProperty(v.getValue().getTeacherName())); TableColumn<CourseItem, String> c3 = new TableColumn<CourseItem, String>("Описание"); c3.setCellValueFactory(v -> new SimpleStringProperty(v.getValue().getDescription())); courseTable.getColumns().addAll(c1, c2, c3); courseTable.setItems(courses); VBox.setVgrow(courseTable, Priority.ALWAYS); UiKit.configureTable(assignmentTable); TableColumn<AssignmentItem, String> a1 = new TableColumn<AssignmentItem, String>("Название"); a1.setCellValueFactory(v -> new SimpleStringProperty(v.getValue().getTitle())); TableColumn<AssignmentItem, String> a2 = new TableColumn<AssignmentItem, String>("Срок"); a2.setCellValueFactory(v -> new SimpleStringProperty(v.getValue().getDueDate())); TableColumn<AssignmentItem, String> a3 = new TableColumn<AssignmentItem, String>("Создано"); a3.setCellValueFactory(v -> new SimpleStringProperty(v.getValue().getCreatedAt())); assignmentTable.getColumns().addAll(a1, a2, a3); assignmentTable.setItems(assignments); VBox.setVgrow(assignmentTable, Priority.ALWAYS); VBox left = UiKit.card( UiKit.section("Мои курсы"), UiKit.subtitle("Выбирай курс и сразу видь задания по нему."), courseBox, courseTable ); VBox right = UiKit.card( UiKit.section("Задания выбранного курса"), UiKit.subtitle("Список автоматически подстраивается под выбранный курс."), assignmentTable ); SplitPane split = new SplitPane(left, right); split.setDividerPositions(0.54); split.getStyleClass().add("workspace-split-pane"); HBox.setHgrow(split, Priority.ALWAYS); getChildren().add(split); courseBox.valueProperty().addListener((obs, oldV, newV) -> updateAssignments(newV)); refresh(); } private void updateAssignments(CourseItem course) { assignments.clear(); if (course != null) { assignments.addAll(service.findAssignmentsForCourse(course.getId())); } } public void refresh() { List<CourseItem> newCourses = service.findStudentCourses(studentId); CourseItem current = courseBox.getValue(); courses.setAll(newCourses); courseTable.setItems(courses); courseBox.getItems().setAll(newCourses); if (current != null) { for (CourseItem c : newCourses) { if (c.getId() == current.getId()) { courseBox.getSelectionModel().select(c); break; } } } if (courseBox.getValue() == null && !newCourses.isEmpty()) { courseBox.getSelectionModel().select(0); } updateAssignments(courseBox.getValue()); } }