diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 45e8f58fbc0..f3a2422bdb2 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -65,7 +65,7 @@ public interface Logic { BooleanProperty getIsAnalyticsTab(); - void setToPersonTab(); - ObjectProperty getAnalytics(); + + BooleanProperty getIsPersonTab(); } diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 66dfdeff5ff..1cf4c1f7ea1 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -121,7 +121,7 @@ public void setIsAnalyticsTab(boolean isAnalyticsTab) { } @Override - public void setToPersonTab() { - model.setToPersonTab(); + public BooleanProperty getIsPersonTab() { + return model.getIsPersonTab(); } } diff --git a/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java b/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java index 7989d8cd88f..218121faf26 100644 --- a/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java @@ -50,6 +50,7 @@ public CommandResult execute(Model model) throws CommandException { } else { model.updateFilteredLoanList(loan -> loan.isAssignedTo(personToShowLoan) && loan.isActive()); } + model.setDualPanel(); return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(personToShowLoan)), false, false, true); } diff --git a/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java b/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java index 1ab9af86d50..77c7ab5440e 100644 --- a/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java @@ -28,6 +28,7 @@ public CommandResult execute(Model model) { } else { model.updateFilteredLoanList(PREDICATE_SHOW_ALL_ACTIVE_LOANS); } + model.setIsLoansTab(true); return new CommandResult(MESSAGE_SUCCESS, false, false, true); } } diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index aa7c614ca48..c0145a431a1 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -156,4 +156,10 @@ public interface Model { void unmarkLoan(Loan loanToUnmark); ObjectProperty getDashboardData(); + + BooleanProperty getIsPersonTab(); + + void setIsPersonTab(Boolean isPersonTab); + + void setDualPanel(); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index c41c5d4f517..dc223243cb7 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -37,6 +37,7 @@ public class ModelManager implements Model { private final SortedList sortedLoans; private final BooleanProperty isLoansTab = new SimpleBooleanProperty(false); private final BooleanProperty isAnalyticsTab = new SimpleBooleanProperty(false); + private final BooleanProperty isPersonTab = new SimpleBooleanProperty(false); private final ObjectProperty dashboardData = new SimpleObjectProperty<>(); /** @@ -220,8 +221,10 @@ public BooleanProperty getIsLoansTab() { @Override public void setIsLoansTab(Boolean isLoansTab) { + System.out.println("Method setIsLoansTab called inside ModelManager"); if (isLoansTab) { this.isAnalyticsTab.setValue(false); + this.isPersonTab.setValue(false); } this.isLoansTab.setValue(isLoansTab); } @@ -233,14 +236,17 @@ public BooleanProperty getIsAnalyticsTab() { @Override public void setToPersonTab() { + System.out.println("Method setToPersonTab called inside ModelManager"); this.isLoansTab.setValue(false); this.isAnalyticsTab.setValue(false); + this.setIsPersonTab(true); } @Override public void setIsAnalyticsTab(Boolean isAnalyticsTab) { if (isAnalyticsTab) { this.isLoansTab.setValue(false); + this.isPersonTab.setValue(false); } this.isAnalyticsTab.setValue(isAnalyticsTab); } @@ -256,4 +262,27 @@ public void generateDashboardData(Analytics analytics) { Date urgencyBenchmark = this.addressBook.getUniqueLoanList().getEarliestReturnDate(); dashboardData.setValue(new DashboardData(analytics, impactBenchmark, urgencyBenchmark)); } + + @Override + public BooleanProperty getIsPersonTab() { + return this.isPersonTab; + } + + @Override + public void setIsPersonTab(Boolean isPersonTab) { + System.out.println("Method setIsPersonTab called inside ModelManager"); + if (isPersonTab) { + this.isLoansTab.setValue(false); + this.isAnalyticsTab.setValue(false); + } + this.isPersonTab.setValue(isPersonTab); + } + + @Override + public void setDualPanel() { + System.out.println("Method setDualPanel called inside ModelManager"); + this.isLoansTab.setValue(true); + this.isPersonTab.setValue(true); + this.isAnalyticsTab.setValue(false); + } } diff --git a/src/main/java/seedu/address/ui/LoanListPanel.java b/src/main/java/seedu/address/ui/LoanListPanel.java index 9fc94a33579..6b85b6b8cdc 100644 --- a/src/main/java/seedu/address/ui/LoanListPanel.java +++ b/src/main/java/seedu/address/ui/LoanListPanel.java @@ -31,8 +31,6 @@ public LoanListPanel(ObservableList loanList, ObservableList perso super(FXML); loanListView.setItems(loanList); loanListView.setCellFactory(listView -> new LoanListViewCell()); - personListView.setItems(personList); - personListView.setCellFactory(listView -> new PersonListViewCell()); } /** diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index f00e0155292..f5b03e8858b 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -75,6 +75,8 @@ public class MainWindow extends UiPart { private BooleanProperty isAnalyticsTab; + private BooleanProperty isPersonTab; + /** * Creates a {@code MainWindow} with the given {@code Stage} and {@code Logic}. */ @@ -167,8 +169,13 @@ private void initializeLocalListeners() { this.isLoansTab = logic.getIsLoansTab(); // Add listener to update the analytics panel when the tab is switched this.isAnalyticsTab = logic.getIsAnalyticsTab(); + this.isPersonTab = logic.getIsPersonTab(); logic.setIsAnalyticsTab(false); logic.setIsLoansTab(false); + + this.isPersonTab.addListener((observable, oldValue, newValue) -> { + toggleTabs(); + }); this.isLoansTab.addListener((observable, oldValue, newValue) -> { toggleTabs(); }); @@ -178,22 +185,36 @@ private void initializeLocalListeners() { } private void toggleTabs() { - // At most one can be active at a time + // At most one of these can be active at a time assert (!(this.isLoansTab.getValue() && this.isAnalyticsTab.getValue())); - - if (!this.isLoansTab.getValue() && !this.isAnalyticsTab.getValue()) { + if (isPersonTab.getValue() && isLoansTab.getValue()) { + // Default to person list panel + clearAllPlaceholders(); + VBox.setVgrow(personList, Priority.ALWAYS); + VBox.setVgrow(loanList, Priority.NEVER); + VBox.setVgrow(analytics, Priority.NEVER); + personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + VBox.setVgrow(loanList, Priority.ALWAYS); + loanListPanelPlaceholder.getChildren().add(loanListPanel.getRoot()); + VBox.setVgrow(analytics, Priority.NEVER); + personListPanelPlaceholder.setMaxHeight(240); + System.out.println("Both tabs are active"); + } else if (isPersonTab.getValue()) { // Default to person list panel clearAllPlaceholders(); + personListPanelPlaceholder.setMaxHeight(Double.POSITIVE_INFINITY); VBox.setVgrow(personList, Priority.ALWAYS); VBox.setVgrow(loanList, Priority.NEVER); VBox.setVgrow(analytics, Priority.NEVER); personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + System.out.println("Only person tab is active"); } else if (this.isLoansTab.getValue()) { clearAllPlaceholders(); VBox.setVgrow(loanList, Priority.ALWAYS); VBox.setVgrow(personList, Priority.NEVER); VBox.setVgrow(analytics, Priority.NEVER); loanListPanelPlaceholder.getChildren().add(loanListPanel.getRoot()); + System.out.println("Only loans tab is active"); } else { clearAllPlaceholders(); VBox.setVgrow(analytics, Priority.ALWAYS); @@ -276,7 +297,7 @@ private CommandResult executeCommand(String commandText) throws CommandException handleExit(); } // Enable/Disable the loan tab based on whether command is loan related - logic.setIsLoansTab(commandResult.isLoanRelated()); + // logic.setIsLoansTab(commandResult.isLoanRelated()); return commandResult; } catch (CommandException | ParseException e) { diff --git a/src/main/resources/view/LoanListPanel.fxml b/src/main/resources/view/LoanListPanel.fxml index 7bd0ce923aa..879ddf2ec21 100644 --- a/src/main/resources/view/LoanListPanel.fxml +++ b/src/main/resources/view/LoanListPanel.fxml @@ -4,6 +4,5 @@ - diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 9074afbbbd5..fedd16dd75e 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -198,6 +198,7 @@ public void setIsLoansTab(Boolean isLoansTab) { public void markLoan(Loan loanToMark) { throw new AssertionError("This method should not be called."); } + @Override public void unmarkLoan(Loan loanToUnmark) { throw new AssertionError("This method should not be called."); @@ -208,6 +209,21 @@ public ObjectProperty getDashboardData() { throw new AssertionError("This method should not be called."); } + @Override + public BooleanProperty getIsPersonTab() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setIsPersonTab(Boolean isPersonTab) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setDualPanel() { + throw new AssertionError("This method should not be called."); + } + @Override public void deleteLoan(Loan loan) { throw new AssertionError("This method should not be called.");