diff --git a/src/main/java/seedu/savvytasker/MainApp.java b/src/main/java/seedu/savvytasker/MainApp.java index 27a6d1770070..342007930dea 100644 --- a/src/main/java/seedu/savvytasker/MainApp.java +++ b/src/main/java/seedu/savvytasker/MainApp.java @@ -69,14 +69,6 @@ public void init() throws Exception { initEventsCenter(); } - - public static Ui getUiManager() { - if (instance != null) { - return instance.ui; - } else { - return null; - } - } private String getApplicationParameter(String parameterName){ Map applicationParameters = getParameters().getNamed(); diff --git a/src/main/java/seedu/savvytasker/commons/core/Messages.java b/src/main/java/seedu/savvytasker/commons/core/Messages.java index 134dcd37d6b9..bb130b8ebb7e 100644 --- a/src/main/java/seedu/savvytasker/commons/core/Messages.java +++ b/src/main/java/seedu/savvytasker/commons/core/Messages.java @@ -9,6 +9,7 @@ public class Messages { public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; public static final String MESSAGE_INVALID_TASK_DISPLAYED_INDEX = "The task index provided is invalid"; public static final String MESSAGE_TASKS_LISTED_OVERVIEW = "%1$d tasks listed!"; + public static final String MESSAGE_ALIASES_LISTED_OVERVIEW = "%1$d aliases listed!"; public static final String MESSAGE_INVALID_START_END = "The end time cannot be earlier than the start time"; } diff --git a/src/main/java/seedu/savvytasker/commons/events/ui/ChangeListRequestEvent.java b/src/main/java/seedu/savvytasker/commons/events/ui/ChangeListRequestEvent.java new file mode 100644 index 000000000000..8f1f4f7fef28 --- /dev/null +++ b/src/main/java/seedu/savvytasker/commons/events/ui/ChangeListRequestEvent.java @@ -0,0 +1,26 @@ +package seedu.savvytasker.commons.events.ui; + +import seedu.savvytasker.commons.events.BaseEvent; + +/** + * Indicates a request to jump to the list of tasks + */ +public class ChangeListRequestEvent extends BaseEvent { + + public enum DisplayedList { + Task, + Alias + } + + public final DisplayedList displayedList; + + public ChangeListRequestEvent(DisplayedList displayedList) { + this.displayedList = displayedList; + } + + @Override + public String toString() { + return this.getClass().getSimpleName(); + } + +} diff --git a/src/main/java/seedu/savvytasker/logic/LogicManager.java b/src/main/java/seedu/savvytasker/logic/LogicManager.java index 1a8f140f9125..1a48c53d1dda 100644 --- a/src/main/java/seedu/savvytasker/logic/LogicManager.java +++ b/src/main/java/seedu/savvytasker/logic/LogicManager.java @@ -9,8 +9,11 @@ import javafx.collections.ObservableList; import seedu.savvytasker.MainApp; import seedu.savvytasker.commons.core.ComponentManager; +import seedu.savvytasker.commons.core.EventsCenter; import seedu.savvytasker.commons.core.LogsCenter; import seedu.savvytasker.commons.events.model.AliasSymbolChangedEvent; +import seedu.savvytasker.commons.events.ui.ChangeListRequestEvent; +import seedu.savvytasker.commons.events.ui.ChangeListRequestEvent.DisplayedList; import seedu.savvytasker.logic.commands.Command; import seedu.savvytasker.logic.commands.CommandResult; import seedu.savvytasker.logic.commands.ListCommand; @@ -67,10 +70,7 @@ public CommandResult execute(String commandText) { if (!(command instanceof ListCommand)) { // forcefully show the task list instead - Ui uiManager = MainApp.getUiManager(); - if (uiManager != null) { - uiManager.showTaskList(true); - } + EventsCenter.getInstance().post(new ChangeListRequestEvent(DisplayedList.Task)); } //@@author A0097627N diff --git a/src/main/java/seedu/savvytasker/logic/commands/Command.java b/src/main/java/seedu/savvytasker/logic/commands/Command.java index 9ef43c3dc2fa..d93369958660 100644 --- a/src/main/java/seedu/savvytasker/logic/commands/Command.java +++ b/src/main/java/seedu/savvytasker/logic/commands/Command.java @@ -19,6 +19,15 @@ public abstract class Command { public static String getMessageForTaskListShownSummary(int displaySize) { return String.format(Messages.MESSAGE_TASKS_LISTED_OVERVIEW, displaySize); } + /** + * Constructs a feedback message to summarise an operation that displayed a listing of aliases. + * + * @param displaySize used to generate summary + * @return summary message for tasks displayed + */ + public static String getMessageForAliasListShownSummary(int displaySize) { + return String.format(Messages.MESSAGE_ALIASES_LISTED_OVERVIEW, displaySize); + } /** * Executes the command and returns the result message. diff --git a/src/main/java/seedu/savvytasker/logic/commands/ListCommand.java b/src/main/java/seedu/savvytasker/logic/commands/ListCommand.java index e695f0273cfc..f8c39d9032af 100644 --- a/src/main/java/seedu/savvytasker/logic/commands/ListCommand.java +++ b/src/main/java/seedu/savvytasker/logic/commands/ListCommand.java @@ -1,6 +1,8 @@ package seedu.savvytasker.logic.commands; -import seedu.savvytasker.MainApp; +import seedu.savvytasker.commons.core.EventsCenter; +import seedu.savvytasker.commons.events.ui.ChangeListRequestEvent; +import seedu.savvytasker.commons.events.ui.ChangeListRequestEvent.DisplayedList; import seedu.savvytasker.model.ListType; /** @@ -39,7 +41,6 @@ public CommandResult execute() { // shows the task list by default, unless user // specifies to show the alias - MainApp.getUiManager().showTaskList(true); switch (_listType) { case DueDate: @@ -52,13 +53,18 @@ public CommandResult execute() { model.updateFilteredListToShowArchived(); break; case Alias: - MainApp.getUiManager().showTaskList(false); + EventsCenter.getInstance().post(new ChangeListRequestEvent(DisplayedList.Alias)); break; default: // nothing to do break; } - return new CommandResult(getMessageForTaskListShownSummary(model.getFilteredTaskList().size())); + if (_listType != ListType.Alias) { + EventsCenter.getInstance().post(new ChangeListRequestEvent(DisplayedList.Task)); + return new CommandResult(getMessageForTaskListShownSummary(model.getFilteredTaskList().size())); + } else { + return new CommandResult(getMessageForAliasListShownSummary(model.getAliasSymbolCount())); + } } //@@author diff --git a/src/main/java/seedu/savvytasker/model/Model.java b/src/main/java/seedu/savvytasker/model/Model.java index 4702191da93c..4b081eb8ba34 100644 --- a/src/main/java/seedu/savvytasker/model/Model.java +++ b/src/main/java/seedu/savvytasker/model/Model.java @@ -77,4 +77,7 @@ public interface Model { /** Removes an the given AliasSymbol. */ void removeAliasSymbol(AliasSymbol symbol) throws SymbolKeywordNotFoundException; + + /** Gets the number of aliases */ + int getAliasSymbolCount(); } diff --git a/src/main/java/seedu/savvytasker/model/ModelManager.java b/src/main/java/seedu/savvytasker/model/ModelManager.java index 129c4c6a53c9..1551a6608316 100644 --- a/src/main/java/seedu/savvytasker/model/ModelManager.java +++ b/src/main/java/seedu/savvytasker/model/ModelManager.java @@ -139,6 +139,11 @@ public synchronized void removeAliasSymbol(AliasSymbol symbol) throws SymbolKeyw indicateSavvyTaskerChanged(); indicateAliasSymbolRemoved(symbol); } + + @Override + public int getAliasSymbolCount() { + return savvyTasker.getAliasSymbolCount(); + } //@@author //=========== Filtered/Sorted Task List Accessors =============================================================== diff --git a/src/main/java/seedu/savvytasker/model/SavvyTasker.java b/src/main/java/seedu/savvytasker/model/SavvyTasker.java index 22d8d8774758..7b32afb8635f 100644 --- a/src/main/java/seedu/savvytasker/model/SavvyTasker.java +++ b/src/main/java/seedu/savvytasker/model/SavvyTasker.java @@ -252,6 +252,10 @@ public void removeAliasSymbol(AliasSymbol symbol) throws SymbolKeywordNotFoundEx } //@@author + public int getAliasSymbolCount() { + return symbols.size(); + } + //// util methods @Override diff --git a/src/main/java/seedu/savvytasker/ui/Ui.java b/src/main/java/seedu/savvytasker/ui/Ui.java index ca25ec24cafe..73319c96daf2 100644 --- a/src/main/java/seedu/savvytasker/ui/Ui.java +++ b/src/main/java/seedu/savvytasker/ui/Ui.java @@ -12,8 +12,5 @@ public interface Ui { /** Stops the UI. */ void stop(); - - /** Shows/Hides the task list */ - void showTaskList(boolean isShown); } diff --git a/src/main/java/seedu/savvytasker/ui/UiManager.java b/src/main/java/seedu/savvytasker/ui/UiManager.java index 07ef44c25208..f5b5835b2868 100644 --- a/src/main/java/seedu/savvytasker/ui/UiManager.java +++ b/src/main/java/seedu/savvytasker/ui/UiManager.java @@ -14,6 +14,8 @@ import seedu.savvytasker.commons.core.Config; import seedu.savvytasker.commons.core.LogsCenter; import seedu.savvytasker.commons.events.storage.DataSavingExceptionEvent; +import seedu.savvytasker.commons.events.ui.ChangeListRequestEvent; +import seedu.savvytasker.commons.events.ui.ChangeListRequestEvent.DisplayedList; import seedu.savvytasker.commons.events.ui.JumpToListRequestEvent; import seedu.savvytasker.commons.events.ui.ShowHelpRequestEvent; import seedu.savvytasker.commons.events.ui.TaskPanelSelectionChangedEvent; @@ -65,11 +67,6 @@ public void stop() { mainWindow.hide(); mainWindow.releaseResources(); } - - @Override - public void showTaskList(boolean isShown) { - mainWindow.showTaskList(isShown); - } private void showFileOperationAlertAndWait(String description, String details, Throwable cause) { final String content = details + ":\n" + cause.toString(); @@ -117,6 +114,16 @@ private void handleShowHelpEvent(ShowHelpRequestEvent event) { mainWindow.handleHelp(); } + @Subscribe + private void handleChangeListRequestEvent(ChangeListRequestEvent event) { + logger.info(LogsCenter.getEventHandlingLogMessage(event)); + if (event.displayedList == DisplayedList.Task) { + mainWindow.showTaskList(true); + } else { + mainWindow.showTaskList(false); + } + } + @Subscribe private void handleJumpToListRequestEvent(JumpToListRequestEvent event) { logger.info(LogsCenter.getEventHandlingLogMessage(event));