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

Bug fixes and edit GUI #215

Merged
merged 20 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/seedu/algobase/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import seedu.algobase.storage.UserPrefsStorage;
import seedu.algobase.ui.Ui;
import seedu.algobase.ui.UiManager;
import seedu.algobase.ui.action.UiLogic;
import seedu.algobase.ui.action.UiLogicManager;

/**
* Runs the application.
Expand All @@ -42,6 +44,7 @@ public class MainApp extends Application {

protected Ui ui;
protected Logic logic;
protected UiLogic uiLogic;
protected Storage storage;
protected Model model;
protected Config config;
Expand All @@ -67,8 +70,9 @@ public void init() throws Exception {
model = initModelManager(storage, userPrefs);

logic = new LogicManager(model, storage);
uiLogic = new UiLogicManager(model, storage);

ui = new UiManager(logic);
ui = new UiManager(logic, uiLogic);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/algobase/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
public class Messages {

public static final String MESSAGE_UNKNOWN_UI_ACTION = "Unknown action";
public static final String MESSAGE_UNKNOWN_UI_ACTION_PROPERTY = "Unknown action property";
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_FIND_RULE_DISPLAYED_INDEX = "The Find Rule index provided is invalid";
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/seedu/algobase/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import seedu.algobase.model.searchrule.problemsearchrule.ProblemSearchRule;
import seedu.algobase.model.tag.Tag;
import seedu.algobase.model.task.Task;
import seedu.algobase.storage.SaveStorageRunnable;

/**
* API of the Logic component
Expand All @@ -31,13 +30,6 @@ public interface Logic {
*/
CommandResult execute(String commandText) throws CommandException, ParseException;

/**
* Returns a runnable that saves the AlgoBase.
*
* @see seedu.algobase.model.Model#getAlgoBase()
*/
SaveStorageRunnable getSaveAlgoBaseStorageRunnable();

