From d7e03306344866e0d0080a7e5edbba4308005c15 Mon Sep 17 00:00:00 2001 From: John Phua Date: Fri, 2 Nov 2018 11:40:07 +0800 Subject: [PATCH] Contacts assigned and tasks assigned commands (#113) * Add predicates for assignment of tasks and persons * Change select command to assigned command * Add assigned command for tasks * Refactor and change equality operator to .equals * Fix trailing whitespaces * Fix wrong import order * Fix lint * Remove contacts select from user guide * Fix and standardise line breaks in events --- docs/UserGuide.adoc | 8 +-- .../events/ui/CalendarPanelClickEvent.java | 1 + .../ui/JumpToPersonListRequestEvent.java | 1 - .../events/ui/JumpToTaskListRequestEvent.java | 1 - .../events/ui/NewResultAvailableEvent.java | 1 - .../ui/PersonPanelDeselectionEvent.java | 14 ++++ .../ui/PersonPanelSelectionChangedEvent.java | 1 - .../events/ui/ShowHelpRequestEvent.java | 1 - .../events/ui/TaskPanelDeselectionEvent.java | 2 +- .../ui/TaskPanelSelectionChangedEvent.java | 2 - ...electCommand.java => AssignedCommand.java} | 21 ++++-- .../logic/commands/tasks/AssignedCommand.java | 66 +++++++++++++++++++ .../address/logic/parser/ContactsParser.java | 8 +-- .../address/logic/parser/TasksParser.java | 5 ++ ...Parser.java => AssignedCommandParser.java} | 16 ++--- .../parser/tasks/AssignedCommandParser.java | 30 +++++++++ .../person/IsAssignedToPersonPredicate.java | 30 +++++++++ .../model/task/IsAssignedToTaskPredicate.java | 30 +++++++++ .../seedu/address/ui/PersonListPanel.java | 5 ++ ...mandTest.java => AssignedCommandTest.java} | 24 +++---- .../logic/parser/ContactsParserTest.java | 10 +-- ...st.java => AssignedCommandParserTest.java} | 10 +-- .../systemtests/HelpCommandSystemTest.java | 4 +- ...st.java => AssignedCommandSystemTest.java} | 43 +++++++----- .../contacts/ContactsSystemTest.java | 4 +- 25 files changed, 260 insertions(+), 78 deletions(-) create mode 100644 src/main/java/seedu/address/commons/events/ui/PersonPanelDeselectionEvent.java rename src/main/java/seedu/address/logic/commands/contacts/{SelectCommand.java => AssignedCommand.java} (66%) create mode 100644 src/main/java/seedu/address/logic/commands/tasks/AssignedCommand.java rename src/main/java/seedu/address/logic/parser/contacts/{SelectCommandParser.java => AssignedCommandParser.java} (60%) create mode 100644 src/main/java/seedu/address/logic/parser/tasks/AssignedCommandParser.java create mode 100644 src/main/java/seedu/address/model/person/IsAssignedToPersonPredicate.java create mode 100644 src/main/java/seedu/address/model/task/IsAssignedToTaskPredicate.java rename src/test/java/seedu/address/logic/commands/contacts/{SelectCommandTest.java => AssignedCommandTest.java} (81%) rename src/test/java/seedu/address/logic/parser/contacts/{SelectCommandParserTest.java => AssignedCommandParserTest.java} (70%) rename src/test/java/systemtests/contacts/{SelectCommandSystemTest.java => AssignedCommandSystemTest.java} (80%) diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index b385c28130d7..abb63388b17a 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -72,12 +72,6 @@ Format: Format: `contacts find KEYWORD [MORE_KEYWORDS]` -==== Select a contact: `contacts select` - -Format: `contacts select INDEX` - -Selects the contact identified by the index number used in the displayed contact list. - ==== Delete contact: `contacts delete` Format: `contacts delete INDEX` @@ -92,7 +86,7 @@ Format: `contacts assign c/CONTACT_INDEX k/TASK_INDEX` Format: `contacts unassign c/CONTACT_INDEX k/TASK_INDEX` // end::assigntasktocontact[] -==== Show tasks assigned to contact: +==== Show tasks assigned to contact: `contacts assigned` Format: `contacts assigned CONTACT_ID` diff --git a/src/main/java/seedu/address/commons/events/ui/CalendarPanelClickEvent.java b/src/main/java/seedu/address/commons/events/ui/CalendarPanelClickEvent.java index 016ead96c441..c53c8ec29e4c 100644 --- a/src/main/java/seedu/address/commons/events/ui/CalendarPanelClickEvent.java +++ b/src/main/java/seedu/address/commons/events/ui/CalendarPanelClickEvent.java @@ -6,6 +6,7 @@ * Represents a click event in the Calendar Panel */ public class CalendarPanelClickEvent extends TaskPanelSelectionChangedEvent { + public CalendarPanelClickEvent(Task newSelection) { super(newSelection); } diff --git a/src/main/java/seedu/address/commons/events/ui/JumpToPersonListRequestEvent.java b/src/main/java/seedu/address/commons/events/ui/JumpToPersonListRequestEvent.java index 01744304a70d..96a9521517e8 100644 --- a/src/main/java/seedu/address/commons/events/ui/JumpToPersonListRequestEvent.java +++ b/src/main/java/seedu/address/commons/events/ui/JumpToPersonListRequestEvent.java @@ -18,5 +18,4 @@ public JumpToPersonListRequestEvent(Index targetIndex) { public String toString() { return getClass().getSimpleName(); } - } diff --git a/src/main/java/seedu/address/commons/events/ui/JumpToTaskListRequestEvent.java b/src/main/java/seedu/address/commons/events/ui/JumpToTaskListRequestEvent.java index 3008c5bc9186..6ce0ca21b50b 100644 --- a/src/main/java/seedu/address/commons/events/ui/JumpToTaskListRequestEvent.java +++ b/src/main/java/seedu/address/commons/events/ui/JumpToTaskListRequestEvent.java @@ -18,5 +18,4 @@ public JumpToTaskListRequestEvent(Index targetIndex) { public String toString() { return getClass().getSimpleName(); } - } diff --git a/src/main/java/seedu/address/commons/events/ui/NewResultAvailableEvent.java b/src/main/java/seedu/address/commons/events/ui/NewResultAvailableEvent.java index a5e8b2e13883..ba241886ebcb 100644 --- a/src/main/java/seedu/address/commons/events/ui/NewResultAvailableEvent.java +++ b/src/main/java/seedu/address/commons/events/ui/NewResultAvailableEvent.java @@ -17,5 +17,4 @@ public NewResultAvailableEvent(String message) { public String toString() { return getClass().getSimpleName(); } - } diff --git a/src/main/java/seedu/address/commons/events/ui/PersonPanelDeselectionEvent.java b/src/main/java/seedu/address/commons/events/ui/PersonPanelDeselectionEvent.java new file mode 100644 index 000000000000..549dc440540f --- /dev/null +++ b/src/main/java/seedu/address/commons/events/ui/PersonPanelDeselectionEvent.java @@ -0,0 +1,14 @@ +package seedu.address.commons.events.ui; + +import seedu.address.commons.events.BaseEvent; + +/** + * Represents a deselection in the Person List Panel + */ +public class PersonPanelDeselectionEvent extends BaseEvent { + + @Override + public String toString() { + return getClass().getSimpleName(); + } +} diff --git a/src/main/java/seedu/address/commons/events/ui/PersonPanelSelectionChangedEvent.java b/src/main/java/seedu/address/commons/events/ui/PersonPanelSelectionChangedEvent.java index c5c8b9ce90ed..ee97ac9fb1f4 100644 --- a/src/main/java/seedu/address/commons/events/ui/PersonPanelSelectionChangedEvent.java +++ b/src/main/java/seedu/address/commons/events/ui/PersonPanelSelectionChangedEvent.java @@ -8,7 +8,6 @@ */ public class PersonPanelSelectionChangedEvent extends BaseEvent { - private final Person newSelection; public PersonPanelSelectionChangedEvent(Person newSelection) { diff --git a/src/main/java/seedu/address/commons/events/ui/ShowHelpRequestEvent.java b/src/main/java/seedu/address/commons/events/ui/ShowHelpRequestEvent.java index 87d5c70a1b79..8f83bbf4630f 100644 --- a/src/main/java/seedu/address/commons/events/ui/ShowHelpRequestEvent.java +++ b/src/main/java/seedu/address/commons/events/ui/ShowHelpRequestEvent.java @@ -11,5 +11,4 @@ public class ShowHelpRequestEvent extends BaseEvent { public String toString() { return getClass().getSimpleName(); } - } diff --git a/src/main/java/seedu/address/commons/events/ui/TaskPanelDeselectionEvent.java b/src/main/java/seedu/address/commons/events/ui/TaskPanelDeselectionEvent.java index 49016bdd20b2..8852f617c351 100644 --- a/src/main/java/seedu/address/commons/events/ui/TaskPanelDeselectionEvent.java +++ b/src/main/java/seedu/address/commons/events/ui/TaskPanelDeselectionEvent.java @@ -6,9 +6,9 @@ * Represents a deselection in the Task List Panel */ public class TaskPanelDeselectionEvent extends BaseEvent { + @Override public String toString() { return getClass().getSimpleName(); } - } diff --git a/src/main/java/seedu/address/commons/events/ui/TaskPanelSelectionChangedEvent.java b/src/main/java/seedu/address/commons/events/ui/TaskPanelSelectionChangedEvent.java index 3f88d9d47efc..fdde4d52ade1 100644 --- a/src/main/java/seedu/address/commons/events/ui/TaskPanelSelectionChangedEvent.java +++ b/src/main/java/seedu/address/commons/events/ui/TaskPanelSelectionChangedEvent.java @@ -8,7 +8,6 @@ */ public class TaskPanelSelectionChangedEvent extends BaseEvent { - private final Task newSelection; public TaskPanelSelectionChangedEvent(Task newSelection) { @@ -23,5 +22,4 @@ public String toString() { public Task getNewSelection() { return newSelection; } - } diff --git a/src/main/java/seedu/address/logic/commands/contacts/SelectCommand.java b/src/main/java/seedu/address/logic/commands/contacts/AssignedCommand.java similarity index 66% rename from src/main/java/seedu/address/logic/commands/contacts/SelectCommand.java rename to src/main/java/seedu/address/logic/commands/contacts/AssignedCommand.java index c42f17cae6a9..5d16626fa365 100644 --- a/src/main/java/seedu/address/logic/commands/contacts/SelectCommand.java +++ b/src/main/java/seedu/address/logic/commands/contacts/AssignedCommand.java @@ -13,17 +13,20 @@ import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.person.IsAssignedToPersonPredicate; import seedu.address.model.person.Person; /** - * Selects a person identified using its displayed index from the address book. + * Selects a person identified using its displayed index, + * and the list of tasks will update to show only the tasks assigned to the person */ -public class SelectCommand extends Command { +public class AssignedCommand extends Command { - public static final String COMMAND_WORD = "select"; + public static final String COMMAND_WORD = "assigned"; public static final String MESSAGE_USAGE = getCommandFormat(COMMAND_WORD) - + ": Selects the person identified by the index number used in the displayed person list.\n" + + ": Selects the person identified by the index number used in the displayed person " + + "list and shows the list of tasks assigned to the person.\n" + "Parameters: INDEX (must be a positive integer)\n" + "Example: " + getCommandFormat(COMMAND_WORD) + " 1"; @@ -31,7 +34,7 @@ public class SelectCommand extends Command { private final Index targetIndex; - public SelectCommand(Index targetIndex) { + public AssignedCommand(Index targetIndex) { this.targetIndex = targetIndex; } @@ -44,7 +47,11 @@ public CommandResult execute(Model model, CommandHistory history) throws Command if (targetIndex.getZeroBased() >= filteredPersonList.size()) { throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } + // Retrieve the desired person and update filter + Person desiredPerson = filteredPersonList.get(targetIndex.getZeroBased()); + model.updateFilteredTaskList(new IsAssignedToPersonPredicate(desiredPerson)); + // Update UI (purely cosmetic for now) EventsCenter.getInstance().post(new JumpToPersonListRequestEvent(targetIndex)); return new CommandResult(String.format(MESSAGE_SELECT_PERSON_SUCCESS, targetIndex.getOneBased())); @@ -53,7 +60,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof SelectCommand // instanceof handles nulls - && targetIndex.equals(((SelectCommand) other).targetIndex)); // state check + || (other instanceof AssignedCommand // instanceof handles nulls + && targetIndex.equals(((AssignedCommand) other).targetIndex)); // state check } } diff --git a/src/main/java/seedu/address/logic/commands/tasks/AssignedCommand.java b/src/main/java/seedu/address/logic/commands/tasks/AssignedCommand.java new file mode 100644 index 000000000000..eef901289cac --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/tasks/AssignedCommand.java @@ -0,0 +1,66 @@ +package seedu.address.logic.commands.tasks; + +import static java.util.Objects.requireNonNull; + +import java.util.List; + +import seedu.address.commons.core.EventsCenter; +import seedu.address.commons.core.Messages; +import seedu.address.commons.core.index.Index; +import seedu.address.commons.events.ui.JumpToTaskListRequestEvent; +import seedu.address.logic.CommandHistory; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.task.IsAssignedToTaskPredicate; +import seedu.address.model.task.Task; + +/** + * Selects a task identified using its displayed index, + * and the list of persons will update to show only the persons that are assigned to the task + */ +public class AssignedCommand extends Command { + + public static final String COMMAND_WORD = "assigned"; + + public static final String MESSAGE_USAGE = getCommandFormat(COMMAND_WORD) + + ": Selects the task identified by the index number used in the displayed task " + + "list and shows the list of persons assigned to the task.\n" + + "Parameters: INDEX (must be a positive integer)\n" + + "Example: " + getCommandFormat(COMMAND_WORD) + " 1"; + + public static final String MESSAGE_SELECT_TASK_SUCCESS = "Selected Task: %1$s"; + + private final Index targetIndex; + + public AssignedCommand(Index targetIndex) { + this.targetIndex = targetIndex; + } + + @Override + public CommandResult execute(Model model, CommandHistory history) throws CommandException { + requireNonNull(model); + + List filteredTaskList = model.getFilteredTaskList(); + + if (targetIndex.getZeroBased() >= filteredTaskList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + } + // Retrieve the desired task and update filter + Task desiredTask = filteredTaskList.get(targetIndex.getZeroBased()); + model.updateFilteredPersonList(new IsAssignedToTaskPredicate(desiredTask)); + + // Update UI (purely cosmetic for now) + EventsCenter.getInstance().post(new JumpToTaskListRequestEvent(targetIndex)); + return new CommandResult(String.format(MESSAGE_SELECT_TASK_SUCCESS, targetIndex.getOneBased())); + + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof AssignedCommand // instanceof handles nulls + && targetIndex.equals(((AssignedCommand) other).targetIndex)); // state check + } +} diff --git a/src/main/java/seedu/address/logic/parser/ContactsParser.java b/src/main/java/seedu/address/logic/parser/ContactsParser.java index 5baf994d2839..1bf8e0e13a5d 100644 --- a/src/main/java/seedu/address/logic/parser/ContactsParser.java +++ b/src/main/java/seedu/address/logic/parser/ContactsParser.java @@ -10,19 +10,19 @@ import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.contacts.AddCommand; import seedu.address.logic.commands.contacts.AssignCommand; +import seedu.address.logic.commands.contacts.AssignedCommand; import seedu.address.logic.commands.contacts.ClearCommand; import seedu.address.logic.commands.contacts.DeleteCommand; import seedu.address.logic.commands.contacts.EditCommand; import seedu.address.logic.commands.contacts.FindCommand; import seedu.address.logic.commands.contacts.ListCommand; -import seedu.address.logic.commands.contacts.SelectCommand; import seedu.address.logic.commands.contacts.UnassignCommand; import seedu.address.logic.parser.contacts.AddCommandParser; import seedu.address.logic.parser.contacts.AssignCommandParser; +import seedu.address.logic.parser.contacts.AssignedCommandParser; import seedu.address.logic.parser.contacts.DeleteCommandParser; import seedu.address.logic.parser.contacts.EditCommandParser; import seedu.address.logic.parser.contacts.FindCommandParser; -import seedu.address.logic.parser.contacts.SelectCommandParser; import seedu.address.logic.parser.contacts.UnassignCommandParser; import seedu.address.logic.parser.exceptions.ParseException; @@ -62,8 +62,8 @@ public Command parseCommand(String userInput) throws ParseException { case EditCommand.COMMAND_WORD: return new EditCommandParser().parse(arguments); - case SelectCommand.COMMAND_WORD: - return new SelectCommandParser().parse(arguments); + case AssignedCommand.COMMAND_WORD: + return new AssignedCommandParser().parse(arguments); case DeleteCommand.COMMAND_WORD: return new DeleteCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/logic/parser/TasksParser.java b/src/main/java/seedu/address/logic/parser/TasksParser.java index 4a5bdcf34cda..41742e81955b 100644 --- a/src/main/java/seedu/address/logic/parser/TasksParser.java +++ b/src/main/java/seedu/address/logic/parser/TasksParser.java @@ -10,6 +10,7 @@ import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.tasks.AddCommand; import seedu.address.logic.commands.tasks.AssignCommand; +import seedu.address.logic.commands.tasks.AssignedCommand; import seedu.address.logic.commands.tasks.DeleteCommand; import seedu.address.logic.commands.tasks.EditCommand; import seedu.address.logic.commands.tasks.FindCommand; @@ -19,6 +20,7 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.logic.parser.tasks.AddCommandParser; import seedu.address.logic.parser.tasks.AssignCommandParser; +import seedu.address.logic.parser.tasks.AssignedCommandParser; import seedu.address.logic.parser.tasks.DeleteCommandParser; import seedu.address.logic.parser.tasks.EditCommandParser; import seedu.address.logic.parser.tasks.FindCommandParser; @@ -61,6 +63,9 @@ public Command parseCommand(String userInput) throws ParseException { case EditCommand.COMMAND_WORD: return new EditCommandParser().parse(arguments); + case AssignedCommand.COMMAND_WORD: + return new AssignedCommandParser().parse(arguments); + case DeleteCommand.COMMAND_WORD: return new DeleteCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/logic/parser/contacts/SelectCommandParser.java b/src/main/java/seedu/address/logic/parser/contacts/AssignedCommandParser.java similarity index 60% rename from src/main/java/seedu/address/logic/parser/contacts/SelectCommandParser.java rename to src/main/java/seedu/address/logic/parser/contacts/AssignedCommandParser.java index 845242d25219..adc1741d436b 100644 --- a/src/main/java/seedu/address/logic/parser/contacts/SelectCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/contacts/AssignedCommandParser.java @@ -3,27 +3,27 @@ import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.contacts.SelectCommand; +import seedu.address.logic.commands.contacts.AssignedCommand; import seedu.address.logic.parser.Parser; import seedu.address.logic.parser.exceptions.ParseException; /** - * Parses input arguments and creates a new SelectCommand object + * Parses input arguments and creates a new AssignedCommand object */ -public class SelectCommandParser implements Parser { +public class AssignedCommandParser implements Parser { /** - * Parses the given {@code String} of arguments in the context of the SelectCommand - * and returns an SelectCommand object for execution. + * Parses the given {@code String} of arguments in the context of the AssignedCommand + * and returns an AssignedCommand object for execution. * @throws ParseException if the user input does not conform the expected format */ - public SelectCommand parse(String args) throws ParseException { + public AssignedCommand parse(String args) throws ParseException { try { Index index = ParserUtil.parseIndex(args); - return new SelectCommand(index); + return new AssignedCommand(index); } catch (ParseException pe) { throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, SelectCommand.MESSAGE_USAGE), pe, true); + String.format(MESSAGE_INVALID_COMMAND_FORMAT, AssignedCommand.MESSAGE_USAGE), pe, true); } } } diff --git a/src/main/java/seedu/address/logic/parser/tasks/AssignedCommandParser.java b/src/main/java/seedu/address/logic/parser/tasks/AssignedCommandParser.java new file mode 100644 index 000000000000..23778f818019 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/tasks/AssignedCommandParser.java @@ -0,0 +1,30 @@ +package seedu.address.logic.parser.tasks; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.tasks.AssignedCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.contacts.ParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses input arguments and creates a new AssignedCommand object + */ +public class AssignedCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the AssignedCommand + * and returns an AssignedCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public AssignedCommand parse(String args) throws ParseException { + try { + Index index = ParserUtil.parseIndex(args); + return new AssignedCommand(index); + } catch (ParseException pe) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, AssignedCommand.MESSAGE_USAGE), pe, true); + } + } +} diff --git a/src/main/java/seedu/address/model/person/IsAssignedToPersonPredicate.java b/src/main/java/seedu/address/model/person/IsAssignedToPersonPredicate.java new file mode 100644 index 000000000000..9996d95aa98b --- /dev/null +++ b/src/main/java/seedu/address/model/person/IsAssignedToPersonPredicate.java @@ -0,0 +1,30 @@ +package seedu.address.model.person; + +import java.util.function.Predicate; + +import seedu.address.model.task.Task; + +/** + * Tests that a {@code Task} is assigned to the desired person (i.e. task contains id of {@code Person}) + */ +public class IsAssignedToPersonPredicate implements Predicate { + private final Person person; + + public IsAssignedToPersonPredicate(Person person) { + this.person = person; + } + + @Override + public boolean test(Task task) { + return task.getPersonIds().stream() + .anyMatch(personId -> person.getId().equals(personId)); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof IsAssignedToPersonPredicate // instanceof handles nulls + && person.equals(((IsAssignedToPersonPredicate) other).person)); // state check + } + +} diff --git a/src/main/java/seedu/address/model/task/IsAssignedToTaskPredicate.java b/src/main/java/seedu/address/model/task/IsAssignedToTaskPredicate.java new file mode 100644 index 000000000000..d0036c472852 --- /dev/null +++ b/src/main/java/seedu/address/model/task/IsAssignedToTaskPredicate.java @@ -0,0 +1,30 @@ +package seedu.address.model.task; + +import java.util.function.Predicate; + +import seedu.address.model.person.Person; + +/** + * Tests that a {@code Person} is assigned to the desired task (i.e. person contains id of {@code Task}) + */ +public class IsAssignedToTaskPredicate implements Predicate { + private final Task task; + + public IsAssignedToTaskPredicate(Task task) { + this.task = task; + } + + @Override + public boolean test(Person person) { + return person.getTaskIds().stream() + .anyMatch(taskId -> task.getId().equals(taskId)); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof IsAssignedToTaskPredicate // instanceof handles nulls + && task.equals(((IsAssignedToTaskPredicate) other).task)); // state check + } + +} diff --git a/src/main/java/seedu/address/ui/PersonListPanel.java b/src/main/java/seedu/address/ui/PersonListPanel.java index 9a4401ba0a99..c6bb33d98867 100644 --- a/src/main/java/seedu/address/ui/PersonListPanel.java +++ b/src/main/java/seedu/address/ui/PersonListPanel.java @@ -12,6 +12,7 @@ import javafx.scene.layout.Region; import seedu.address.commons.core.LogsCenter; import seedu.address.commons.events.ui.JumpToPersonListRequestEvent; +import seedu.address.commons.events.ui.PersonPanelDeselectionEvent; import seedu.address.commons.events.ui.PersonPanelSelectionChangedEvent; import seedu.address.model.person.Person; @@ -43,6 +44,10 @@ private void setEventHandlerForSelectionChangeEvent() { if (newValue != null) { logger.fine("Selection in person list panel changed to : '" + newValue + "'"); raise(new PersonPanelSelectionChangedEvent(newValue)); + + } else { + logger.fine("Person list panel is deselected"); + raise(new PersonPanelDeselectionEvent()); } }); } diff --git a/src/test/java/seedu/address/logic/commands/contacts/SelectCommandTest.java b/src/test/java/seedu/address/logic/commands/contacts/AssignedCommandTest.java similarity index 81% rename from src/test/java/seedu/address/logic/commands/contacts/SelectCommandTest.java rename to src/test/java/seedu/address/logic/commands/contacts/AssignedCommandTest.java index e18c4da89c21..48307d014e8c 100644 --- a/src/test/java/seedu/address/logic/commands/contacts/SelectCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/contacts/AssignedCommandTest.java @@ -24,9 +24,9 @@ import seedu.address.ui.testutil.EventsCollectorRule; /** - * Contains integration tests (interaction with the Model) for {@code SelectCommand}. + * Contains integration tests (interaction with the Model) for {@code AssignedCommand}. */ -public class SelectCommandTest { +public class AssignedCommandTest { @Rule public final EventsCollectorRule eventsCollectorRule = new EventsCollectorRule(); @@ -72,14 +72,14 @@ public void execute_invalidIndexFilteredList_failure() { @Test public void equals() { - SelectCommand selectFirstCommand = new SelectCommand(INDEX_FIRST_PERSON); - SelectCommand selectSecondCommand = new SelectCommand(INDEX_SECOND_PERSON); + AssignedCommand selectFirstCommand = new AssignedCommand(INDEX_FIRST_PERSON); + AssignedCommand selectSecondCommand = new AssignedCommand(INDEX_SECOND_PERSON); // same object -> returns true assertTrue(selectFirstCommand.equals(selectFirstCommand)); // same values -> returns true - SelectCommand selectFirstCommandCopy = new SelectCommand(INDEX_FIRST_PERSON); + AssignedCommand selectFirstCommandCopy = new AssignedCommand(INDEX_FIRST_PERSON); assertTrue(selectFirstCommand.equals(selectFirstCommandCopy)); // different types -> returns false @@ -93,15 +93,15 @@ public void equals() { } /** - * Executes a {@code SelectCommand} with the given {@code index}, + * Executes a {@code AssignedCommand} with the given {@code index}, * and checks that {@code JumpToPersonListRequestEvent} * is raised with the correct index. */ private void assertExecutionSuccess(Index index) { - SelectCommand selectCommand = new SelectCommand(index); - String expectedMessage = String.format(SelectCommand.MESSAGE_SELECT_PERSON_SUCCESS, index.getOneBased()); + AssignedCommand assignedCommand = new AssignedCommand(index); + String expectedMessage = String.format(AssignedCommand.MESSAGE_SELECT_PERSON_SUCCESS, index.getOneBased()); - assertCommandSuccess(selectCommand, model, commandHistory, expectedMessage, expectedModel); + assertCommandSuccess(assignedCommand, model, commandHistory, expectedMessage, expectedModel); JumpToPersonListRequestEvent lastEvent = (JumpToPersonListRequestEvent) eventsCollectorRule.eventsCollector .getMostRecent(); @@ -109,12 +109,12 @@ private void assertExecutionSuccess(Index index) { } /** - * Executes a {@code SelectCommand} with the given {@code index}, and checks that a {@code CommandException} + * Executes a {@code AssignedCommand} with the given {@code index}, and checks that a {@code CommandException} * is thrown with the {@code expectedMessage}. */ private void assertExecutionFailure(Index index, String expectedMessage) { - SelectCommand selectCommand = new SelectCommand(index); - assertCommandFailure(selectCommand, model, commandHistory, expectedMessage); + AssignedCommand assignedCommand = new AssignedCommand(index); + assertCommandFailure(assignedCommand, model, commandHistory, expectedMessage); assertTrue(eventsCollectorRule.eventsCollector.isEmpty()); } } diff --git a/src/test/java/seedu/address/logic/parser/ContactsParserTest.java b/src/test/java/seedu/address/logic/parser/ContactsParserTest.java index 128a3138095f..2a08b43a71f2 100644 --- a/src/test/java/seedu/address/logic/parser/ContactsParserTest.java +++ b/src/test/java/seedu/address/logic/parser/ContactsParserTest.java @@ -16,13 +16,13 @@ import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.contacts.AddCommand; +import seedu.address.logic.commands.contacts.AssignedCommand; import seedu.address.logic.commands.contacts.ClearCommand; import seedu.address.logic.commands.contacts.DeleteCommand; import seedu.address.logic.commands.contacts.EditCommand; import seedu.address.logic.commands.contacts.EditCommand.EditPersonDescriptor; import seedu.address.logic.commands.contacts.FindCommand; import seedu.address.logic.commands.contacts.ListCommand; -import seedu.address.logic.commands.contacts.SelectCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; @@ -81,10 +81,10 @@ public void parseCommand_list() throws Exception { } @Test - public void parseCommand_select() throws Exception { - SelectCommand command = (SelectCommand) parser.parseCommand( - SelectCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased()); - assertEquals(new SelectCommand(INDEX_FIRST_PERSON), command); + public void parseCommand_assigned() throws Exception { + AssignedCommand command = (AssignedCommand) parser.parseCommand( + AssignedCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased()); + assertEquals(new AssignedCommand(INDEX_FIRST_PERSON), command); } @Test diff --git a/src/test/java/seedu/address/logic/parser/contacts/SelectCommandParserTest.java b/src/test/java/seedu/address/logic/parser/contacts/AssignedCommandParserTest.java similarity index 70% rename from src/test/java/seedu/address/logic/parser/contacts/SelectCommandParserTest.java rename to src/test/java/seedu/address/logic/parser/contacts/AssignedCommandParserTest.java index f47b229a5e48..a6978a39d4ac 100644 --- a/src/test/java/seedu/address/logic/parser/contacts/SelectCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/contacts/AssignedCommandParserTest.java @@ -7,24 +7,24 @@ import org.junit.Test; -import seedu.address.logic.commands.contacts.SelectCommand; +import seedu.address.logic.commands.contacts.AssignedCommand; /** * Test scope: similar to {@code DeleteCommandParserTest}. * @see DeleteCommandParserTest */ -public class SelectCommandParserTest { +public class AssignedCommandParserTest { - private SelectCommandParser parser = new SelectCommandParser(); + private AssignedCommandParser parser = new AssignedCommandParser(); @Test public void parse_validArgs_returnsSelectCommand() { - assertParseSuccess(parser, "1", new SelectCommand(INDEX_FIRST_PERSON)); + assertParseSuccess(parser, "1", new AssignedCommand(INDEX_FIRST_PERSON)); } @Test public void parse_invalidArgs_throwsParseException() { assertParseFailure(parser, "a", - String.format(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SelectCommand.MESSAGE_USAGE), "")); + String.format(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AssignedCommand.MESSAGE_USAGE), "")); } } diff --git a/src/test/java/systemtests/HelpCommandSystemTest.java b/src/test/java/systemtests/HelpCommandSystemTest.java index ceb05e416100..1c2a70933611 100644 --- a/src/test/java/systemtests/HelpCommandSystemTest.java +++ b/src/test/java/systemtests/HelpCommandSystemTest.java @@ -13,8 +13,8 @@ import guitests.GuiRobot; import guitests.guihandles.HelpWindowHandle; import seedu.address.logic.commands.HelpCommand; +import seedu.address.logic.commands.contacts.AssignedCommand; import seedu.address.logic.commands.contacts.DeleteCommand; -import seedu.address.logic.commands.contacts.SelectCommand; import seedu.address.ui.StatusBarFooter; /** @@ -56,7 +56,7 @@ public void openHelpWindow() { getMainWindowHandle().focus(); // assert that while the help window is open the UI updates correctly for a command execution - executeCommand(MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased()); + executeCommand(MODULE_WORD + " " + AssignedCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased()); assertEquals("", getCommandBox().getInput()); assertCommandBoxShowsDefaultStyle(); assertNotEquals(HelpCommand.SHOWING_HELP_MESSAGE, getResultDisplay().getText()); diff --git a/src/test/java/systemtests/contacts/SelectCommandSystemTest.java b/src/test/java/systemtests/contacts/AssignedCommandSystemTest.java similarity index 80% rename from src/test/java/systemtests/contacts/SelectCommandSystemTest.java rename to src/test/java/systemtests/contacts/AssignedCommandSystemTest.java index 8e0cb5cae028..7a55e385cc5d 100644 --- a/src/test/java/systemtests/contacts/SelectCommandSystemTest.java +++ b/src/test/java/systemtests/contacts/AssignedCommandSystemTest.java @@ -4,7 +4,7 @@ import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; -import static seedu.address.logic.commands.contacts.SelectCommand.MESSAGE_SELECT_PERSON_SUCCESS; +import static seedu.address.logic.commands.contacts.AssignedCommand.MESSAGE_SELECT_PERSON_SUCCESS; import static seedu.address.logic.parser.ContactsParser.MODULE_WORD; import static seedu.address.testutil.TestUtil.getLastIndex; import static seedu.address.testutil.TestUtil.getMidIndex; @@ -16,11 +16,11 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.RedoCommand; import seedu.address.logic.commands.UndoCommand; -import seedu.address.logic.commands.contacts.SelectCommand; +import seedu.address.logic.commands.contacts.AssignedCommand; import seedu.address.model.Model; import systemtests.AppSystemTest; -public class SelectCommandSystemTest extends ContactsSystemTest { +public class AssignedCommandSystemTest extends ContactsSystemTest { @Test public void select() { /* ------------------------ Perform select operations on the shown unfiltered list -------------------------- */ @@ -28,13 +28,13 @@ public void select() { /* Case: select the first card in the person list, command with leading spaces and trailing spaces * -> selected */ - String command = " " + MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " " + String command = " " + MODULE_WORD + " " + AssignedCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased() + " "; assertCommandSuccess(command, INDEX_FIRST_PERSON); /* Case: select the last card in the person list -> selected */ Index personCount = getLastIndex(getModel()); - command = MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " " + personCount.getOneBased(); + command = MODULE_WORD + " " + AssignedCommand.COMMAND_WORD + " " + personCount.getOneBased(); assertCommandSuccess(command, personCount); /* Case: undo previous selection -> rejected */ @@ -49,7 +49,7 @@ public void select() { /* Case: select the middle card in the person list -> selected */ Index middleIndex = getMidIndex(getModel()); - command = MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " " + middleIndex.getOneBased(); + command = MODULE_WORD + " " + AssignedCommand.COMMAND_WORD + " " + middleIndex.getOneBased(); assertCommandSuccess(command, middleIndex); /* Case: select the current selected card -> selected */ @@ -62,44 +62,49 @@ public void select() { */ showPersonsWithName(KEYWORD_MATCHING_MEIER); int invalidIndex = getModel().getAddressBook().getPersonList().size(); - assertCommandFailure(MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " " + invalidIndex, + assertCommandFailure(MODULE_WORD + " " + AssignedCommand.COMMAND_WORD + " " + invalidIndex, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); /* Case: filtered person list, select index within bounds of address book and person list -> selected */ Index validIndex = Index.fromOneBased(1); assertTrue(validIndex.getZeroBased() < getModel().getFilteredPersonList().size()); - command = MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " " + validIndex.getOneBased(); + command = MODULE_WORD + " " + AssignedCommand.COMMAND_WORD + " " + validIndex.getOneBased(); assertCommandSuccess(command, validIndex); /* ----------------------------------- Perform invalid select operations ------------------------------------ */ /* Case: invalid index (0) -> rejected */ - assertCommandFailure(MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " " + 0, - String.format(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SelectCommand.MESSAGE_USAGE), MODULE_WORD)); + assertCommandFailure(MODULE_WORD + " " + AssignedCommand.COMMAND_WORD + " " + 0, + String.format(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + AssignedCommand.MESSAGE_USAGE), MODULE_WORD)); /* Case: invalid index (-1) -> rejected */ - assertCommandFailure(MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " " + -1, - String.format(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SelectCommand.MESSAGE_USAGE), MODULE_WORD)); + assertCommandFailure(MODULE_WORD + " " + AssignedCommand.COMMAND_WORD + " " + -1, + String.format(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + AssignedCommand.MESSAGE_USAGE), MODULE_WORD)); /* Case: invalid index (size + 1) -> rejected */ invalidIndex = getModel().getFilteredPersonList().size() + 1; - assertCommandFailure(MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " " + invalidIndex, + assertCommandFailure(MODULE_WORD + " " + AssignedCommand.COMMAND_WORD + " " + invalidIndex, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); /* Case: invalid arguments (alphabets) -> rejected */ - assertCommandFailure(MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " abc", - String.format(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SelectCommand.MESSAGE_USAGE), MODULE_WORD)); + assertCommandFailure(MODULE_WORD + " " + AssignedCommand.COMMAND_WORD + " abc", + String.format(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + AssignedCommand.MESSAGE_USAGE), MODULE_WORD)); /* Case: invalid arguments (extra argument) -> rejected */ - assertCommandFailure(MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " 1 abc", - String.format(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SelectCommand.MESSAGE_USAGE), MODULE_WORD)); + assertCommandFailure(MODULE_WORD + " " + AssignedCommand.COMMAND_WORD + " 1 abc", + String.format(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + AssignedCommand.MESSAGE_USAGE), MODULE_WORD)); /* Case: mixed case command word -> rejected */ assertCommandFailure(MODULE_WORD + " " + "SeLeCt 1", MESSAGE_UNKNOWN_COMMAND); /* Case: select from empty address book -> rejected */ deleteAllPersons(); - assertCommandFailure(MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased(), + assertCommandFailure(MODULE_WORD + " " + + AssignedCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased(), MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } @@ -114,6 +119,7 @@ public void select() { * 6. Status bar remains unchanged.
* Verifications 1, 3 and 4 are performed by * {@code AppSystemTest#assertApplicationDisplaysExpected(String, String, Model)}.
+ * * @see AppSystemTest#assertApplicationDisplaysExpected(String, String, Model) * @see AppSystemTest#assertSelectedCardChanged(Index) */ @@ -145,6 +151,7 @@ private void assertCommandSuccess(String command, Index expectedSelectedCardInde * 5. Browser url, selected card and status bar remain unchanged.
* Verifications 1, 3 and 4 are performed by * {@code AppSystemTest#assertApplicationDisplaysExpected(String, String, Model)}.
+ * * @see AppSystemTest#assertApplicationDisplaysExpected(String, String, Model) */ private void assertCommandFailure(String command, String expectedResultMessage) { diff --git a/src/test/java/systemtests/contacts/ContactsSystemTest.java b/src/test/java/systemtests/contacts/ContactsSystemTest.java index b8bf735337ae..9a4ca1978eb2 100644 --- a/src/test/java/systemtests/contacts/ContactsSystemTest.java +++ b/src/test/java/systemtests/contacts/ContactsSystemTest.java @@ -5,10 +5,10 @@ import static seedu.address.logic.parser.ContactsParser.MODULE_WORD; import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.contacts.AssignedCommand; import seedu.address.logic.commands.contacts.ClearCommand; import seedu.address.logic.commands.contacts.FindCommand; import seedu.address.logic.commands.contacts.ListCommand; -import seedu.address.logic.commands.contacts.SelectCommand; import systemtests.AppSystemTest; /** @@ -35,7 +35,7 @@ protected void showPersonsWithName(String keyword) { * Selects the person at {@code index} of the displayed list. */ protected void selectPerson(Index index) { - executeCommand(MODULE_WORD + " " + SelectCommand.COMMAND_WORD + " " + index.getOneBased()); + executeCommand(MODULE_WORD + " " + AssignedCommand.COMMAND_WORD + " " + index.getOneBased()); assertEquals(index.getZeroBased(), getPersonListPanel().getSelectedCardIndex()); }