From a393c82649423e1f0b2a60c3cf8d2160e81cc233 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 28 Aug 2024 15:37:09 -0400 Subject: [PATCH] =?UTF-8?q?#7=20Perfil=20de=20Personal=20Administrativo=20?= =?UTF-8?q?-=20Listado=20de=20empleados=20(Mostrar=20mensaje:=20No=20exist?= =?UTF-8?q?en=20m=C3=A1s=20datos=20en=20la=20lista)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/EmployeesListView.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index bada406..4dc9706 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -7,6 +7,7 @@ import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.html.H2; import com.vaadin.flow.component.html.Main; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; +import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; import com.vaadin.flow.spring.annotation.SpringComponent; @@ -98,16 +99,28 @@ public class EmployeesListView extends Main { private Button createNavigationButton(String label, int increment) { Button button = new Button(label); - button.addClickListener(event -> changePage(increment)); + button.addClickListener(event -> handlePageChange(increment)); return button; } - private void changePage(int increment) { - if (increment < 0 && currentPage > 1) { - currentPage--; - } else if (increment > 0 && employeeService.hasNextPage(currentPage, pageSize, sortField, ascending)) { - currentPage++; + private void handlePageChange(int increment) { + if (isPageChangeValid(increment)) { + currentPage += increment; + updateGrid(); + } else { + showNotification("No existen más datos en lista."); } - updateGrid(); + } + private boolean isPageChangeValid(int increment) { + if (increment < 0) { + return currentPage > 1; + } else if (increment > 0) { + return employeeService.hasNextPage(currentPage, pageSize, sortField, ascending); + } + return false; + } + private void showNotification(String message) { + Notification notification = new Notification(message, 3000, Notification.Position.BOTTOM_END); + notification.open(); } private Button createAddEmployeeButton() { return new Button("Add Employee", event -> @@ -117,7 +130,5 @@ public class EmployeesListView extends Main { private void updateGrid() { Page page = employeeService.getEmployeesPaginated(currentPage, pageSize, sortField, ascending); grid.setItems(page.getContent()); - previous.setEnabled(currentPage > 1); - next.setEnabled(page.hasNext()); } }