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()); } }