Skip to content

Commit

Permalink
Merge pull request AY2425S1-CS2103T-T11-2#282 from currynia/branch-b
Browse files Browse the repository at this point in the history
Update view command
  • Loading branch information
Incogdino authored Nov 8, 2024
2 parents b340f50 + 491769a commit f2bd627
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/java/seedu/address/logic/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ public class ViewCommand extends Command {
public static final String CLOSE_VIEW_ACKNOWLEDGMENT = "Closing view of contact";
private static final ViewCommand closeView = new ViewCommand();
private static final CommandResult closeViewResult = new CommandResult(CLOSE_VIEW_ACKNOWLEDGMENT, null, true);

private static ListChangeListener<Person> listener;
private final Name personName;
private final boolean isClose;



/**
* @param name Name of the contact.
*/
Expand All @@ -66,6 +65,9 @@ public static CommandResult getCloseViewResult() {

@Override
public CommandResult execute(Model model) throws CommandException {
if (listener != null) {
model.getAddressBook().getPersonList().removeListener(listener);
}
if (isClose) {
return closeViewResult;
}
Expand All @@ -80,12 +82,12 @@ public CommandResult execute(Model model) throws CommandException {

private CommandResult createCommandResult(Model model) {
ObjectProperty<Person> person = new SimpleObjectProperty<>(model.getPerson(personName).orElseThrow());
ListChangeListener<Person> listener = change -> {
listener = change -> {
while (change.next()) {
if (change.wasAdded() || change.wasRemoved()) {
if (change.wasRemoved()) {
person.set(null);
model.getPerson(personName).ifPresentOrElse(
person::set, () -> {});
person::set, () -> model.getAddressBook().getPersonList().removeListener(listener));

}
}
Expand Down

0 comments on commit f2bd627

Please sign in to comment.