diff --git a/src/main/java/com/application/munera/views/people/PeopleView.java b/src/main/java/com/application/munera/views/people/PeopleView.java index 070ad5f..3032b9e 100644 --- a/src/main/java/com/application/munera/views/people/PeopleView.java +++ b/src/main/java/com/application/munera/views/people/PeopleView.java @@ -83,16 +83,7 @@ public class PeopleView extends Div implements BeforeEnterObserver { List people = (List) personService.findAll(); - for (Person person : people) { - // Add the person as a root item - grid.getTreeData().addItem(null, person); - - // Fetch expenses for the current person - List expenses = expenseService.findExpenseByUser(person); - - // Add each expense as a child item under the person - for (Expense expense : expenses) grid.getTreeData().addItem(person, expense); - } + this.setGridData(people); // when a row is selected or deselected, populate form grid.asSingleSelect().addValueChangeListener(event -> { @@ -261,4 +252,17 @@ public class PeopleView extends Div implements BeforeEnterObserver { } return badge; } + + public void setGridData(List people) { + for (Person person : people) { + // Add the person as a root item + grid.getTreeData().addItem(null, person); + + // Fetch expenses for the current person + List expenses = expenseService.findExpenseByUser(person); + + // Add each expense as a child item under the person + for (Expense expense : expenses) grid.getTreeData().addItem(person, expense); + } + } } \ No newline at end of file