forked from nus-cs2103-AY1920S1/addressbook-level3
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into active-participants
- Loading branch information
Showing
52 changed files
with
908 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package seedu.address.logic; | ||
|
||
/** | ||
* Represents the different command sub-types for GUI-related commands. | ||
*/ | ||
public enum CommandSubType { | ||
ACTIVITY, | ||
CONTACT | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 43 additions & 6 deletions
49
src/main/java/seedu/address/logic/commands/ListCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,61 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ACTIVITY; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_CONTACT; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_ENTRIES; | ||
|
||
import seedu.address.logic.CommandSubType; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Context; | ||
import seedu.address.model.ContextType; | ||
import seedu.address.model.Model; | ||
|
||
/** | ||
* Lists all persons in the address book to the user. | ||
* Updates the GUI to list all entries of a specified type to the user. | ||
*/ | ||
public class ListCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "list"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Listed all persons"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Switches the current view to list all contacts or activities. " | ||
+ "If an argument is supplied with a parameter, it is ignored.\n" | ||
+ "Parameters: " + PREFIX_CONTACT + " OR " + PREFIX_ACTIVITY + "\n" | ||
+ "Example: list " + PREFIX_CONTACT; | ||
|
||
public static final String MESSAGE_SUCCESS = "Listed all %s"; | ||
public static final String MESSAGE_UNKNOWN_LIST_TYPE = "List command has unknown type!"; | ||
|
||
private final CommandSubType type; | ||
|
||
public ListCommand(CommandSubType type) { | ||
requireNonNull(type); | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
|
||
switch (this.type) { | ||
case CONTACT: | ||
model.setContext(Context.newListContactContext()); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_ENTRIES); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, "contacts"), ContextType.LIST_CONTACT); | ||
case ACTIVITY: | ||
model.setContext(Context.newListActivityContext()); | ||
model.updateFilteredActivityList(PREDICATE_SHOW_ALL_ENTRIES); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, "activities"), ContextType.LIST_ACTIVITY); | ||
default: | ||
throw new CommandException(MESSAGE_UNKNOWN_LIST_TYPE); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ListCommand // instanceof handles nulls | ||
&& type.equals(((ListCommand) other).type)); // state check | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.