/**
* Returns the AlgoBase.
*
Expand Down
23 changes: 5 additions & 18 deletions src/main/java/seedu/algobase/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import seedu.algobase.model.searchrule.problemsearchrule.ProblemSearchRule;
import seedu.algobase.model.tag.Tag;
import seedu.algobase.model.task.Task;
import seedu.algobase.storage.SaveStorageRunnable;
import seedu.algobase.storage.Storage;

/**
Expand Down Expand Up @@ -57,31 +56,19 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
history.add(commandText);
}

if (!getSaveAlgoBaseStorageRunnable().save()) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE);
try {
storage.saveAlgoBase(model.getAlgoBase());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}


TabManager tabManager = getGuiState().getTabManager();
tabManager.refreshTabManager();

return commandResult;
}

@Override
public SaveStorageRunnable getSaveAlgoBaseStorageRunnable() {
return new SaveStorageRunnable() {
@Override
public boolean save() {
try {
storage.saveAlgoBase(model.getAlgoBase());
return true;
} catch (IOException ioe) {
return false;
}
}
};
}

@Override
public ReadOnlyAlgoBase getAlgoBase() {
return model.getAlgoBase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ClearCommand extends Command {
@Override
public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(model);
model.clearPlans();
model.setAlgoBase(new AlgoBase());
return new CommandResult(MESSAGE_SUCCESS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import seedu.algobase.model.gui.WriteOnlyTabManager;

/**
* Close tabs in the GUI.
* Opens a tab in the GUI.
*/
public class OpenTabCommand extends Command {

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/seedu/algobase/model/AlgoBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ void removePlan(Plan key) {
plans.remove(key);
}

/**
Clear the list of plans
tiuweehan marked this conversation as resolved.
Show resolved Hide resolved
*/
public void clearPlans() {
plans.clear();
}

@Override
public ObservableList<Plan> getPlanList() {
return plans.asUnmodifiableObservableList();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/algobase/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ public interface Model {
*/
void deletePlan(Plan plan);

/**
* Clear the list of plans
*/
void clearPlans();

/**
* Adds the given Plan.
* {@code Plan} must not already exist in the algobase.
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/algobase/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ public void deletePlan(Plan target) {
algoBase.removePlan(target);
}

@Override
public void clearPlans() {
algoBase.clearPlans();
}

@Override
public void addPlan(Plan plan) {
algoBase.addPlan(plan);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/algobase/model/gui/TabManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public TabCommandType closeDetailsTab(TabData tabData) throws NoSuchElementExcep
this.tabsData.remove(tabData);

// If there are no tab data
if (this.tabsData.size() == 0) {
if (this.tabsData.size() == 0 || detailsTabPaneIndexValue == 0) {
// Do nothing
} else if (detailsTabPaneIndexValue >= tabIndex.getZeroBased()) {
// decrement the details tab pane index
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/seedu/algobase/model/plan/PlanList.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ public void remove(Plan toRemove) {
clearCurrentPlan();
}

/**
* Removes the equivalent Plan from the list.
* The Plan must exist in the list.
*/
public void clear() {
currentPlan.set("");
solvedCount.set(0);
unsolvedCount.set(0);
internalTaskList.setAll();
}

/**
* Replaces the contents of this list with {@code replacement}.
*/
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/seedu/algobase/storage/SaveStorageRunnable.java

This file was deleted.

49 changes: 40 additions & 9 deletions src/main/java/seedu/algobase/ui/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.algobase.ui;

import java.util.Optional;
import java.util.logging.Logger;

import javafx.event.ActionEvent;
Expand All @@ -18,6 +19,9 @@
import seedu.algobase.logic.commands.exceptions.CommandException;
import seedu.algobase.logic.parser.exceptions.ParseException;
import seedu.algobase.model.ModelType;
import seedu.algobase.ui.action.UiActionDetails;
import seedu.algobase.ui.action.UiActionResult;
import seedu.algobase.ui.action.UiLogic;
import seedu.algobase.ui.details.DetailsTabPane;
import seedu.algobase.ui.display.DisplayTab;
import seedu.algobase.ui.display.DisplayTabPane;
Expand All @@ -34,6 +38,7 @@ public class MainWindow extends UiPart<Stage> {

private Stage primaryStage;
private Logic logic;
private UiLogic uiLogic;

private ProblemListPanel problemListPanel;
private TagListPanel tagListPanel;
Expand All @@ -60,12 +65,13 @@ public class MainWindow extends UiPart<Stage> {
@FXML
private SplitPane layoutPanePlaceholder;

public MainWindow(Stage primaryStage, Logic logic) {
public MainWindow(Stage primaryStage, Logic logic, UiLogic uiLogic) {
super(FXML, primaryStage);

// Set dependencies
this.primaryStage = primaryStage;
this.logic = logic;
this.uiLogic = uiLogic;

// Configure the UI
setWindowDefaultSize(logic.getGuiSettings());
Expand Down Expand Up @@ -118,7 +124,7 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
*/
void fillInnerParts() {
DisplayTabPane displayTabPane = getDisplayTabPane();
DetailsTabPane detailsTabPane = new DetailsTabPane(logic);
DetailsTabPane detailsTabPane = new DetailsTabPane(logic, this::executeUiAction);
TaskManagementPane taskManagementPane = new TaskManagementPane(
logic.getProcessedTaskList(),
logic.getCurrentPlan(),
Expand Down Expand Up @@ -146,14 +152,11 @@ void fillInnerParts() {
private DisplayTabPane getDisplayTabPane() {
problemListPanel = new ProblemListPanel(
logic.getProcessedProblemList(),
logic.getGuiState().getTabManager(),
logic.getSaveAlgoBaseStorageRunnable()
this::executeUiAction
);
planListPanel = new PlanListPanel(
logic.getProcessedPlanList(),
logic.getGuiState().getTabManager(),
logic.getSaveAlgoBaseStorageRunnable(),
logic.getAlgoBase()
this::executeUiAction
);
tagListPanel = new TagListPanel(logic.getProcessedTagList());
findRuleListPanel = new FindRuleListPanel(logic.getProcessedFindRuleList());
Expand All @@ -162,8 +165,8 @@ private DisplayTabPane getDisplayTabPane() {
DisplayTab planListPanelTab = new DisplayTab(ModelType.PLAN.getTabName(), planListPanel);
DisplayTab findRuleListPaneTab = new DisplayTab(ModelType.FINDRULE.getTabName(), findRuleListPanel);
return new DisplayTabPane(
logic.getGuiState().getTabManager(),
logic.getSaveAlgoBaseStorageRunnable(),
logic.getGuiState().getReadOnlyTabManager(),
this::executeUiAction,
problemListPanelTab,
tagListPanelTab,
planListPanelTab,
Expand Down Expand Up @@ -238,4 +241,32 @@ private CommandResult executeCommand(String commandText) throws CommandException
throw e;
}
}

/**
* Executes a UI action returns the result.
*
* @see seedu.algobase.ui.action.UiLogic#execute(UiActionDetails)
*/
private UiActionResult executeUiAction(UiActionDetails uiActionDetails) {
try {
UiActionResult uiActionResult = uiLogic.execute(uiActionDetails);
uiActionResult.getFeedbackToUser().ifPresent((feedback) -> {
logger.info("Result: " + feedback);
resultDisplay.setFeedbackToUser(feedback);
});

if (uiActionResult.isShowHelp()) {
handleHelp();
}

if (uiActionResult.isExit()) {
handleExit();
}

return uiActionResult;
} catch (UiActionException | ParseException e) {
resultDisplay.setFeedbackToUser(e.getMessage());
tiuweehan marked this conversation as resolved.
Show resolved Hide resolved
return new UiActionResult(Optional.empty());
}
}
}
37 changes: 16 additions & 21 deletions src/main/java/seedu/algobase/ui/PlanCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
import seedu.algobase.commons.core.LogsCenter;
import seedu.algobase.logic.parser.ParserUtil;
import seedu.algobase.model.ModelType;
import seedu.algobase.model.ReadOnlyAlgoBase;
import seedu.algobase.model.gui.TabData;
import seedu.algobase.model.gui.WriteOnlyTabManager;
import seedu.algobase.model.plan.Plan;
import seedu.algobase.storage.SaveStorageRunnable;
import seedu.algobase.ui.action.UiActionDetails;
import seedu.algobase.ui.action.UiActionExecutor;
import seedu.algobase.ui.action.UiActionType;

/**
* An UI component that displays information of a {@code Plan}.
Expand All @@ -43,13 +42,7 @@ public class PlanCard extends UiPart<Region> {
@FXML
private Label endDate;

public PlanCard(
Plan plan,
int displayedIndex,
WriteOnlyTabManager writeOnlyTabManager,
SaveStorageRunnable saveStorageRunnable,
ReadOnlyAlgoBase algoBase
) {
public PlanCard(Plan plan, int displayedIndex, UiActionExecutor uiActionExecutor) {
super(FXML);
this.planIndex = displayedIndex - 1;
this.plan = plan;
Expand All @@ -68,7 +61,7 @@ public PlanCard(
endDate.setText(plan.getEndDate().format(ParserUtil.FORMATTER));
endDate.setWrapText(true);
endDate.setTextAlignment(TextAlignment.JUSTIFY);
addMouseClickListener(writeOnlyTabManager, saveStorageRunnable, algoBase);
addMouseClickListener(uiActionExecutor);
}

@Override
Expand All @@ -93,23 +86,25 @@ public boolean equals(Object other) {
/**
* Spawns a new Tab when the cardPane registers a double click event.
*
* @param writeOnlyTabManager The tab manager to be written to.
* @param uiActionExecutor The executor for the given UI action
*/
public void addMouseClickListener(
WriteOnlyTabManager writeOnlyTabManager,
SaveStorageRunnable saveStorageRunnable,
ReadOnlyAlgoBase algoBase
) {
public void addMouseClickListener(UiActionExecutor uiActionExecutor) {
cardPane.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
if (mouseEvent.getClickCount() == 2) {
logger.info("Double Clicked on Problem card with name " + plan.getPlanName());
logger.info("Opening new plan tab");
writeOnlyTabManager.openDetailsTab(new TabData(ModelType.PLAN, plan.getId()));
saveStorageRunnable.save();
algoBase.setCurrentPlan(planIndex);
uiActionExecutor.execute(new UiActionDetails(
UiActionType.OPEN_DETAILS_TAB,
ModelType.PLAN,
plan.getId()
));
uiActionExecutor.execute(new UiActionDetails(
UiActionType.SET_PLAN,
plan.getId()
));
}
}
}
Expand Down
Loading