From 0fc5b07f5edffef49426d3f8b7d1792a0e49cfbc Mon Sep 17 00:00:00 2001 From: filippo-ferrari Date: Thu, 18 Jul 2024 18:44:29 +0200 Subject: [PATCH] refactor --- .../munera/views/people/PeopleView.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) 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