diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index ee29fa30e0b..69f80525834 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -2,7 +2,6 @@ import java.nio.file.Path; -import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; @@ -13,6 +12,7 @@ import seedu.address.model.analytics.DashboardData; import seedu.address.model.person.Loan; import seedu.address.model.person.Person; +import seedu.address.model.tabindicator.TabIndicator; /** * API of the Logic component @@ -57,17 +57,7 @@ public interface Logic { ObservableList getSortedLoanList(); - void setIsLoansTab(boolean isLoansTab); - - BooleanProperty getIsLoansTab(); - - void setIsAnalyticsTab(boolean isAnalyticsTab); - - BooleanProperty getIsAnalyticsTab(); - ObjectProperty getAnalytics(); - BooleanProperty getIsPersonTab(); - - BooleanProperty getLoaneeInfoFlag(); + ObjectProperty getTabIndicator(); } diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 3cad3fa7fe0..f926387dfb9 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -5,7 +5,6 @@ import java.nio.file.Path; import java.util.logging.Logger; -import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; @@ -20,8 +19,10 @@ import seedu.address.model.analytics.DashboardData; import seedu.address.model.person.Loan; import seedu.address.model.person.Person; +import seedu.address.model.tabindicator.TabIndicator; import seedu.address.storage.Storage; + /** * The main LogicManager of the app. */ @@ -95,38 +96,13 @@ public ObservableList getSortedLoanList() { return model.getSortedLoanList(); } - @Override - public void setIsLoansTab(boolean isLoansTab) { - model.setIsLoansTab(isLoansTab); - } - - @Override - public BooleanProperty getIsLoansTab() { - return model.getIsLoansTab(); - } - @Override public ObjectProperty getAnalytics() { return model.getDashboardData(); } @Override - public BooleanProperty getIsAnalyticsTab() { - return model.getIsAnalyticsTab(); - } - - @Override - public void setIsAnalyticsTab(boolean isAnalyticsTab) { - model.setIsAnalyticsTab(isAnalyticsTab); - } - - @Override - public BooleanProperty getIsPersonTab() { - return model.getIsPersonTab(); - } - - @Override - public BooleanProperty getLoaneeInfoFlag() { - return model.getLoaneeInfoFlag(); + public ObjectProperty getTabIndicator() { + return model.getTabIndicator(); } } diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index a2cf7e72377..34661300c9c 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -83,7 +83,7 @@ public CommandResult execute(Model model) throws CommandException { } model.setPerson(personToEdit, editedPerson); - if (model.getIsLoansTab().get()) { + if (model.getTabIndicator().getValue().getIsLoansTab()) { model.updateFilteredPersonList(person -> person.isSamePerson(editedPerson)); model.updateFilteredLoanList(loan -> loan.isAssignedTo(editedPerson)); } @@ -141,7 +141,8 @@ public static class EditPersonDescriptor { private Address address; private Set tags; - public EditPersonDescriptor() {} + public EditPersonDescriptor() { + } /** * Copy constructor. diff --git a/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java b/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java index 6a65399b6e1..a482b91d322 100644 --- a/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java @@ -47,7 +47,7 @@ public CommandResult execute(Model model) throws CommandException { model.updateFilteredPersonList(person -> person.equals(personToShowLoan)); model.updateFilteredLoanList(loan -> loan.isAssignedTo(personToShowLoan), isShowAllLoans); model.setDualPanel(); - model.setLoaneeInfoFlag(false); + model.setIsShowLoaneeInfo(false); 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 12f26b4dca3..ceb7d0d3e23 100644 --- a/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java @@ -23,7 +23,7 @@ public CommandResult execute(Model model) { model.updateFilteredPersonList(PREDICATE_SHOW_NO_PERSONS); model.updateFilteredLoanList(unused -> true, isShowAllLoans); model.setIsLoansTab(true); - model.setLoaneeInfoFlag(true); + model.setIsShowLoaneeInfo(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 bf8477c8ccf..41252360041 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -1,10 +1,8 @@ package seedu.address.model; import java.nio.file.Path; -import java.util.List; import java.util.function.Predicate; -import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; @@ -13,6 +11,7 @@ import seedu.address.model.person.Analytics; import seedu.address.model.person.Loan; import seedu.address.model.person.Person; +import seedu.address.model.tabindicator.TabIndicator; /** * The API of the Model component. @@ -159,14 +158,18 @@ public interface Model { */ void updateFilteredLoanList(Predicate predicate, boolean isShowAllLoans); - void setLoanList(List loanList); - - BooleanProperty getIsLoansTab(); - + /** + * Sets the tab to the loans tab. + * + * @param isLoansTab + */ void setIsLoansTab(Boolean isLoansTab); - BooleanProperty getIsAnalyticsTab(); - + /** + * Sets the tab to the analytics tab. + * + * @param isAnalyticsTab + */ void setIsAnalyticsTab(Boolean isAnalyticsTab); void setToPersonTab(); @@ -179,13 +182,9 @@ public interface Model { ObjectProperty getDashboardData(); - BooleanProperty getIsPersonTab(); - - void setIsPersonTab(Boolean isPersonTab); - void setDualPanel(); - BooleanProperty getLoaneeInfoFlag(); + void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo); - void setLoaneeInfoFlag(Boolean loaneeInfoFlag); + ObjectProperty getTabIndicator(); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 803a10edc39..dbb45ffc5e2 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -6,13 +6,10 @@ import java.math.BigDecimal; import java.nio.file.Path; import java.util.Date; -import java.util.List; import java.util.function.Predicate; import java.util.logging.Logger; -import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; @@ -24,6 +21,7 @@ import seedu.address.model.person.Analytics; import seedu.address.model.person.Loan; import seedu.address.model.person.Person; +import seedu.address.model.tabindicator.TabIndicator; /** * Represents the in-memory model of the address book data. @@ -36,11 +34,8 @@ public class ModelManager implements Model { private final FilteredList filteredPersons; private final FilteredList filteredLoans; 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 BooleanProperty isShowAllLoans = new SimpleBooleanProperty(false); - private final BooleanProperty loaneeInfoFlag = new SimpleBooleanProperty(true); + private final ObjectProperty tabIndicator = new SimpleObjectProperty<>(new TabIndicator(false, + false, true, false, false)); private final ObjectProperty dashboardData = new SimpleObjectProperty<>(); @@ -192,14 +187,15 @@ public ObservableList getSortedLoanList() { public void updateFilteredLoanList(Predicate predicate) { requireNonNull(predicate); Predicate secondPredicate = - isShowAllLoans.get() ? PREDICATE_SHOW_ALL_LOANS : PREDICATE_SHOW_ALL_ACTIVE_LOANS; + this.tabIndicator.getValue().getIsShowAllLoans() ? PREDICATE_SHOW_ALL_LOANS + : PREDICATE_SHOW_ALL_ACTIVE_LOANS; filteredLoans.setPredicate(predicate.and(secondPredicate)); } @Override public void updateFilteredLoanList(Predicate predicate, boolean isShowAllLoans) { requireNonNull(predicate); - this.isShowAllLoans.setValue(isShowAllLoans); + this.tabIndicator.setValue(this.tabIndicator.getValue().setIsShowAllLoans(isShowAllLoans)); updateFilteredLoanList(predicate); } @@ -221,50 +217,25 @@ public boolean equals(Object other) { && sortedLoans.equals(otherModelManager.sortedLoans); } - @Override - public void setLoanList(List loanList) { - filteredLoans.clear(); - filteredLoans.setAll(loanList); - } - - @Override - public BooleanProperty getIsLoansTab() { - return this.isLoansTab; - } - @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); + this.tabIndicator.setValue(this.tabIndicator.getValue().setIsLoansTab(isLoansTab)); } - @Override - public BooleanProperty getIsAnalyticsTab() { - return this.isAnalyticsTab; - } @Override public void setToPersonTab() { - System.out.println("Method setToPersonTab called inside ModelManager"); - this.isLoansTab.setValue(false); - this.isAnalyticsTab.setValue(false); this.updateFilteredLoanList(PREDICATE_SHOW_NO_LOANS); - this.setIsPersonTab(true); + this.tabIndicator.setValue(this.tabIndicator.getValue().setIsPersonTab(true)); } @Override public void setIsAnalyticsTab(Boolean isAnalyticsTab) { if (isAnalyticsTab) { - this.isLoansTab.setValue(false); - this.isPersonTab.setValue(false); this.updateFilteredPersonList(PREDICATE_SHOW_NO_PERSONS); this.updateFilteredLoanList(PREDICATE_SHOW_NO_LOANS); } - this.isAnalyticsTab.setValue(isAnalyticsTab); + this.tabIndicator.setValue(this.tabIndicator.getValue().setIsAnalyticsTab(isAnalyticsTab)); } @Override @@ -279,36 +250,18 @@ public void generateDashboardData(Analytics analytics) { 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); + this.tabIndicator.setValue(this.tabIndicator.getValue().setDualPanelView()); } @Override - public BooleanProperty getLoaneeInfoFlag() { - return this.loaneeInfoFlag; + public void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo) { + this.tabIndicator.setValue(this.tabIndicator.getValue().setIsShowLoaneeInfo(isShowLoaneeInfo)); } @Override - public void setLoaneeInfoFlag(Boolean loaneeInfoFlag) { - this.loaneeInfoFlag.setValue(loaneeInfoFlag); + public ObjectProperty getTabIndicator() { + return this.tabIndicator; } } diff --git a/src/main/java/seedu/address/model/analytics/DashboardData.java b/src/main/java/seedu/address/model/analytics/DashboardData.java index 0d8585ceaaf..ecf4fab7256 100644 --- a/src/main/java/seedu/address/model/analytics/DashboardData.java +++ b/src/main/java/seedu/address/model/analytics/DashboardData.java @@ -63,7 +63,7 @@ public BigDecimal getImpactIndex() { * @return urgency index between 0 and 1 */ public Float getUrgencyIndex() { - // Should take extra measures to ensure no overdue loans are used for calculations + // both variables can be null if the lists are empty if (analytics.getEarliestReturnDate() == null || earliestReturnDate == null) { return null; } diff --git a/src/main/java/seedu/address/model/person/Analytics.java b/src/main/java/seedu/address/model/person/Analytics.java index 8559df171c1..9641973aa78 100644 --- a/src/main/java/seedu/address/model/person/Analytics.java +++ b/src/main/java/seedu/address/model/person/Analytics.java @@ -157,14 +157,6 @@ public static Analytics getAnalytics(ObservableList loanList) { return analytics; } - public int getNumLoans() { - return numLoans; - } - - public int getNumOverdueLoans() { - return numOverdueLoans; - } - public int getNumActiveLoans() { return numActiveLoans; } @@ -177,46 +169,14 @@ public float getPropActiveLoans() { return propActiveLoans; } - public BigDecimal getTotalValueLoaned() { - return totalValueLoaned; - } - - public BigDecimal getTotalValueOverdue() { - return totalValueOverdue; - } - - public BigDecimal getTotalValueActive() { - return totalValueActive; - } - public BigDecimal getAverageLoanValue() { return averageLoanValue; } - public BigDecimal getAverageOverdueValue() { - return averageOverdueValue; - } - - public BigDecimal getAverageActiveValue() { - return averageActiveValue; - } - - public Date getEarliestLoanDate() { - return earliestLoanDate; - } - public Date getEarliestReturnDate() { return earliestReturnDate; } - public Date getLatestLoanDate() { - return latestLoanDate; - } - - public Date getLatestReturnDate() { - return latestReturnDate; - } - @Override public String toString() { return "Number of loans: " + numLoans + "\n" diff --git a/src/main/java/seedu/address/model/tabindicator/TabIndicator.java b/src/main/java/seedu/address/model/tabindicator/TabIndicator.java new file mode 100644 index 00000000000..b19e6c3db65 --- /dev/null +++ b/src/main/java/seedu/address/model/tabindicator/TabIndicator.java @@ -0,0 +1,106 @@ +package seedu.address.model.tabindicator; + +/** + * Represents the tab indicator of the dashboard. + * Determines which tab is currently shown in the GUI. + */ +public class TabIndicator { + private final boolean isLoansTab; + private final boolean isAnalyticsTab; + private final boolean isPersonTab; + private final boolean isShowAllLoans; + private final boolean isShowLoaneeInfo; + + /** + * Default constructor for TabIndicator. + * + * @param loans Whether the loans tab is shown. + * @param analytics Whether the analytics tab is shown. + * @param person Whether the person tab is shown. + * @param showAllLoans Whether to show all loans or only active loans. + * @param showLoaneeInfo Whether to show loanee information. + */ + public TabIndicator(boolean loans, boolean analytics, boolean person, boolean showAllLoans, + boolean showLoaneeInfo) { + this.isLoansTab = loans; + this.isAnalyticsTab = analytics; + this.isPersonTab = person; + this.isShowAllLoans = showAllLoans; + this.isShowLoaneeInfo = showLoaneeInfo; + } + + public boolean getIsLoansTab() { + return isLoansTab; + } + + public TabIndicator setIsLoansTab(boolean newIsLoansTab) { + if (newIsLoansTab) { + return new TabIndicator(newIsLoansTab, false, false, this.isShowAllLoans, this.isShowLoaneeInfo); + } + return new TabIndicator(newIsLoansTab, isAnalyticsTab, isPersonTab, this.isShowAllLoans, this.isShowLoaneeInfo); + + } + + public boolean getIsAnalyticsTab() { + return isAnalyticsTab; + } + + public TabIndicator setIsAnalyticsTab(boolean newIsAnalyticsTab) { + if (newIsAnalyticsTab) { + return new TabIndicator(false, newIsAnalyticsTab, false, + this.isShowAllLoans, this.isShowLoaneeInfo); + } + return new TabIndicator(this.isLoansTab, newIsAnalyticsTab, this.isPersonTab, + this.isShowAllLoans, this.isShowLoaneeInfo); + } + + public boolean getIsPersonTab() { + return isPersonTab; + } + + public TabIndicator setIsPersonTab(boolean newIsPersonTab) { + if (newIsPersonTab) { + return new TabIndicator(false, false, newIsPersonTab, + this.isShowAllLoans, this.isShowLoaneeInfo); + } + return new TabIndicator(this.isLoansTab, this.isAnalyticsTab, newIsPersonTab, + this.isShowAllLoans, this.isShowLoaneeInfo); + } + + public boolean getIsShowAllLoans() { + return isShowAllLoans; + } + + public TabIndicator setIsShowAllLoans(boolean newIsShowAllLoans) { + return new TabIndicator(this.isLoansTab, this.isAnalyticsTab, this.isPersonTab, + newIsShowAllLoans, this.isShowLoaneeInfo); + } + + public boolean getIsShowLoaneeInfo() { + return isShowLoaneeInfo; + } + + public TabIndicator setIsShowLoaneeInfo(boolean newIsShowLoaneeInfo) { + return new TabIndicator(this.isLoansTab, this.isAnalyticsTab, this.isPersonTab, + this.isShowAllLoans, newIsShowLoaneeInfo); + } + + public TabIndicator setDualPanelView() { + return new TabIndicator(true, false, true, this.isShowAllLoans, this.isShowLoaneeInfo); + } + + /** + * Returns a string representation of the TabIndicator. + * + * @return String representation of the TabIndicator. + */ + public String toString() { + return "Loans: " + isLoansTab + "\n" + + " Analytics: " + isAnalyticsTab + "\n" + + " Person: " + isPersonTab + "\n" + + " ShowAllLoans: " + isShowAllLoans + "\n" + + " ShowLoaneeInfo: " + isShowLoaneeInfo + "\n"; + } + + +} diff --git a/src/main/java/seedu/address/ui/AnalyticsPanel.java b/src/main/java/seedu/address/ui/AnalyticsPanel.java index 4565eab21a0..8bbd5fa0429 100644 --- a/src/main/java/seedu/address/ui/AnalyticsPanel.java +++ b/src/main/java/seedu/address/ui/AnalyticsPanel.java @@ -61,45 +61,56 @@ private void initializeCharts() { urgencyChart.setLegendVisible(false); } - private void updateChart(DashboardData data) { + private void updateReliability(DashboardData data) { Analytics analytics = data.getAnalytics(); if (analytics.getNumActiveLoans() == 0) { reliabilityIndex.setText("No active loans to analyze"); reliabilityChart.setVisible(false); - } else { - reliabilityChart.setVisible(true); - ObservableList reliabilityData = FXCollections.observableArrayList( - new PieChart.Data("Reliability Index", analytics.getPropOverdueLoans()), - new PieChart.Data("", 1 - analytics.getPropOverdueLoans()) - ); - reliabilityChart.setData(reliabilityData); - reliabilityIndex.setText(String.format("%.2f", (1 - analytics.getPropOverdueLoans()) * 100) + "%"); + return; } + reliabilityChart.setVisible(true); + ObservableList reliabilityData = FXCollections.observableArrayList( + new PieChart.Data("Reliability Index", analytics.getPropOverdueLoans()), + new PieChart.Data("", 1 - analytics.getPropOverdueLoans()) + ); + reliabilityChart.setData(reliabilityData); + reliabilityIndex.setText(String.format("%.2f", (1 - analytics.getPropOverdueLoans()) * 100) + "%"); + } + private void updateImpact(DashboardData data) { if (data.getMaxLoanValue().compareTo(BigDecimal.ZERO) == 0) { impactIndex.setText("No loans to analyze"); impactChart.setVisible(false); - } else { - impactChart.setVisible(true); - ObservableList impactData = FXCollections.observableArrayList( - new PieChart.Data("Impact Index", data.getImpactIndex().doubleValue()), - new PieChart.Data("", 1 - data.getImpactIndex().doubleValue()) - ); - impactChart.setData(impactData); - impactIndex.setText(String.format("%.2f", data.getImpactIndex().doubleValue() * 100) + "%"); + return; } + impactChart.setVisible(true); + ObservableList impactData = FXCollections.observableArrayList( + new PieChart.Data("Impact Index", data.getImpactIndex().doubleValue()), + new PieChart.Data("", 1 - data.getImpactIndex().doubleValue()) + ); + impactChart.setData(impactData); + impactIndex.setText(String.format("%.2f", data.getImpactIndex().doubleValue() * 100) + "%"); + } + + private void updateUrgency(DashboardData data) { if (data.getUrgencyIndex() == null) { urgencyIndex.setText("No due loans to analyze"); urgencyChart.setVisible(false); - } else { - urgencyChart.setVisible(true); - ObservableList urgencyData = FXCollections.observableArrayList( - new PieChart.Data("Urgency Index", data.getUrgencyIndex()), - new PieChart.Data("", 1 - data.getUrgencyIndex()) - ); - urgencyChart.setData(urgencyData); - urgencyIndex.setText(String.format("%.2f", data.getUrgencyIndex() * 100) + "%"); + return; } + urgencyChart.setVisible(true); + ObservableList urgencyData = FXCollections.observableArrayList( + new PieChart.Data("Urgency Index", data.getUrgencyIndex()), + new PieChart.Data("", 1 - data.getUrgencyIndex()) + ); + urgencyChart.setData(urgencyData); + urgencyIndex.setText(String.format("%.2f", data.getUrgencyIndex() * 100) + "%"); + } + + private void updateChart(DashboardData data) { + updateReliability(data); + updateImpact(data); + updateUrgency(data); } } diff --git a/src/main/java/seedu/address/ui/LoanListPanel.java b/src/main/java/seedu/address/ui/LoanListPanel.java index 68575e5a08f..81eeeefce0f 100644 --- a/src/main/java/seedu/address/ui/LoanListPanel.java +++ b/src/main/java/seedu/address/ui/LoanListPanel.java @@ -2,7 +2,7 @@ import java.util.logging.Logger; -import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.ListCell; @@ -10,7 +10,7 @@ import javafx.scene.layout.Region; import seedu.address.commons.core.LogsCenter; import seedu.address.model.person.Loan; -import seedu.address.model.person.Person; +import seedu.address.model.tabindicator.TabIndicator; /** * Panel containing the list of persons. @@ -22,26 +22,23 @@ public class LoanListPanel extends UiPart { @FXML private ListView loanListView; - @FXML - private ListView personListView; - - private BooleanProperty loaneeInfoFlag; + // private final BooleanProperty isShowLoaneeInfo; + private final ObjectProperty tabIndicator; /** * Creates a {@code PersonListPanel} with the given {@code ObservableList}. */ - public LoanListPanel(ObservableList loanList, BooleanProperty loaneeInfoFlag) { + public LoanListPanel(ObservableList loanList, ObjectProperty tabIndicator) { super(FXML); loanListView.setItems(loanList); loanListView.setCellFactory(listView -> new LoanListViewCell()); - this.loaneeInfoFlag = loaneeInfoFlag; + this.tabIndicator = tabIndicator; } /** * Custom {@code ListCell} that displays the graphics of a {@code Person} using a {@code PersonCard}. */ class LoanListViewCell extends ListCell { - @Override protected void updateItem(Loan loan, boolean empty) { super.updateItem(loan, empty); @@ -50,7 +47,8 @@ protected void updateItem(Loan loan, boolean empty) { setGraphic(null); setText(null); } else { - setGraphic(new LoanCard(loan, getIndex() + 1, loaneeInfoFlag.getValue()).getRoot()); + setGraphic(new LoanCard(loan, getIndex() + 1, + tabIndicator.getValue().getIsShowLoaneeInfo()).getRoot()); } } } diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index d13f8551666..08fa4cb18f5 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -2,7 +2,7 @@ import java.util.logging.Logger; -import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.MenuItem; @@ -19,6 +19,7 @@ import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tabindicator.TabIndicator; /** * The Main Window. Provides the basic application layout containing @@ -70,14 +71,7 @@ public class MainWindow extends UiPart { private VBox analytics; @FXML private VBox personList; - - private BooleanProperty isLoansTab; - - private BooleanProperty isAnalyticsTab; - - private BooleanProperty isPersonTab; - - private BooleanProperty loaneeInfoFlag; + private ObjectProperty tabIndicator; /** * Creates a {@code MainWindow} with the given {@code Stage} and {@code Logic}. @@ -142,15 +136,12 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) { void fillInnerParts() { initializeLocalListeners(); // Initial value of isLoansTab is false by default - assert (!this.isLoansTab.getValue()); + assert (!this.tabIndicator.getValue().getIsLoansTab()); // Initial value of isAnalyticsTab is false by default - assert (!this.isAnalyticsTab.getValue()); + assert (!this.tabIndicator.getValue().getIsAnalyticsTab()); personListPanel = new PersonListPanel(logic.getFilteredPersonList()); - this.loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getLoaneeInfoFlag()); - logic.getLoaneeInfoFlag().addListener((observable, oldValue, newValue) -> { - this.loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getLoaneeInfoFlag()); - System.out.println("Loanee info flag changed to: " + newValue); - }); + + loanListPanel = new LoanListPanel(logic.getSortedLoanList(), this.tabIndicator); analyticsPanel = new AnalyticsPanel(logic.getAnalytics()); personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); resultDisplay = new ResultDisplay(); @@ -171,70 +162,68 @@ private void initializePlaceholderSettings() { } private void initializeLocalListeners() { - // Add listener to tab flags - this.isLoansTab = logic.getIsLoansTab(); - this.isAnalyticsTab = logic.getIsAnalyticsTab(); - this.isPersonTab = logic.getIsPersonTab(); - - // Add listener to loaneeInfoFlag - this.loaneeInfoFlag = logic.getLoaneeInfoFlag(); + this.tabIndicator = logic.getTabIndicator(); - logic.setIsAnalyticsTab(false); - logic.setIsLoansTab(false); - - this.isPersonTab.addListener((observable, oldValue, newValue) -> { - toggleTabs(); - }); - this.isLoansTab.addListener((observable, oldValue, newValue) -> { - toggleTabs(); - }); - this.isAnalyticsTab.addListener((observable, oldValue, newValue) -> { + this.tabIndicator.addListener((observable, oldValue, newValue) -> { toggleTabs(); }); + + + } + + private void activateDualPanelView() { + 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(105); + personListPanelPlaceholder.setMinHeight(105); + VBox.setVgrow(personList, Priority.NEVER); + } + + private void activatePersonListOnlyView() { + 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()); + } + + private void activateAnalyticsView() { + clearAllPlaceholders(); + VBox.setVgrow(analytics, Priority.ALWAYS); + VBox.setVgrow(personList, Priority.NEVER); + VBox.setVgrow(loanList, Priority.NEVER); + personListPanelPlaceholder.setMinHeight(0); + analyticsPanelPlaceholder.getChildren().add(analyticsPanel.getRoot()); + } + + private void activateLoanListOnlyView() { + clearAllPlaceholders(); + VBox.setVgrow(loanList, Priority.ALWAYS); + VBox.setVgrow(personList, Priority.NEVER); + VBox.setVgrow(analytics, Priority.NEVER); + loanListPanelPlaceholder.getChildren().add(loanListPanel.getRoot()); + personListPanelPlaceholder.setMinHeight(0); } private void toggleTabs() { // At most one of these can be active at a time - assert (!(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(105); - personListPanelPlaceholder.setMinHeight(105); - VBox.setVgrow(personList, Priority.NEVER); - - 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()); - personListPanelPlaceholder.setMinHeight(0); - System.out.println("Only loans tab is active"); + assert (!(this.tabIndicator.getValue().getIsLoansTab() && this.tabIndicator.getValue().getIsAnalyticsTab())); + + if (this.tabIndicator.getValue().getIsPersonTab() && this.tabIndicator.getValue().getIsLoansTab()) { + activateDualPanelView(); + } else if (this.tabIndicator.getValue().getIsPersonTab()) { + activatePersonListOnlyView(); + } else if (this.tabIndicator.getValue().getIsLoansTab()) { + activateLoanListOnlyView(); } else { - clearAllPlaceholders(); - VBox.setVgrow(analytics, Priority.ALWAYS); - VBox.setVgrow(personList, Priority.NEVER); - VBox.setVgrow(loanList, Priority.NEVER); - personListPanelPlaceholder.setMinHeight(0); - analyticsPanelPlaceholder.getChildren().add(analyticsPanel.getRoot()); + activateAnalyticsView(); } } @@ -310,8 +299,6 @@ private CommandResult executeCommand(String commandText) throws CommandException if (commandResult.isExit()) { handleExit(); } - // Enable/Disable the loan tab based on whether command is loan related - // logic.setIsLoansTab(commandResult.isLoanRelated()); return commandResult; } catch (CommandException | ParseException e) { diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 0fb9c259046..1133bd16283 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -10,12 +10,10 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import java.util.function.Predicate; import org.junit.jupiter.api.Test; -import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; @@ -29,6 +27,7 @@ import seedu.address.model.person.Analytics; import seedu.address.model.person.Loan; import seedu.address.model.person.Person; +import seedu.address.model.tabindicator.TabIndicator; import seedu.address.testutil.PersonBuilder; public class AddCommandTest { @@ -169,12 +168,6 @@ public void updateFilteredPersonList(Predicate predicate) { throw new AssertionError("This method should not be called."); } - - @Override - public void setLoanList(List loanList) { - throw new AssertionError("This method should not be called."); - } - @Override public ObservableList getSortedLoanList() { throw new AssertionError("This method should not be called."); @@ -190,11 +183,6 @@ public void updateFilteredLoanList(Predicate predicate, boolean isShowAllL throw new AssertionError("This method should not be called."); } - @Override - public BooleanProperty getIsLoansTab() { - throw new AssertionError("This method should not be called."); - } - @Override public void setIsLoansTab(Boolean isLoansTab) { throw new AssertionError("This method should not be called."); @@ -215,28 +203,18 @@ 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 BooleanProperty getLoaneeInfoFlag() { + public void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo) { throw new AssertionError("This method should not be called."); } @Override - public void setLoaneeInfoFlag(Boolean loaneeInfoFlag) { + public ObjectProperty getTabIndicator() { throw new AssertionError("This method should not be called."); } @@ -260,11 +238,6 @@ public void setIsAnalyticsTab(Boolean isAnalyticsTab) { throw new AssertionError("This method should not be called."); } - @Override - public BooleanProperty getIsAnalyticsTab() { - throw new AssertionError("This method should not be called."); - } - @Override public void setToPersonTab() { throw new AssertionError("This method should not be called."); diff --git a/src/test/java/seedu/address/model/person/AnalyticsTest.java b/src/test/java/seedu/address/model/person/AnalyticsTest.java index 16740513a6d..e79f3bd9238 100644 --- a/src/test/java/seedu/address/model/person/AnalyticsTest.java +++ b/src/test/java/seedu/address/model/person/AnalyticsTest.java @@ -23,9 +23,6 @@ public void constructor_null_throwsNullPointerException() { public void emptyLoanList() { // Empty loan list should not throw any exceptions Analytics test = Analytics.getAnalytics(new UniqueLoanList().asUnmodifiableObservableList()); - - assertEquals(0, test.getNumLoans()); // No loans - assertEquals(0, test.getNumOverdueLoans()); // No overdue loans assertEquals(0, test.getNumActiveLoans()); // No active loans assertEquals(0, test.getPropOverdueLoans()); // Proportion of overdue loans is 0 (default) assertEquals(0, test.getPropActiveLoans()); // Proportion of active loans is 0 (default) @@ -40,8 +37,6 @@ public void singleLoan() { UniqueLoanList loanList = new UniqueLoanList(); loanList.addLoan(loan); Analytics test = Analytics.getAnalytics(loanList.asUnmodifiableObservableList()); - assertEquals(1, test.getNumLoans()); // 1 loan - assertEquals(0, test.getNumOverdueLoans()); // No overdue loans assertEquals(1, test.getNumActiveLoans()); // 1 active loan assertEquals(0, test.getPropOverdueLoans()); // Proportion of overdue loans is 0 (default) assertEquals(1, test.getPropActiveLoans()); // Proportion of active loans is 1 @@ -62,8 +57,6 @@ public void multipleActiveLoans() { loanList.addLoan(loan3); loanList.addLoan(loan4); Analytics test = Analytics.getAnalytics(loanList.asUnmodifiableObservableList()); - assertEquals(4, test.getNumLoans()); // 4 loans - assertEquals(1, test.getNumOverdueLoans()); // 1 overdue loans assertEquals(4, test.getNumActiveLoans()); // 4 active loans assertEquals(0.25, test.getPropOverdueLoans()); // Proportion of overdue loans is 0.25 assertEquals(1, test.getPropActiveLoans()); // Proportion of active loans is 1 @@ -89,8 +82,6 @@ public void withInactiveLoans() { loanList.addLoan(loan3); loanList.addLoan(loan4); Analytics test = Analytics.getAnalytics(loanList.asUnmodifiableObservableList()); - assertEquals(4, test.getNumLoans()); // 4 loans - assertEquals(0, test.getNumOverdueLoans()); // 1 overdue loan but is returned so should be zero assertEquals(3, test.getNumActiveLoans()); // 3 active loans assertEquals(0, test.getPropOverdueLoans()); // Proportion of overdue loans is 0 (loan4 is returned) assertEquals(0.75, test.getPropActiveLoans()); // Proportion of active loans is 1