Skip to content

Commit

Permalink
Merge pull request AY2425S1-CS2103T-F15-4#114 from dasha3412/branch-w…
Browse files Browse the repository at this point in the history
…eddingUI

Add UI to show weddings
  • Loading branch information
riccoljy authored Oct 23, 2024
2 parents 0e49722 + 52b011d commit b2d648b
Show file tree
Hide file tree
Showing 20 changed files with 446 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies {
}

shadowJar {
archiveFileName = 'addressbook.jar'
archiveFileName = 'WedLinker.jar'
}

defaultTasks 'clean', 'test'
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +34,9 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();

/** Returns an unmodifiable view of the filtered list of weddings */
ObservableList<Wedding> getFilteredWeddingList();

/**
* Returns the user prefs' address book file path.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;

/**
Expand Down Expand Up @@ -71,6 +72,11 @@ public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
}

@Override
public ObservableList<Wedding> getFilteredWeddingList() {
return model.getFilteredWeddingList();
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
Expand Down
52 changes: 48 additions & 4 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,49 @@ 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;
}

/**
* Constructs a {@code CommandResult} with the specified {@code feedbackToUser},
* 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() {
Expand All @@ -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;
}
Expand All @@ -62,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
Expand All @@ -76,6 +119,7 @@ public String toString() {
.add("feedbackToUser", feedbackToUser)
.add("showHelp", showHelp)
.add("exit", exit)
.add("switchView", switchView)
.toString();
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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 weddings 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
48 changes: 46 additions & 2 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,6 +33,7 @@ public class MainWindow extends UiPart<Stage> {

// Independent Ui parts residing in this Ui container
private PersonListPanel personListPanel;
private WeddingListPanel weddingListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;

Expand All @@ -42,7 +44,7 @@ public class MainWindow extends UiPart<Stage> {
private MenuItem helpMenuItem;

@FXML
private StackPane personListPanelPlaceholder;
private StackPane listPanelPlaceholder;

@FXML
private StackPane resultDisplayPlaceholder;
Expand Down Expand Up @@ -111,7 +113,9 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
*/
void fillInnerParts() {
personListPanel = new PersonListPanel(logic.getFilteredPersonList());
personListPanelPlaceholder.getChildren().add(personListPanel.getRoot());
listPanelPlaceholder.getChildren().add(personListPanel.getRoot());

weddingListPanel = new WeddingListPanel(logic.getFilteredWeddingList());

resultDisplay = new ResultDisplay();
resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot());
Expand Down Expand Up @@ -186,11 +190,51 @@ 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);
resultDisplay.setFeedbackToUser(e.getMessage());
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 {@code Wedding} list.
*/
public void changeToWeddingView() {
weddingListPanel.updateWeddingList(logic.getFilteredWeddingList());
listPanelPlaceholder.getChildren().clear();
listPanelPlaceholder.getChildren().add(weddingListPanel.getRoot());
}

/**
* Changes the list panel to show the {@code Person} list.
*/
public void changeToPersonView() {
personListPanel.updatePersonList(logic.getFilteredPersonList());
listPanelPlaceholder.getChildren().clear();
listPanelPlaceholder.getChildren().add(personListPanel.getRoot());
}

}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class PersonCard extends UiPart<Region> {
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);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/ui/PersonListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public PersonListPanel(ObservableList<Person> personList) {
personListView.setCellFactory(listView -> new PersonListViewCell());
}

/**
* Updates the {@code PersonListView} with an updated list of persons.
*/
public void updatePersonList(ObservableList<Person> personList) {
personListView.setItems(personList);
}

/**
* Custom {@code ListCell} that displays the graphics of a {@code Person} using a {@code PersonCard}.
*/
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/seedu/address/ui/WeddingCard.java
Original file line number Diff line number Diff line change
@@ -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 Wedding}.
*/
public class WeddingCard extends UiPart<Region> {

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 <a href="https://github.com/se-edu/addressbook-level4/issues/336">The issue on AddressBook level 4</a>
*/

public final Wedding wedding;

@FXML
private HBox cardPane;
@FXML
private Label name;
@FXML
private Label id;

/**
* Creates a {@code WeddingCard} with the given {@code Wedding} and index to display.
*/
public WeddingCard(Wedding wedding, int displayedIndex) {
super(FXML);
this.wedding = wedding;
id.setText(displayedIndex + ". ");
name.setText(wedding.getWeddingName().toString());
}
}
Loading

0 comments on commit b2d648b

Please sign in to comment.