Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ui #121

Merged
merged 13 commits into from Oct 29, 2019
Expand Up @@ -15,6 +15,7 @@
import seedu.exercise.logic.commands.exceptions.CommandException;
import seedu.exercise.model.Model;
import seedu.exercise.model.resource.Exercise;
import seedu.exercise.ui.ListResourceType;

/**
* Adds an exercise to the exercise book.
Expand Down Expand Up @@ -65,7 +66,7 @@ public CommandResult execute(Model model) throws CommandException {
model.updateStatistic();
eventPayload.put(KEY_EXERCISE_TO_ADD, exerciseToAdd);
EventHistory.getInstance().addCommandToUndoStack(this);
return new CommandResult(String.format(MESSAGE_SUCCESS, exerciseToAdd));
return new CommandResult(String.format(MESSAGE_SUCCESS, exerciseToAdd), ListResourceType.EXERCISE);
}

@Override
Expand Down
Expand Up @@ -23,6 +23,7 @@
import seedu.exercise.model.property.Name;
import seedu.exercise.model.resource.Exercise;
import seedu.exercise.model.resource.Regime;
import seedu.exercise.ui.ListResourceType;

/**
* Adds a regime to the regime book.
Expand Down Expand Up @@ -86,7 +87,7 @@ private CommandResult addNewRegimeToModel(Model model) throws CommandException {
addExercisesToRegime(regime, model);
model.addRegime(regime);
addToEventPayloadForAddRegime(regime);
return new CommandResult(MESSAGE_SUCCESS_NEW_REGIME);
return new CommandResult(MESSAGE_SUCCESS_NEW_REGIME, ListResourceType.REGIME);
}

/**
Expand All @@ -104,7 +105,7 @@ private CommandResult addExercisesToExistingRegime(Model model) throws CommandEx

model.setRegime(originalRegime, editedRegime);
model.updateFilteredRegimeList(Model.PREDICATE_SHOW_ALL_REGIMES);
return new CommandResult(MESSAGE_SUCCESS_ADD_EXERCISE_TO_REGIME);
return new CommandResult(MESSAGE_SUCCESS_ADD_EXERCISE_TO_REGIME, ListResourceType.REGIME);
}

/**
Expand Down
Expand Up @@ -8,6 +8,7 @@
import seedu.exercise.model.Model;
import seedu.exercise.model.ReadOnlyResourceBook;
import seedu.exercise.model.resource.Exercise;
import seedu.exercise.ui.ListResourceType;

/**
* Clears the exercise book.
Expand All @@ -27,7 +28,7 @@ public CommandResult execute(Model model) {
eventPayload.put(KEY_EXERCISE_BOOK_CLEARED, exerciseBookCleared);
EventHistory.getInstance().addCommandToUndoStack(this);
model.setExerciseBook(new ReadOnlyResourceBook<>());
return new CommandResult(MESSAGE_SUCCESS);
return new CommandResult(MESSAGE_SUCCESS, ListResourceType.SUGGESTION);
}

@Override
Expand Down
44 changes: 36 additions & 8 deletions src/main/java/seedu/exercise/logic/commands/CommandResult.java
Expand Up @@ -4,6 +4,8 @@

import java.util.Objects;

import seedu.exercise.ui.ListResourceType;

/**
* Represents the result of a command execution.
*/
Expand All @@ -14,36 +16,57 @@ public class CommandResult {
/**
* Help information should be shown to the user.
*/
private final boolean showHelp;
private boolean showHelp;

/**
* The application should exit.
*/
private final boolean exit;
private boolean exit;

kwekke marked this conversation as resolved.
Show resolved Hide resolved
/**
* Show the resolve window to user due to scheduling conflict
*/
private final boolean showResolve;
private boolean showResolve;

/**
* The type of resource to be shown in the GUI.
*/
private ListResourceType showListResourceType;

/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit, boolean showResolve) {
public CommandResult(String feedbackToUser, boolean showHelp,
boolean isExit, boolean showResolve, ListResourceType listResourceType) {
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
this.exit = isExit;
this.showResolve = showResolve;
this.showListResourceType = listResourceType;
}

/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit, boolean showResolve) {
this(feedbackToUser, showHelp, exit, showResolve, ListResourceType.NULL);
}

public CommandResult(String feedbackToUser, ListResourceType listResourceType) {
this(feedbackToUser);
this.showListResourceType = listResourceType;
}

/**
* Constructs a {@code CommandResult} with the specified {@code feedbackToUser},
* and other fields set to their default value.
*/
public CommandResult(String feedbackToUser) {
this(feedbackToUser, false, false, false);
this(feedbackToUser, false, false, false, ListResourceType.NULL);
}



