Rama-Ricardo #14
@ -7,6 +7,7 @@ import com.vaadin.flow.component.combobox.ComboBox;
|
|||||||
import com.vaadin.flow.component.html.H2;
|
import com.vaadin.flow.component.html.H2;
|
||||||
import com.vaadin.flow.component.html.Main;
|
import com.vaadin.flow.component.html.Main;
|
||||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
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.PageTitle;
|
||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||||
@ -98,16 +99,28 @@ public class EmployeesListView extends Main {
|
|||||||
|
|
||||||
private Button createNavigationButton(String label, int increment) {
|
private Button createNavigationButton(String label, int increment) {
|
||||||
Button button = new Button(label);
|
Button button = new Button(label);
|
||||||
button.addClickListener(event -> changePage(increment));
|
button.addClickListener(event -> handlePageChange(increment));
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
private void changePage(int increment) {
|
private void handlePageChange(int increment) {
|
||||||
if (increment < 0 && currentPage > 1) {
|
if (isPageChangeValid(increment)) {
|
||||||
currentPage--;
|
currentPage += increment;
|
||||||
} else if (increment > 0 && employeeService.hasNextPage(currentPage, pageSize, sortField, ascending)) {
|
|
||||||
currentPage++;
|
|
||||||
}
|
|
||||||
updateGrid();
|
updateGrid();
|
||||||
|
} else {
|
||||||
|
showNotification("No existen más datos en lista.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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() {
|
private Button createAddEmployeeButton() {
|
||||||
return new Button("Add Employee", event ->
|
return new Button("Add Employee", event ->
|
||||||
@ -117,7 +130,5 @@ public class EmployeesListView extends Main {
|
|||||||
private void updateGrid() {
|
private void updateGrid() {
|
||||||
Page<Employee> page = employeeService.getEmployeesPaginated(currentPage, pageSize, sortField, ascending);
|
Page<Employee> page = employeeService.getEmployeesPaginated(currentPage, pageSize, sortField, ascending);
|
||||||
grid.setItems(page.getContent());
|
grid.setItems(page.getContent());
|
||||||
previous.setEnabled(currentPage > 1);
|
|
||||||
next.setEnabled(page.hasNext());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user