Skip to content

Commit

Permalink
Merge pull request #109 from marcus-ny/branch-fix-GUI-gap-in-viewloan
Browse files Browse the repository at this point in the history
Fix gap in GUI when `viewloan <index>` is called
  • Loading branch information
Joseph31416 authored Apr 4, 2024
2 parents f504e9d + 64ab6f7 commit 376b672
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public interface Logic {

BooleanProperty getIsAnalyticsTab();

void setToPersonTab();

ObjectProperty<DashboardData> getAnalytics();

BooleanProperty getIsPersonTab();
}
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void setIsAnalyticsTab(boolean isAnalyticsTab) {
}

@Override
public void setToPersonTab() {
model.setToPersonTab();
public BooleanProperty getIsPersonTab() {
return model.getIsPersonTab();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@ public interface Model {
void unmarkLoan(Loan loanToUnmark);

ObjectProperty<DashboardData> getDashboardData();

BooleanProperty getIsPersonTab();

void setIsPersonTab(Boolean isPersonTab);

void setDualPanel();
}
29 changes: 29 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class ModelManager implements Model {
private final SortedList<Loan> 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> dashboardData = new SimpleObjectProperty<>();

/**
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
}
2 changes: 0 additions & 2 deletions src/main/java/seedu/address/ui/LoanListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public LoanListPanel(ObservableList<Loan> loanList, ObservableList<Person> perso
super(FXML);
loanListView.setItems(loanList);
loanListView.setCellFactory(listView -> new LoanListViewCell());
personListView.setItems(personList);
personListView.setCellFactory(listView -> new PersonListViewCell());
}

/**
Expand Down
29 changes: 25 additions & 4 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class MainWindow extends UiPart<Stage> {

private BooleanProperty isAnalyticsTab;

private BooleanProperty isPersonTab;

/**
* Creates a {@code MainWindow} with the given {@code Stage} and {@code Logic}.
*/
Expand Down Expand Up @@ -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();
});
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/view/LoanListPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
<?import javafx.scene.layout.VBox?>

<VBox xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" spacing="0">
<ListView fx:id="personListView" maxHeight="290"/>
<ListView fx:id="loanListView" VBox.vgrow="ALWAYS"/>
</VBox>
16 changes: 16 additions & 0 deletions src/test/java/seedu/address/logic/commands/AddCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -208,6 +209,21 @@ public ObjectProperty<DashboardData> 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.");
Expand Down

0 comments on commit 376b672

Please sign in to comment.