From e29e70494f54fdff9424b8296d720e6a9867bcba Mon Sep 17 00:00:00 2001 From: dasha3412 Date: Fri, 18 Oct 2024 17:51:40 +0800 Subject: [PATCH 1/9] Change JAR build name --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0db3743584e..2b9e97920a7 100644 --- a/build.gradle +++ b/build.gradle @@ -66,7 +66,7 @@ dependencies { } shadowJar { - archiveFileName = 'addressbook.jar' + archiveFileName = 'WedLinker.jar' } defaultTasks 'clean', 'test' From 58a7acd05921d9ad7fb62a0f9b2697ca0b0940a3 Mon Sep 17 00:00:00 2001 From: dasha3412 Date: Sat, 19 Oct 2024 13:40:02 +0800 Subject: [PATCH 2/9] Add view switch functionality --- src/main/java/seedu/address/logic/Logic.java | 4 ++ .../seedu/address/logic/LogicManager.java | 7 +++ .../address/logic/commands/CommandResult.java | 46 ++++++++++++++++- .../address/logic/commands/ListCommand.java | 3 +- .../logic/commands/ListWeddingsCommand.java | 24 +++++++++ .../logic/parser/AddressBookParser.java | 2 + .../java/seedu/address/ui/MainWindow.java | 46 ++++++++++++++++- src/main/java/seedu/address/ui/UiManager.java | 8 +++ .../java/seedu/address/ui/WeddingCard.java | 42 ++++++++++++++++ .../seedu/address/ui/WeddingListPanel.java | 49 +++++++++++++++++++ src/main/resources/view/MainWindow.fxml | 4 +- src/main/resources/view/WeddingListCard.fxml | 36 ++++++++++++++ src/main/resources/view/WeddingListPanel.fxml | 8 +++ 13 files changed, 272 insertions(+), 7 deletions(-) create mode 100644 src/main/java/seedu/address/logic/commands/ListWeddingsCommand.java create mode 100644 src/main/java/seedu/address/ui/WeddingCard.java create mode 100644 src/main/java/seedu/address/ui/WeddingListPanel.java create mode 100644 src/main/resources/view/WeddingListCard.fxml create mode 100644 src/main/resources/view/WeddingListPanel.fxml diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 92cd8fa605a..66d8cb2ccfd 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -9,6 +9,7 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.person.Person; +import seedu.address.model.wedding.Wedding; /** * API of the Logic component @@ -33,6 +34,9 @@ public interface Logic { /** Returns an unmodifiable view of the filtered list of persons */ ObservableList getFilteredPersonList(); + /** Returns an unmodifiable view of the filtered list of weddings */ + ObservableList getFilteredWeddingList(); + /** * Returns the user prefs' address book file path. */ diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 5aa3b91c7d0..f8cc99fedb2 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -10,12 +10,14 @@ import seedu.address.commons.core.LogsCenter; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.CommandResult.SwitchView; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.AddressBookParser; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.Model; import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.person.Person; +import seedu.address.model.wedding.Wedding; import seedu.address.storage.Storage; /** @@ -71,6 +73,11 @@ public ObservableList getFilteredPersonList() { return model.getFilteredPersonList(); } + @Override + public ObservableList getFilteredWeddingList() { + return model.getFilteredWeddingList(); + } + @Override public Path getAddressBookFilePath() { return model.getAddressBookFilePath(); diff --git a/src/main/java/seedu/address/logic/commands/CommandResult.java b/src/main/java/seedu/address/logic/commands/CommandResult.java index 249b6072d0d..8f0ba01e47f 100644 --- a/src/main/java/seedu/address/logic/commands/CommandResult.java +++ b/src/main/java/seedu/address/logic/commands/CommandResult.java @@ -19,13 +19,25 @@ public class CommandResult { /** The application should exit. */ private final boolean exit; + /** + * Which view to switch to. + */ + public enum SwitchView { + PERSON, + WEDDING, + NONE + } + + private final SwitchView switchView; + /** * Constructs a {@code CommandResult} with the specified fields. */ - public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) { + public CommandResult(String feedbackToUser, boolean showHelp, boolean exit, SwitchView view) { this.feedbackToUser = requireNonNull(feedbackToUser); this.showHelp = showHelp; this.exit = exit; + switchView = view; } /** @@ -33,7 +45,23 @@ public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) { * and other fields set to their default value. */ public CommandResult(String feedbackToUser) { - this(feedbackToUser, false, false); + this(feedbackToUser, false, false, SwitchView.NONE); + } + + /** + * Constructs a {@code CommandResult} with the specified {@code feedbackToUser}, {@code showHelp}, and + * {@code exit} with {@code switchView} set to none. + */ + public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) { + this(feedbackToUser, showHelp, exit, SwitchView.NONE); + } + + /** + * Constructs a {@code CommandResult} with the specified {@code feedbackToUser}, the view the user wants + * to switch to and other fields set to their default value. + */ + public CommandResult(String feedbackToUser, SwitchView view) { + this(feedbackToUser, false, false, view); } public String getFeedbackToUser() { @@ -44,6 +72,20 @@ public boolean isShowHelp() { return showHelp; } + /** + * Checks if the command requires switching view. + */ + public boolean isSwitchView() { + return switch (switchView) { + case PERSON, WEDDING -> true; + default -> false; + }; + } + + public SwitchView getView() { + return switchView; + } + public boolean isExit() { return exit; } diff --git a/src/main/java/seedu/address/logic/commands/ListCommand.java b/src/main/java/seedu/address/logic/commands/ListCommand.java index 84be6ad2596..825b1e07343 100644 --- a/src/main/java/seedu/address/logic/commands/ListCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListCommand.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import seedu.address.logic.commands.CommandResult.SwitchView; import seedu.address.model.Model; /** @@ -19,6 +20,6 @@ public class ListCommand extends Command { public CommandResult execute(Model model) { requireNonNull(model); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - return new CommandResult(MESSAGE_SUCCESS); + return new CommandResult(MESSAGE_SUCCESS, SwitchView.PERSON); } } diff --git a/src/main/java/seedu/address/logic/commands/ListWeddingsCommand.java b/src/main/java/seedu/address/logic/commands/ListWeddingsCommand.java new file mode 100644 index 00000000000..f7d10ef90b2 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/ListWeddingsCommand.java @@ -0,0 +1,24 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_WEDDINGS; + +import seedu.address.logic.commands.CommandResult.SwitchView; +import seedu.address.model.Model; + +/** + * Lists all persons in the address book to the user. + */ +public class ListWeddingsCommand extends Command { + + public static final String COMMAND_WORD = "list-weddings"; + + public static final String MESSAGE_SUCCESS = "Listed all weddings"; + + @Override + public CommandResult execute(Model model) { + requireNonNull(model); + model.updateFilteredWeddingList(PREDICATE_SHOW_ALL_WEDDINGS); + return new CommandResult(MESSAGE_SUCCESS, SwitchView.WEDDING); + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index b3561e4b9de..fb2b8411faf 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -21,6 +21,7 @@ import seedu.address.logic.commands.ExitCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.ListWeddingsCommand; import seedu.address.logic.commands.TagCommand; import seedu.address.logic.commands.UnassignWeddingCommand; import seedu.address.logic.commands.UntagCommand; @@ -66,6 +67,7 @@ public Command parseCommand(String userInput) throws ParseException { case ClearCommand.COMMAND_WORD -> new ClearCommand(); case FindCommand.COMMAND_WORD -> new FindCommandParser().parse(arguments); case ListCommand.COMMAND_WORD -> new ListCommand(); + case ListWeddingsCommand.COMMAND_WORD -> new ListWeddingsCommand(); case ExitCommand.COMMAND_WORD -> new ExitCommand(); case HelpCommand.COMMAND_WORD -> new HelpCommand(); case CreateTagCommand.COMMAND_WORD -> new CreateTagCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 79e74ef37c0..2605b1cd981 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -14,6 +14,7 @@ import seedu.address.commons.core.LogsCenter; import seedu.address.logic.Logic; import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.CommandResult.SwitchView; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; @@ -32,6 +33,7 @@ public class MainWindow extends UiPart { // Independent Ui parts residing in this Ui container private PersonListPanel personListPanel; + private WeddingListPanel weddingListPanel; private ResultDisplay resultDisplay; private HelpWindow helpWindow; @@ -42,7 +44,7 @@ public class MainWindow extends UiPart { private MenuItem helpMenuItem; @FXML - private StackPane personListPanelPlaceholder; + private StackPane listPanelPlaceholder; @FXML private StackPane resultDisplayPlaceholder; @@ -111,7 +113,7 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) { */ void fillInnerParts() { personListPanel = new PersonListPanel(logic.getFilteredPersonList()); - personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + listPanelPlaceholder.getChildren().add(personListPanel.getRoot()); resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); @@ -186,6 +188,10 @@ private CommandResult executeCommand(String commandText) throws CommandException handleExit(); } + if (commandResult.isSwitchView()) { + switchView(commandResult.getView()); + } + return commandResult; } catch (CommandException | ParseException e) { logger.info("An error occurred while executing command: " + commandText); @@ -193,4 +199,40 @@ private CommandResult executeCommand(String commandText) throws CommandException throw e; } } + + /** + * Switches the view shown to the user. + * @param switchView The view that should be shown. + */ + public void switchView(SwitchView switchView) { + switch (switchView) { + case PERSON: + changeToPersonView(); + break; + case WEDDING: + changeToWeddingView(); + break; + default: + throw new UnsupportedOperationException("Invalid view selected."); + } + } + + /** + * Changes the list panel to show the wedding list. + */ + public void changeToWeddingView() { + weddingListPanel = new WeddingListPanel(logic.getFilteredWeddingList()); + listPanelPlaceholder.getChildren().clear(); + listPanelPlaceholder.getChildren().add(weddingListPanel.getRoot()); + } + + /** + * Changes the list panel to show the wedding list. + */ + public void changeToPersonView() { + personListPanel = new PersonListPanel(logic.getFilteredPersonList()); + listPanelPlaceholder.getChildren().clear(); + listPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + } + } diff --git a/src/main/java/seedu/address/ui/UiManager.java b/src/main/java/seedu/address/ui/UiManager.java index fdf024138bc..b5879b736a2 100644 --- a/src/main/java/seedu/address/ui/UiManager.java +++ b/src/main/java/seedu/address/ui/UiManager.java @@ -19,6 +19,14 @@ public class UiManager implements Ui { public static final String ALERT_DIALOG_PANE_FIELD_ID = "alertDialogPane"; + /** + * The set of possible views. + */ + public static enum View { + PERSON, + WEDDING + } + private static final Logger logger = LogsCenter.getLogger(UiManager.class); private static final String ICON_APPLICATION = "/images/address_book_32.png"; diff --git a/src/main/java/seedu/address/ui/WeddingCard.java b/src/main/java/seedu/address/ui/WeddingCard.java new file mode 100644 index 00000000000..f903f2e7af9 --- /dev/null +++ b/src/main/java/seedu/address/ui/WeddingCard.java @@ -0,0 +1,42 @@ +package seedu.address.ui; + +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Region; +import seedu.address.model.wedding.Wedding; + +/** + * A UI component that displays information of a {@code Person}. + */ +public class WeddingCard extends UiPart { + + private static final String FXML = "WeddingListCard.fxml"; + + /** + * Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX. + * As a consequence, UI elements' variable names cannot be set to such keywords + * or an exception will be thrown by JavaFX during runtime. + * + * @see The issue on AddressBook level 4 + */ + + public final Wedding wedding; + + @FXML + private HBox cardPane; + @FXML + private Label name; + @FXML + private Label id; + + /** + * Creates a {@code PersonCode} with the given {@code Person} and index to display. + */ + public WeddingCard(Wedding wedding, int displayedIndex) { + super(FXML); + this.wedding = wedding; + id.setText(displayedIndex + ". "); + name.setText(wedding.getWeddingName().toString()); + } +} diff --git a/src/main/java/seedu/address/ui/WeddingListPanel.java b/src/main/java/seedu/address/ui/WeddingListPanel.java new file mode 100644 index 00000000000..9eb9baf03b1 --- /dev/null +++ b/src/main/java/seedu/address/ui/WeddingListPanel.java @@ -0,0 +1,49 @@ +package seedu.address.ui; + +import java.util.logging.Logger; + +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.scene.layout.Region; +import seedu.address.commons.core.LogsCenter; +import seedu.address.model.wedding.Wedding; + +/** + * Panel containing the list of persons. + */ +public class WeddingListPanel extends UiPart { + private static final String FXML = "WeddingListPanel.fxml"; + private final Logger logger = LogsCenter.getLogger(WeddingListPanel.class); + + @FXML + private ListView weddingListView; + + /** + * Creates a {@code PersonListPanel} with the given {@code ObservableList}. + */ + public WeddingListPanel(ObservableList weddingList) { + super(FXML); + weddingListView.setItems(weddingList); + weddingListView.setCellFactory(listView -> new WeddingListViewCell()); + } + + /** + * Custom {@code ListCell} that displays the graphics of a {@code Person} using a {@code PersonCard}. + */ + class WeddingListViewCell extends ListCell { + @Override + protected void updateItem(Wedding wedding, boolean empty) { + super.updateItem(wedding, empty); + + if (empty || wedding == null) { + setGraphic(null); + setText(null); + } else { + setGraphic(new WeddingCard(wedding, getIndex() + 1).getRoot()); + } + } + } + +} diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml index 0fb778a8560..87ed871fc4b 100644 --- a/src/main/resources/view/MainWindow.fxml +++ b/src/main/resources/view/MainWindow.fxml @@ -46,11 +46,11 @@ - + - + diff --git a/src/main/resources/view/WeddingListCard.fxml b/src/main/resources/view/WeddingListCard.fxml new file mode 100644 index 00000000000..8865781ff7d --- /dev/null +++ b/src/main/resources/view/WeddingListCard.fxml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/view/WeddingListPanel.fxml b/src/main/resources/view/WeddingListPanel.fxml new file mode 100644 index 00000000000..018f95b4065 --- /dev/null +++ b/src/main/resources/view/WeddingListPanel.fxml @@ -0,0 +1,8 @@ + + + + + + + + From d2111ff365687edebb3910858605d18ec42e35c5 Mon Sep 17 00:00:00 2001 From: dasha3412 Date: Sat, 19 Oct 2024 13:44:29 +0800 Subject: [PATCH 3/9] Fix comments --- src/main/java/seedu/address/logic/LogicManager.java | 1 - .../seedu/address/logic/commands/ListWeddingsCommand.java | 2 +- src/main/java/seedu/address/ui/MainWindow.java | 4 ++-- src/main/java/seedu/address/ui/PersonCard.java | 2 +- src/main/java/seedu/address/ui/WeddingCard.java | 4 ++-- src/main/java/seedu/address/ui/WeddingListPanel.java | 6 +++--- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index f8cc99fedb2..8e48bb01f1b 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -10,7 +10,6 @@ import seedu.address.commons.core.LogsCenter; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; -import seedu.address.logic.commands.CommandResult.SwitchView; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.AddressBookParser; import seedu.address.logic.parser.exceptions.ParseException; diff --git a/src/main/java/seedu/address/logic/commands/ListWeddingsCommand.java b/src/main/java/seedu/address/logic/commands/ListWeddingsCommand.java index f7d10ef90b2..165a2040b92 100644 --- a/src/main/java/seedu/address/logic/commands/ListWeddingsCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListWeddingsCommand.java @@ -7,7 +7,7 @@ import seedu.address.model.Model; /** - * Lists all persons in the address book to the user. + * Lists all weddings in the address book to the user. */ public class ListWeddingsCommand extends Command { diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 2605b1cd981..1c59f71ac56 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -218,7 +218,7 @@ public void switchView(SwitchView switchView) { } /** - * Changes the list panel to show the wedding list. + * Changes the list panel to show the {@code Wedding} list. */ public void changeToWeddingView() { weddingListPanel = new WeddingListPanel(logic.getFilteredWeddingList()); @@ -227,7 +227,7 @@ public void changeToWeddingView() { } /** - * Changes the list panel to show the wedding list. + * Changes the list panel to show the {@code Person} list. */ public void changeToPersonView() { personListPanel = new PersonListPanel(logic.getFilteredPersonList()); diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index c44e7e2394b..8a903a2a257 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -44,7 +44,7 @@ public class PersonCard extends UiPart { private FlowPane weddings; /** - * Creates a {@code PersonCode} with the given {@code Person} and index to display. + * Creates a {@code PersonCard} with the given {@code Person} and index to display. */ public PersonCard(Person person, int displayedIndex) { super(FXML); diff --git a/src/main/java/seedu/address/ui/WeddingCard.java b/src/main/java/seedu/address/ui/WeddingCard.java index f903f2e7af9..b0d0e72f668 100644 --- a/src/main/java/seedu/address/ui/WeddingCard.java +++ b/src/main/java/seedu/address/ui/WeddingCard.java @@ -7,7 +7,7 @@ import seedu.address.model.wedding.Wedding; /** - * A UI component that displays information of a {@code Person}. + * A UI component that displays information of a {@code Wedding}. */ public class WeddingCard extends UiPart { @@ -31,7 +31,7 @@ public class WeddingCard extends UiPart { private Label id; /** - * Creates a {@code PersonCode} with the given {@code Person} and index to display. + * Creates a {@code WeddingCard} with the given {@code Wedding} and index to display. */ public WeddingCard(Wedding wedding, int displayedIndex) { super(FXML); diff --git a/src/main/java/seedu/address/ui/WeddingListPanel.java b/src/main/java/seedu/address/ui/WeddingListPanel.java index 9eb9baf03b1..c899ce3926c 100644 --- a/src/main/java/seedu/address/ui/WeddingListPanel.java +++ b/src/main/java/seedu/address/ui/WeddingListPanel.java @@ -11,7 +11,7 @@ import seedu.address.model.wedding.Wedding; /** - * Panel containing the list of persons. + * Panel containing the list of weddings. */ public class WeddingListPanel extends UiPart { private static final String FXML = "WeddingListPanel.fxml"; @@ -21,7 +21,7 @@ public class WeddingListPanel extends UiPart { private ListView weddingListView; /** - * Creates a {@code PersonListPanel} with the given {@code ObservableList}. + * Creates a {@code WeddingListPanel} with the given {@code ObservableList}. */ public WeddingListPanel(ObservableList weddingList) { super(FXML); @@ -30,7 +30,7 @@ public WeddingListPanel(ObservableList weddingList) { } /** - * Custom {@code ListCell} that displays the graphics of a {@code Person} using a {@code PersonCard}. + * Custom {@code ListCell} that displays the graphics of a {@code Wedding} using a {@code WeddingCard}. */ class WeddingListViewCell extends ListCell { @Override From ad81b7c4f2dbf7cdfc4e70306b69a6262a26929f Mon Sep 17 00:00:00 2001 From: dasha3412 Date: Sat, 19 Oct 2024 14:48:50 +0800 Subject: [PATCH 4/9] Add AddressBookParser tests --- .../address/logic/commands/CommandResult.java | 6 +- .../logic/commands/CommandResultTest.java | 30 +++++- .../logic/commands/ListCommandTest.java | 6 +- .../logic/parser/AddressBookParserTest.java | 91 +++++++++++++++++++ 4 files changed, 126 insertions(+), 7 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/CommandResult.java b/src/main/java/seedu/address/logic/commands/CommandResult.java index 8f0ba01e47f..9719d8c0931 100644 --- a/src/main/java/seedu/address/logic/commands/CommandResult.java +++ b/src/main/java/seedu/address/logic/commands/CommandResult.java @@ -104,12 +104,13 @@ public boolean equals(Object other) { CommandResult otherCommandResult = (CommandResult) other; return feedbackToUser.equals(otherCommandResult.feedbackToUser) && showHelp == otherCommandResult.showHelp - && exit == otherCommandResult.exit; + && exit == otherCommandResult.exit + && switchView == otherCommandResult.switchView; } @Override public int hashCode() { - return Objects.hash(feedbackToUser, showHelp, exit); + return Objects.hash(feedbackToUser, showHelp, exit, switchView); } @Override @@ -118,6 +119,7 @@ public String toString() { .add("feedbackToUser", feedbackToUser) .add("showHelp", showHelp) .add("exit", exit) + .add("switchView", switchView) .toString(); } diff --git a/src/test/java/seedu/address/logic/commands/CommandResultTest.java b/src/test/java/seedu/address/logic/commands/CommandResultTest.java index 7b8c7cd4546..c0d589332de 100644 --- a/src/test/java/seedu/address/logic/commands/CommandResultTest.java +++ b/src/test/java/seedu/address/logic/commands/CommandResultTest.java @@ -7,6 +7,8 @@ import org.junit.jupiter.api.Test; +import seedu.address.logic.commands.CommandResult.SwitchView; + public class CommandResultTest { @Test public void equals() { @@ -15,6 +17,12 @@ public void equals() { // same values -> returns true assertTrue(commandResult.equals(new CommandResult("feedback"))); assertTrue(commandResult.equals(new CommandResult("feedback", false, false))); + assertTrue(commandResult.equals(new CommandResult("feedback", false, false, + SwitchView.NONE))); + + // same object -> returns true + assertEquals(commandResult.isSwitchView(), new CommandResult("feedback", false, false, + SwitchView.NONE).isSwitchView()); // same object -> returns true assertTrue(commandResult.equals(commandResult)); @@ -29,10 +37,22 @@ public void equals() { assertFalse(commandResult.equals(new CommandResult("different"))); // different showHelp value -> returns false - assertFalse(commandResult.equals(new CommandResult("feedback", true, false))); + assertFalse(commandResult.equals(new CommandResult("feedback", true, false, + SwitchView.NONE))); // different exit value -> returns false - assertFalse(commandResult.equals(new CommandResult("feedback", false, true))); + assertFalse(commandResult.equals(new CommandResult("feedback", false, true, + SwitchView.NONE))); + + // different switchView value -> returns false + assertFalse(commandResult.equals(new CommandResult("feedback", false, false, + SwitchView.WEDDING))); + assertFalse(commandResult.equals(new CommandResult("feedback", false, false, + SwitchView.PERSON))); + + // different switchView value -> returns false + assertNotEquals(commandResult.isSwitchView(), new CommandResult("feedback", false, false, + SwitchView.PERSON).isSwitchView()); } @Test @@ -50,6 +70,10 @@ public void hashcode() { // different exit value -> returns different hashcode assertNotEquals(commandResult.hashCode(), new CommandResult("feedback", false, true).hashCode()); + + // different exit value -> returns different hashcode + assertNotEquals(commandResult.hashCode(), new CommandResult("feedback", false, false, + SwitchView.PERSON).hashCode()); } @Test @@ -57,7 +81,7 @@ public void toStringMethod() { CommandResult commandResult = new CommandResult("feedback"); String expected = CommandResult.class.getCanonicalName() + "{feedbackToUser=" + commandResult.getFeedbackToUser() + ", showHelp=" + commandResult.isShowHelp() - + ", exit=" + commandResult.isExit() + "}"; + + ", exit=" + commandResult.isExit() + ", switchView=" + commandResult.getView() + "}"; assertEquals(expected, commandResult.toString()); } } diff --git a/src/test/java/seedu/address/logic/commands/ListCommandTest.java b/src/test/java/seedu/address/logic/commands/ListCommandTest.java index 435ff1f7275..90c22ea7c28 100644 --- a/src/test/java/seedu/address/logic/commands/ListCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ListCommandTest.java @@ -28,12 +28,14 @@ public void setUp() { @Test public void execute_listIsNotFiltered_showsSameList() { - assertCommandSuccess(new ListCommand(), model, ListCommand.MESSAGE_SUCCESS, expectedModel); + CommandResult actualCommandResult = new ListCommand().execute(model); + assertCommandSuccess(new ListCommand(), model, actualCommandResult, expectedModel); } @Test public void execute_listIsFiltered_showsEverything() { showPersonAtIndex(model, INDEX_FIRST_PERSON); - assertCommandSuccess(new ListCommand(), model, ListCommand.MESSAGE_SUCCESS, expectedModel); + CommandResult actualCommandResult = new ListCommand().execute(model); + assertCommandSuccess(new ListCommand(), model, actualCommandResult, expectedModel); } } diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 9afe7b43653..d2897bebf6d 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -15,14 +15,22 @@ import org.junit.jupiter.api.Test; import seedu.address.logic.commands.AddCommand; +import seedu.address.logic.commands.AssignWeddingCommand; import seedu.address.logic.commands.ClearCommand; +import seedu.address.logic.commands.CreateTagCommand; +import seedu.address.logic.commands.CreateWeddingCommand; import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.commands.DeleteTagCommand; +import seedu.address.logic.commands.DeleteWeddingCommand; import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; import seedu.address.logic.commands.ExitCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.ListWeddingsCommand; import seedu.address.logic.commands.TagCommand; +import seedu.address.logic.commands.UnassignWeddingCommand; +import seedu.address.logic.commands.UntagCommand; import seedu.address.logic.commands.findcommand.FindCommand; import seedu.address.logic.commands.findcommand.FindNameCommand; import seedu.address.logic.parser.exceptions.ParseException; @@ -30,6 +38,8 @@ import seedu.address.model.person.keywordspredicate.NameContainsKeywordsPredicate; import seedu.address.model.tag.Tag; import seedu.address.model.tag.TagName; +import seedu.address.model.wedding.Wedding; +import seedu.address.model.wedding.WeddingName; import seedu.address.testutil.EditPersonDescriptorBuilder; import seedu.address.testutil.PersonBuilder; import seedu.address.testutil.PersonUtil; @@ -104,6 +114,87 @@ public void parseCommand_tag() throws Exception { assertEquals(expectedCommand, command); } + @Test + public void parseCommand_untag() throws Exception { + HashSet tagsToRemove = new HashSet<>(Arrays.asList(new Tag(new TagName("colleague")), + new Tag(new TagName("gym")))); + String userInput = UntagCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased() + " t/gym t/colleague"; + UntagCommand expectedCommand = new UntagCommand(INDEX_FIRST_PERSON, tagsToRemove); + + UntagCommand command = (UntagCommand) parser.parseCommand(userInput); + assertEquals(expectedCommand, command); + } + + @Test + public void parseCommand_createTag() throws Exception { + Tag tagToCreate = new Tag(new TagName("colleague")); + String userInput = CreateTagCommand.COMMAND_WORD + " t/colleague"; + CreateTagCommand expectedCommand = new CreateTagCommand(tagToCreate); + + CreateTagCommand command = (CreateTagCommand) parser.parseCommand(userInput); + assertEquals(expectedCommand, command); + } + + @Test + public void parseCommand_deleteTag() throws Exception { + Tag tagToDelete = new Tag(new TagName("vendor")); + String userInput = DeleteTagCommand.COMMAND_WORD + " t/vendor"; + DeleteTagCommand expectedCommand = new DeleteTagCommand(tagToDelete); + + DeleteTagCommand command = (DeleteTagCommand) parser.parseCommand(userInput); + assertEquals(expectedCommand, command); + } + + @Test + public void parseCommand_createWedding() throws Exception { + Wedding weddingToCreate = new Wedding(new WeddingName("Wedding 19")); + String userInput = CreateWeddingCommand.COMMAND_WORD + " w/Wedding 19"; + CreateWeddingCommand expectedCommand = new CreateWeddingCommand(weddingToCreate); + + CreateWeddingCommand command = (CreateWeddingCommand) parser.parseCommand(userInput); + assertEquals(expectedCommand, command); + } + + @Test + public void parseCommand_deleteWedding() throws Exception { + Wedding weddingToDelete = new Wedding(new WeddingName("Joe's Wedding")); + String userInput = DeleteWeddingCommand.COMMAND_WORD + " w/Joe's Wedding"; + DeleteWeddingCommand expectedCommand = new DeleteWeddingCommand(weddingToDelete); + + DeleteWeddingCommand command = (DeleteWeddingCommand) parser.parseCommand(userInput); + assertEquals(expectedCommand, command); + } + + @Test + public void parseCommand_assignWedding() throws Exception { + HashSet weddingsToAdd = new HashSet<>(Arrays.asList(new Wedding(new WeddingName("Wedding 19")), + new Wedding(new WeddingName("Joe's Wedding")))); + String userInput = AssignWeddingCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased() + + " w/Wedding 19 w/Joe's Wedding"; + AssignWeddingCommand expectedCommand = new AssignWeddingCommand(INDEX_FIRST_PERSON, weddingsToAdd); + + AssignWeddingCommand command = (AssignWeddingCommand) parser.parseCommand(userInput); + assertEquals(expectedCommand, command); + } + + @Test + public void parseCommand_unassignWedding() throws Exception { + HashSet weddingsToRemove = new HashSet<>(Arrays.asList(new Wedding(new WeddingName("Wedding 19")), + new Wedding(new WeddingName("Joe's Wedding")))); + String userInput = UnassignWeddingCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased() + + " w/Wedding 19 w/Joe's Wedding"; + UnassignWeddingCommand expectedCommand = new UnassignWeddingCommand(INDEX_FIRST_PERSON, weddingsToRemove); + + UnassignWeddingCommand command = (UnassignWeddingCommand) parser.parseCommand(userInput); + assertEquals(expectedCommand, command); + } + + @Test + public void parseCommand_listWeddings() throws Exception { + assertTrue(parser.parseCommand(ListWeddingsCommand.COMMAND_WORD) instanceof ListWeddingsCommand); + assertTrue(parser.parseCommand(ListWeddingsCommand.COMMAND_WORD + " 3") instanceof ListWeddingsCommand); + } + @Test public void parseCommand_unrecognisedInput_throwsParseException() { assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE), () From 82a38c7c6d33abf998a1376eb302aef46c8d8d15 Mon Sep 17 00:00:00 2001 From: dasha3412 Date: Sat, 19 Oct 2024 15:03:20 +0800 Subject: [PATCH 5/9] Add list weddings testing --- .../ListWeddingsCommandIntegrationTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/test/java/seedu/address/logic/commands/ListWeddingsCommandIntegrationTest.java diff --git a/src/test/java/seedu/address/logic/commands/ListWeddingsCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/ListWeddingsCommandIntegrationTest.java new file mode 100644 index 00000000000..627fa6b6d2f --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/ListWeddingsCommandIntegrationTest.java @@ -0,0 +1,36 @@ +package seedu.address.logic.commands; + +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; + +/** + * Contains integration tests (interaction with the Model) and unit tests for ListCommand. + */ +public class ListWeddingsCommandIntegrationTest { + + private Model model; + private Model expectedModel; + + @BeforeEach + public void setUp() { + model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + } + + @Test + public void execute_listIsNotFiltered_showsSameList() { + CommandResult actualCommandResult = new ListWeddingsCommand().execute(model); + assertCommandSuccess(new ListWeddingsCommand(), model, actualCommandResult, expectedModel); + } + + // Todo: if wedding filtering is done in the wedding view, have tests for filtered list +} From 78aa77ad63511db1fc63995c97a6b377b30909e8 Mon Sep 17 00:00:00 2001 From: dasha3412 Date: Sat, 19 Oct 2024 15:56:01 +0800 Subject: [PATCH 6/9] Fix checkstyle --- .../logic/commands/ListWeddingsCommandIntegrationTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/seedu/address/logic/commands/ListWeddingsCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/ListWeddingsCommandIntegrationTest.java index 627fa6b6d2f..7df4a462f84 100644 --- a/src/test/java/seedu/address/logic/commands/ListWeddingsCommandIntegrationTest.java +++ b/src/test/java/seedu/address/logic/commands/ListWeddingsCommandIntegrationTest.java @@ -1,8 +1,6 @@ package seedu.address.logic.commands; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import org.junit.jupiter.api.BeforeEach; From cd99c98fd33f5d3c47ce5bc9bd87983291a5766b Mon Sep 17 00:00:00 2001 From: dasha3412 Date: Sat, 19 Oct 2024 16:16:28 +0800 Subject: [PATCH 7/9] Fix LogicManager test coverage --- src/main/java/seedu/address/ui/UiManager.java | 8 -------- src/test/java/seedu/address/logic/LogicManagerTest.java | 5 +++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/seedu/address/ui/UiManager.java b/src/main/java/seedu/address/ui/UiManager.java index b5879b736a2..fdf024138bc 100644 --- a/src/main/java/seedu/address/ui/UiManager.java +++ b/src/main/java/seedu/address/ui/UiManager.java @@ -19,14 +19,6 @@ public class UiManager implements Ui { public static final String ALERT_DIALOG_PANE_FIELD_ID = "alertDialogPane"; - /** - * The set of possible views. - */ - public static enum View { - PERSON, - WEDDING - } - private static final Logger logger = LogsCenter.getLogger(UiManager.class); private static final String ICON_APPLICATION = "/images/address_book_32.png"; diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index baf8ce336a2..94aa06081da 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -87,6 +87,11 @@ public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException assertThrows(UnsupportedOperationException.class, () -> logic.getFilteredPersonList().remove(0)); } + @Test + public void getFilteredWeddingList_modifyList_throwsUnsupportedOperationException() { + assertThrows(UnsupportedOperationException.class, () -> logic.getFilteredWeddingList().remove(0)); + } + /** * Executes the command and confirms that * - no exceptions are thrown
From d2be0b90a50d5df383645b4e19c69e2f11abb765 Mon Sep 17 00:00:00 2001 From: dasha3412 Date: Sun, 20 Oct 2024 00:13:36 +0800 Subject: [PATCH 8/9] Make changing view more efficient --- src/main/java/seedu/address/ui/MainWindow.java | 6 ++++-- src/main/java/seedu/address/ui/PersonListPanel.java | 8 ++++++++ src/main/java/seedu/address/ui/WeddingListPanel.java | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 1c59f71ac56..cd8516cb4f0 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -115,6 +115,8 @@ void fillInnerParts() { personListPanel = new PersonListPanel(logic.getFilteredPersonList()); listPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + weddingListPanel = new WeddingListPanel(logic.getFilteredWeddingList()); + resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); @@ -221,7 +223,7 @@ public void switchView(SwitchView switchView) { * Changes the list panel to show the {@code Wedding} list. */ public void changeToWeddingView() { - weddingListPanel = new WeddingListPanel(logic.getFilteredWeddingList()); + weddingListPanel.updateWeddingList(logic.getFilteredWeddingList()); listPanelPlaceholder.getChildren().clear(); listPanelPlaceholder.getChildren().add(weddingListPanel.getRoot()); } @@ -230,7 +232,7 @@ public void changeToWeddingView() { * Changes the list panel to show the {@code Person} list. */ public void changeToPersonView() { - personListPanel = new PersonListPanel(logic.getFilteredPersonList()); + personListPanel.updatePersonList(logic.getFilteredPersonList()); listPanelPlaceholder.getChildren().clear(); listPanelPlaceholder.getChildren().add(personListPanel.getRoot()); } diff --git a/src/main/java/seedu/address/ui/PersonListPanel.java b/src/main/java/seedu/address/ui/PersonListPanel.java index f4c501a897b..2c5499140c2 100644 --- a/src/main/java/seedu/address/ui/PersonListPanel.java +++ b/src/main/java/seedu/address/ui/PersonListPanel.java @@ -9,6 +9,7 @@ import javafx.scene.layout.Region; import seedu.address.commons.core.LogsCenter; import seedu.address.model.person.Person; +import seedu.address.model.wedding.Wedding; /** * Panel containing the list of persons. @@ -29,6 +30,13 @@ public PersonListPanel(ObservableList personList) { personListView.setCellFactory(listView -> new PersonListViewCell()); } + /** + * Updates the {@code PersonListView} with an updated list of persons. + */ + public void updatePersonList(ObservableList personList) { + personListView.setItems(personList); + } + /** * Custom {@code ListCell} that displays the graphics of a {@code Person} using a {@code PersonCard}. */ diff --git a/src/main/java/seedu/address/ui/WeddingListPanel.java b/src/main/java/seedu/address/ui/WeddingListPanel.java index c899ce3926c..23c86ccd999 100644 --- a/src/main/java/seedu/address/ui/WeddingListPanel.java +++ b/src/main/java/seedu/address/ui/WeddingListPanel.java @@ -29,6 +29,13 @@ public WeddingListPanel(ObservableList weddingList) { weddingListView.setCellFactory(listView -> new WeddingListViewCell()); } + /** + * Updates the {@code WeddingListView} with an updated list of weddings. + */ + public void updateWeddingList(ObservableList weddingList) { + weddingListView.setItems(weddingList); + } + /** * Custom {@code ListCell} that displays the graphics of a {@code Wedding} using a {@code WeddingCard}. */ From 52b011dcad12ac6449b907c282226e8e2eae0713 Mon Sep 17 00:00:00 2001 From: dasha3412 Date: Sun, 20 Oct 2024 00:24:05 +0800 Subject: [PATCH 9/9] Fix checkstyle --- src/main/java/seedu/address/ui/PersonListPanel.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/seedu/address/ui/PersonListPanel.java b/src/main/java/seedu/address/ui/PersonListPanel.java index 2c5499140c2..55495949246 100644 --- a/src/main/java/seedu/address/ui/PersonListPanel.java +++ b/src/main/java/seedu/address/ui/PersonListPanel.java @@ -9,7 +9,6 @@ import javafx.scene.layout.Region; import seedu.address.commons.core.LogsCenter; import seedu.address.model.person.Person; -import seedu.address.model.wedding.Wedding; /** * Panel containing the list of persons.