From 139a7c19d4a26bf4b6aecf3c3a12b95c1686d485 Mon Sep 17 00:00:00 2001 From: justinlengch Date: Thu, 4 Apr 2024 15:09:54 +0800 Subject: [PATCH] Change MainWindow to update student and schedule list after each command --- src/main/java/seedu/address/logic/Logic.java | 1 - .../logic/commands/AddLessonCommand.java | 2 +- .../logic/parser/AddLessonCommandParser.java | 2 +- .../seedu/address/model/ModelManager.java | 3 ++- .../seedu/address/model/student/Lesson.java | 2 +- .../java/seedu/address/ui/MainWindow.java | 19 +++++++++++++++++-- .../seedu/address/ui/ScheduleListPanel.java | 9 ++++++--- 7 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 6696e55727a..2eda20f8fbe 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -32,7 +32,6 @@ public interface Logic { /** Returns an unmodifiable view of the filtered list of students */ ObservableList getFilteredStudentList(); - /** * Returns the user prefs' address book file path. */ diff --git a/src/main/java/seedu/address/logic/commands/AddLessonCommand.java b/src/main/java/seedu/address/logic/commands/AddLessonCommand.java index 91624a9e9ee..0b3485bb140 100644 --- a/src/main/java/seedu/address/logic/commands/AddLessonCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddLessonCommand.java @@ -79,6 +79,6 @@ public CommandResult execute(Model model) throws CommandException { } private String generateSuccessMessage(Student editedStudent) { - return String.format(MESSAGE_ADD_LESSON_SUCCESS, editedStudent); + return String.format(MESSAGE_ADD_LESSON_SUCCESS, Messages.format(editedStudent)); } } diff --git a/src/main/java/seedu/address/logic/parser/AddLessonCommandParser.java b/src/main/java/seedu/address/logic/parser/AddLessonCommandParser.java index ef4390bd37b..b315a0a1845 100644 --- a/src/main/java/seedu/address/logic/parser/AddLessonCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddLessonCommandParser.java @@ -48,7 +48,7 @@ public AddLessonCommand parse(String args) throws ParseException { LocalTime timeDetail = LocalTime.parse(lessonDetails[1], TIME_FORMATTER); int isCompleted; if (lessonDetails.length == 3) { - isCompleted = Integer.parseInt(lessonDetails[3]); + isCompleted = Integer.parseInt(lessonDetails[2]); return new AddLessonCommand(index, dateDetail, timeDetail, isCompleted); } else { return new AddLessonCommand(index, dateDetail, timeDetail); diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 7c01e105432..45d343937d4 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -7,6 +7,7 @@ import java.util.function.Predicate; import java.util.logging.Logger; +import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import seedu.address.commons.core.GuiSettings; @@ -119,7 +120,7 @@ public void setStudent(Student target, Student editedStudent) { */ @Override public ObservableList getFilteredStudentList() { - return filteredStudents; + return FXCollections.unmodifiableObservableList(filteredStudents); } @Override diff --git a/src/main/java/seedu/address/model/student/Lesson.java b/src/main/java/seedu/address/model/student/Lesson.java index 0393c676aa6..c42254613bc 100644 --- a/src/main/java/seedu/address/model/student/Lesson.java +++ b/src/main/java/seedu/address/model/student/Lesson.java @@ -163,6 +163,6 @@ public int hashCode() { * Format state as text for viewing. */ public String toString() { - return this.subject + " " + this.date.toString() + " " + this.time; + return this.subject + " " + this.date.toString() + " " + this.time + " "; } } diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index a4b82bfd906..7ef406316be 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -175,8 +175,21 @@ private void handleExit() { primaryStage.hide(); } - public StudentListPanel getStudentListPanel() { - return studentListPanel; + /** + * Updates Schedule List Panel. + */ + public void updateScheduleListPanel() { + scheduleListPanelPlaceholder.getChildren().clear(); + scheduleListPanel = new ScheduleListPanel(logic.getFilteredStudentList()); + scheduleListPanelPlaceholder.getChildren().add(scheduleListPanel.getRoot()); + } + /** + * Updates Student List Panel. + */ + public void updateStudentListPanel() { + studentListPanelPlaceholder.getChildren().clear(); + studentListPanel = new StudentListPanel(logic.getFilteredStudentList()); + studentListPanelPlaceholder.getChildren().add(studentListPanel.getRoot()); } /** @@ -197,6 +210,8 @@ private CommandResult executeCommand(String commandText) throws CommandException if (commandResult.isExit()) { handleExit(); } + updateStudentListPanel(); + updateScheduleListPanel(); return commandResult; } catch (CommandException | ParseException e) { diff --git a/src/main/java/seedu/address/ui/ScheduleListPanel.java b/src/main/java/seedu/address/ui/ScheduleListPanel.java index dc85d9d6d55..0ab97b03b03 100644 --- a/src/main/java/seedu/address/ui/ScheduleListPanel.java +++ b/src/main/java/seedu/address/ui/ScheduleListPanel.java @@ -23,6 +23,7 @@ public class ScheduleListPanel extends UiPart { private static final String FXML = "ScheduleListPanel.fxml"; private final Logger logger = LogsCenter.getLogger(ScheduleListPanel.class); + private ObservableList studentList; @FXML private ListView> scheduleListView; @@ -32,8 +33,9 @@ public class ScheduleListPanel extends UiPart { */ public ScheduleListPanel(ObservableList studentList) { super(FXML); + this.studentList = studentList; - scheduleListView.setItems(transformList(studentList)); + scheduleListView.setItems(transformList(this.studentList)); scheduleListView.setCellFactory(listView -> new ScheduleListViewCell()); } @@ -48,7 +50,9 @@ public ObservableList> transformList(ObservableList studentLesson = student.getLessons(); for (Lesson l : studentLesson) { - scheduleList.add(new Pair(student, l)); + if (l.getLessonStatus() == 0) { + scheduleList.add(new Pair(student, l)); + } } } @@ -78,7 +82,6 @@ class SortDate implements Comparator> { @Override public int compare(Pair o1, Pair o2) { - // TODO: implement your logic here return o1.getValue().getDate().compareTo(o2.getValue().getDate()); } }