Skip to content

Commit

Permalink
Removed coupling with UI. Used event driven model to trigger UI changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
qhng committed Nov 2, 2016
1 parent 87734d8 commit cac7f0a
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 24 deletions.
8 changes: 0 additions & 8 deletions src/main/java/seedu/savvytasker/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> applicationParameters = getParameters().getNamed();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/savvytasker/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

}
Original file line number Diff line number Diff line change
@@ -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();
}

}
8 changes: 4 additions & 4 deletions src/main/java/seedu/savvytasker/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/seedu/savvytasker/logic/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/seedu/savvytasker/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/savvytasker/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
5 changes: 5 additions & 0 deletions src/main/java/seedu/savvytasker/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===============================================================
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/savvytasker/model/SavvyTasker.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ public void removeAliasSymbol(AliasSymbol symbol) throws SymbolKeywordNotFoundEx
}
//@@author

public int getAliasSymbolCount() {
return symbols.size();
}

//// util methods

@Override
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/seedu/savvytasker/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@ public interface Ui {

/** Stops the UI. */
void stop();

/** Shows/Hides the task list */
void showTaskList(boolean isShown);

}
17 changes: 12 additions & 5 deletions src/main/java/seedu/savvytasker/ui/UiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit cac7f0a

Please sign in to comment.