public String getFeedbackToUser() {
return feedbackToUser;
}
Expand All @@ -60,6 +83,10 @@ public boolean isShowResolve() {
return showResolve;
}

public ListResourceType getShowListResourceType() {
return showListResourceType;
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -75,12 +102,13 @@ public boolean equals(Object other) {
return feedbackToUser.equals(otherCommandResult.feedbackToUser)
&& showHelp == otherCommandResult.showHelp
&& exit == otherCommandResult.exit
&& showResolve == otherCommandResult.showResolve;
&& showResolve == otherCommandResult.showResolve
&& showListResourceType.equals(otherCommandResult.showListResourceType);
}

@Override
public int hashCode() {
return Objects.hash(feedbackToUser, showHelp, exit, showResolve);
return Objects.hash(feedbackToUser, showHelp, exit, showResolve, showListResourceType);
}

}
Expand Up @@ -13,6 +13,7 @@
import seedu.exercise.logic.commands.exceptions.CommandException;
import seedu.exercise.model.Model;
import seedu.exercise.model.resource.Exercise;
import seedu.exercise.ui.ListResourceType;

/**
* Deletes an exercise identified using it's displayed index from the exercise book.
Expand Down Expand Up @@ -44,7 +45,8 @@ public CommandResult execute(Model model) throws CommandException {
model.deleteExercise(exerciseToDelete);
model.updateStatistic();
EventHistory.getInstance().addCommandToUndoStack(this);
return new CommandResult(String.format(MESSAGE_DELETE_EXERCISE_SUCCESS, exerciseToDelete));
return new CommandResult(String.format(MESSAGE_DELETE_EXERCISE_SUCCESS, exerciseToDelete),
ListResourceType.EXERCISE);
}

@Override
Expand Down
Expand Up @@ -19,6 +19,7 @@
import seedu.exercise.model.property.Name;
import seedu.exercise.model.resource.Exercise;
import seedu.exercise.model.resource.Regime;
import seedu.exercise.ui.ListResourceType;

/**
* Deletes a regime identified using it's name or deletes exercises in regime.
Expand Down Expand Up @@ -71,9 +72,8 @@ public CommandResult execute(Model model) throws CommandException {
private CommandResult deleteRegimeFromModel(Regime regimeToDelete, Model model) {
model.deleteRegime(regimeToDelete);
addToEventPayloadForDeleteRegime(regimeToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_REGIME_SUCCESS,
name,
regimeToDelete));
return new CommandResult(String.format(MESSAGE_DELETE_REGIME_SUCCESS, name, regimeToDelete),
ListResourceType.REGIME);
}

/**
Expand All @@ -97,7 +97,8 @@ private CommandResult deleteExercisesFromRegime(Regime originalRegime, Model mod
addToEventPayloadForEditRegime(originalRegime, editedRegime);
model.setRegime(originalRegime, editedRegime);
model.updateFilteredRegimeList(Model.PREDICATE_SHOW_ALL_REGIMES);
return new CommandResult(String.format(MESSAGE_DELETE_EXERCISE_IN_REGIME_SUCCESS, editedRegime));
return new CommandResult(String.format(MESSAGE_DELETE_EXERCISE_IN_REGIME_SUCCESS, editedRegime),
ListResourceType.REGIME);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/exercise/logic/commands/EditCommand.java
Expand Up @@ -33,6 +33,7 @@
import seedu.exercise.model.property.Quantity;
import seedu.exercise.model.property.Unit;
import seedu.exercise.model.resource.Exercise;
import seedu.exercise.ui.ListResourceType;

/**
* Edits the details of an existing exercise in the exercise book.
Expand Down Expand Up @@ -97,7 +98,8 @@ public CommandResult execute(Model model) throws CommandException {
EventHistory.getInstance().addCommandToUndoStack(this);
model.updateFilteredExerciseList(Model.PREDICATE_SHOW_ALL_EXERCISES);
model.updateStatistic();
return new CommandResult(String.format(MESSAGE_EDIT_EXERCISE_SUCCESS, editedExercise));
return new CommandResult(String.format(MESSAGE_EDIT_EXERCISE_SUCCESS, editedExercise),
ListResourceType.EXERCISE);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/exercise/logic/commands/ListCommand.java
Expand Up @@ -4,6 +4,7 @@
import static seedu.exercise.model.Model.PREDICATE_SHOW_ALL_EXERCISES;

import seedu.exercise.model.Model;
import seedu.exercise.ui.ListResourceType;

/**
* Lists all exercises in the exercise book to the user.
Expand All @@ -19,7 +20,7 @@ public class ListCommand extends Command {
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredExerciseList(PREDICATE_SHOW_ALL_EXERCISES);
return new CommandResult(MESSAGE_SUCCESS);
return new CommandResult(MESSAGE_SUCCESS, ListResourceType.EXERCISE);
}

}
Expand Up @@ -8,6 +8,7 @@
import seedu.exercise.logic.commands.exceptions.CommandException;
import seedu.exercise.model.Model;
import seedu.exercise.model.resource.Schedule;
import seedu.exercise.ui.ListResourceType;

/**
* Completes a schedule and removes it from the schedule list.
Expand All @@ -30,7 +31,8 @@ public CommandResult execute(Model model) throws CommandException {
checkValidIndex(model);
completeSchedule(model);

return new CommandResult(String.format(MESSAGE_SUCCESS, Integer.toString(index.getOneBased())));
return new CommandResult(String.format(MESSAGE_SUCCESS, Integer.toString(index.getOneBased())),
ListResourceType.SCHEDULE);
}

@Override
Expand Down
Expand Up @@ -13,6 +13,7 @@
import seedu.exercise.model.property.Name;
import seedu.exercise.model.resource.Regime;
import seedu.exercise.model.resource.Schedule;
import seedu.exercise.ui.ListResourceType;

/**
* Schedules a regime at a specific date.
Expand Down Expand Up @@ -47,7 +48,8 @@ public CommandResult execute(Model model) throws CommandException {

schedule(model, toSchedule);

return new CommandResult(String.format(MESSAGE_SUCCESS, regime.getRegimeName(), dateToSchedule));
return new CommandResult(String.format(MESSAGE_SUCCESS, regime.getRegimeName(), dateToSchedule),
ListResourceType.SCHEDULE);
}

@Override
Expand Down
Expand Up @@ -10,6 +10,7 @@
import seedu.exercise.logic.commands.exceptions.CommandException;
import seedu.exercise.model.Model;
import seedu.exercise.model.resource.Exercise;
import seedu.exercise.ui.ListResourceType;

/**
* Lists basic exercises in the exercise database to the user.
Expand All @@ -29,7 +30,7 @@ public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Exercise> basicExercises = Arrays.asList(getBasicExercises());
model.setSuggestions(basicExercises);
return new CommandResult(MESSAGE_SUCCESS);
return new CommandResult(MESSAGE_SUCCESS, ListResourceType.SUGGESTION);
}

@Override
Expand Down
Expand Up @@ -12,6 +12,7 @@
import seedu.exercise.model.Model;
import seedu.exercise.model.property.Muscle;
import seedu.exercise.model.resource.Exercise;
import seedu.exercise.ui.ListResourceType;

/**
* Lists possible exercises to the user.
Expand Down Expand Up @@ -42,7 +43,7 @@ public SuggestPossibleCommand(Set<Muscle> targetMuscles, Map<String, String> tar
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.updateSuggestedExerciseList(getPredicate());
return new CommandResult(MESSAGE_SUCCESS);
return new CommandResult(MESSAGE_SUCCESS, ListResourceType.SUGGESTION);
}

private Predicate<Exercise> getPredicate() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/exercise/ui/ExerciseListPanel.java
Expand Up @@ -26,6 +26,10 @@ public ExerciseListPanel(ObservableList<Exercise> exerciseList) {
exerciseListView.setCellFactory(listView -> new ExerciseListViewCell());
}

public ListView<Exercise> getExerciseListView() {
return exerciseListView;
}

/**
* Custom {@code ListCell} that displays the graphics of a {@code Exercise} using a {@code ExerciseCard}.
*/
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/seedu/exercise/ui/InfoDisplayPanel.java
@@ -0,0 +1,19 @@
package seedu.exercise.ui;

import java.util.logging.Logger;

import javafx.scene.layout.Region;
import seedu.exercise.commons.core.LogsCenter;

/**
* Placeholder Panel for Specific Information displayed in center panel.
*/
public class InfoDisplayPanel extends UiPart<Region> {
private static final String FXML = "InfoDisplayPanel.fxml";
private final Logger logger = LogsCenter.getLogger(InfoDisplayPanel.class);


public InfoDisplayPanel() {
super(FXML);
}
}
16 changes: 16 additions & 0 deletions src/main/java/seedu/exercise/ui/ListResourceType.java
@@ -0,0 +1,16 @@
package seedu.exercise.ui;

/**
* Encapsulates the different list of resource types to be displayed in GUI.
*/
public enum ListResourceType {
NULL,
EXERCISE,
REGIME,
SCHEDULE,
SUGGESTION;

public static final String LIST_RESOURCE_TYPE_CONSTRAINTS =
"List resource type should be one of the following: exercise, regime, schedule or suggestion";

}