From 4eebdf6f0113f5242d1c1457e809d24778c52a3a Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 3 Sep 2024 11:42:20 -0400 Subject: [PATCH 1/4] #7 Perfil de Personal Administrativo - Listado de empleados (Implementar PagingGrid) --- pom.xml | 5 + .../primefactorsolutions/model/Employee.java | 108 ++++++----- .../service/EmployeeService.java | 52 +++-- .../views/EmployeesListView.java | 180 +++++++++--------- 4 files changed, 182 insertions(+), 163 deletions(-) diff --git a/pom.xml b/pom.xml index e192968..cdd0c6d 100644 --- a/pom.xml +++ b/pom.xml @@ -110,6 +110,11 @@ spring-boot-starter-test test + + commons-beanutils + commons-beanutils + 1.9.4 + org.mockito mockito-core diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index 3d0d863..0a8e09d 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -1,51 +1,59 @@ -package com.primefactorsolutions.model; - -import io.hypersistence.utils.hibernate.type.json.JsonType; -import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.Type; - -import java.time.LocalDate; -import java.util.List; - -@Data -@Entity -@AllArgsConstructor -@NoArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class Employee extends BaseEntity { - private String firstName; - private String lastName; - private LocalDate birthday; - private String birthCity; - - @Enumerated(EnumType.STRING) - private MaritalStatus maritalStatus; - - private String residenceAddress; - private String phoneNumber; - private String personalEmail; - - private String emergencyCName; - private String emergencyCAddress; - private String emergencyCPhone; - private String emergencyCEmail; - - @Enumerated(EnumType.STRING) - private Status status; - - public enum Status { - ACTIVE, - INACTIVE + package com.primefactorsolutions.model; + + import io.hypersistence.utils.hibernate.type.json.JsonType; + import jakarta.persistence.*; + import lombok.AllArgsConstructor; + import lombok.Data; + import lombok.EqualsAndHashCode; + import lombok.NoArgsConstructor; + import org.hibernate.annotations.Type; + + import java.time.LocalDate; + import java.util.List; + + @Data + @Entity + @AllArgsConstructor + @NoArgsConstructor + @EqualsAndHashCode(callSuper = true) + public class Employee extends BaseEntity { + private String firstName; + private String lastName; + private LocalDate birthday; + private String birthCity; + + @Enumerated(EnumType.STRING) + private MaritalStatus maritalStatus; + + private String residenceAddress; + private String phoneNumber; + private String personalEmail; + + private String emergencyCName; + private String emergencyCAddress; + private String emergencyCPhone; + private String emergencyCEmail; + + @Enumerated(EnumType.STRING) + private Status status; + + public enum Status { + ACTIVE, + INACTIVE + } + + public enum MaritalStatus { + SINGLE, + MARRIED, + WIDOWED, + DIVORCED + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } } - - public enum MaritalStatus { - SINGLE, - MARRIED, - WIDOWED, - DIVORCED - } -} diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index 5e5a94f..55c2218 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -1,49 +1,65 @@ package com.primefactorsolutions.service; import com.primefactorsolutions.model.Employee; +import org.apache.commons.beanutils.BeanComparator; import com.primefactorsolutions.repositories.EmployeeRepository; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; import lombok.Data; -import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import java.util.List; import java.util.UUID; import java.util.Optional; +import java.util.Collections; @Service @Data public class EmployeeService { private final EmployeeRepository employeeRepository; + private List pagedBase; public EmployeeService(EmployeeRepository employeeRepository) { this.employeeRepository = employeeRepository; } + private void initializePagedBase() { + if (pagedBase == null) { + this.pagedBase = employeeRepository.findAll(); + } + } + + public List findEmployees(int start, int pageSize, String sortProperty, boolean asc) { + initializePagedBase(); // Asegurarse de que pagedBase esté inicializada + System.err.println("findAll " + start + " " + pageSize + " sort " + sortProperty + " asc:" + asc ); + int end = (int) (start + pageSize); + if (end > pagedBase.size()) { + end = pagedBase.size(); + } + Collections.sort(pagedBase, new BeanComparator(sortProperty)); + + if(!asc) { + Collections.reverse(pagedBase); + } + return pagedBase.subList((int) start, end); + } + + public List findEmployees(int start, int pageSize) { + initializePagedBase(); // Asegurarse de que pagedBase esté inicializada + System.err.println("findAll " + start + " " + pageSize); + int end = (int) (start + pageSize); + if (end > pagedBase.size()) { + end = pagedBase.size(); + } + return pagedBase.subList((int) start, end); + } + public Employee createOrUpdate(final Employee employee) { final Employee saved = employeeRepository.save(employee); return saved; } - public List getEmployees() { - return employeeRepository.findAll(); - } - public Employee getEmployee(final UUID id) { Optional employee = employeeRepository.findById(id); return employee.orElse(null); } - - public Page getEmployeesPaginated(int pageNo, int pageSize, String sortField, boolean ascending) { - Sort sort = ascending ? Sort.by(sortField).ascending() : Sort.by(sortField).descending(); - Pageable pageable = PageRequest.of(pageNo - 1, pageSize, sort); - return employeeRepository.findAll(pageable); - } - - public boolean hasNextPage(int currentPage, int pageSize, String sortField, boolean ascending) { - return getEmployeesPaginated(currentPage, pageSize, sortField, ascending).hasNext(); - } } diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 4dc9706..3b0e664 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -3,18 +3,20 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.service.EmployeeService; import com.vaadin.flow.component.button.Button; -import com.vaadin.flow.component.combobox.ComboBox; +import com.vaadin.flow.component.checkbox.Checkbox; 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; +import org.vaadin.firitin.components.grid.PagingGrid; +import com.vaadin.flow.component.grid.GridSortOrder; +import com.vaadin.flow.data.provider.SortDirection; import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; -import org.vaadin.firitin.components.grid.VGrid; -import org.springframework.data.domain.Page; + +import java.util.List; + @SpringComponent @Scope("prototype") @@ -24,111 +26,99 @@ import org.springframework.data.domain.Page; public class EmployeesListView extends Main { private final EmployeeService employeeService; - private final int pageSize = 5; - private int currentPage = 1; - private String sortField = "firstName"; - private boolean ascending = true; - private VGrid grid; - private Button previous; - private Button next; + private final PagingGrid table = new PagingGrid<>(Employee.class); public EmployeesListView(EmployeeService employeeService) { this.employeeService = employeeService; - addComponents(); - updateGrid(); + setupView(); + refreshGrid(); } - private void addComponents() { - addTitle(); - addOrderButtons(); - configureGrid(); - addNavigationButtons(); + private void setupView() { + add(new H2("Employee List")); + configureTable(); + add(createAddEmployeeButton()); + add(table); } - private void addTitle() { - final H2 title = new H2("Employees list"); - add(title); + private void configureTable() { + table.setColumns("firstName", "lastName", "status"); + addStatusColumn(); + addEditButtonColumn("Edit", this::navigateToEditView); + addEditButtonColumn("Save", this::navigateToSaveChangeStatus); + setupPagingGrid(); } - private void addOrderButtons() { - final HorizontalLayout hl = new HorizontalLayout(); - hl.add(createOrderButton("Employee List in Ascending Order", true)); - hl.add(createOrderButton("Employee List in Descending Order", false)); - add(hl); + private void addStatusColumn() { + table.addComponentColumn(this::createStatusCheckbox) + .setHeader("Change Status"); } - private Button createOrderButton(String label, boolean isAscending) { + private Checkbox createStatusCheckbox(Employee employee) { + Checkbox statusCheckbox = new Checkbox( employee.getStatus() == Employee.Status.ACTIVE); + return statusCheckbox; + } + + private void updateEmployeeStatus(Employee employee, boolean isActive) { + employee.setStatus(isActive ? Employee.Status.ACTIVE : Employee.Status.INACTIVE); + employeeService.createOrUpdate(employee); + refreshGrid(); + } + + private void addEditButtonColumn(String label, ButtonClickHandler handler) { + table.addComponentColumn(employee -> createButton(label, () -> handler.handle(employee))); + } + + private Button createButton(String label, Runnable onClickAction) { Button button = new Button(label); - button.addClickListener(event -> { - sortField = "firstName"; - ascending = isAscending; - updateGrid(); - }); + button.addClickListener(event -> onClickAction.run()); return button; } - private void configureGrid() { - grid = new VGrid<>(Employee.class); - grid.setColumns("firstName", "lastName", "status"); - grid.setAllRowsVisible(true); - grid.addComponentColumn(employee -> createStatusComboBox()).setHeader("Change Status"); - grid.addComponentColumn(employee -> createEditButton()); - grid.addComponentColumn(employee -> createSaveButton()); - add(grid); - } - private ComboBox createStatusComboBox() { - ComboBox statusComboBox = new ComboBox<>(); - statusComboBox.setItems("Active", "Inactive"); - return statusComboBox; - } - - private Button createEditButton() { - return new Button("Edit"); - } - private Button createSaveButton() { - return new Button("Save"); - } - - private void addNavigationButtons() { - final HorizontalLayout hf = new HorizontalLayout(); - previous = createNavigationButton("Previous", -1); - next = createNavigationButton("Next", 1); - hf.add(previous, next, createAddEmployeeButton()); - add(hf); - } - - private Button createNavigationButton(String label, int increment) { - Button button = new Button(label); - button.addClickListener(event -> handlePageChange(increment)); - return button; - } - private void handlePageChange(int increment) { - if (isPageChangeValid(increment)) { - currentPage += increment; - 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() { - return new Button("Add Employee", event -> - getUI().flatMap(ui -> ui.navigate(EmployeeView.class, "new")) - ); + return createButton("Add Employee", this::navigateToAddEmployeeView); } - private void updateGrid() { - Page page = employeeService.getEmployeesPaginated(currentPage, pageSize, sortField, ascending); - grid.setItems(page.getContent()); + + private void navigateToEditView(Employee employee) { + getUI().ifPresent(ui -> ui.navigate(EmployeeView.class, employee.getId().toString())); } -} + + private void navigateToAddEmployeeView() { + getUI().ifPresent(ui -> ui.navigate(EmployeeView.class, "new")); + } + + private void navigateToSaveChangeStatus(Employee employee) { + // no-op + } + + private void setupPagingGrid() { + table.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); + table.setPageSize(5); + } + + private void refreshGrid() { + table.setPagingDataProvider((page, pageSize) -> fetchEmployees((int) page, pageSize)); + } + + private List fetchEmployees(int page, int pageSize) { + int start = page * pageSize; + if (hasSortOrder()) { + return fetchSortedEmployees(start, pageSize); + } + return employeeService.findEmployees(start, pageSize); + } + + private boolean hasSortOrder() { + return !table.getSortOrder().isEmpty(); + } + + private List fetchSortedEmployees(int start, int pageSize) { + GridSortOrder sortOrder = table.getSortOrder().getFirst(); + return employeeService.findEmployees(start, pageSize, sortOrder.getSorted().getKey(), sortOrder.getDirection() == SortDirection.ASCENDING); + } + + @FunctionalInterface + private interface ButtonClickHandler { + void handle(Employee employee); + } +} \ No newline at end of file From 7d6955a5c355b532ae787b6721662a22a9ef049f Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 3 Sep 2024 20:00:09 -0400 Subject: [PATCH 2/4] #7 Perfil de Personal Administrativo - Listado de empleados (correcciones) --- .../primefactorsolutions/model/Employee.java | 8 ---- .../service/EmployeeService.java | 42 +++++++------------ .../views/EmployeesListView.java | 11 ----- 3 files changed, 14 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index 0a8e09d..94fce40 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -21,38 +21,30 @@ private String lastName; private LocalDate birthday; private String birthCity; - @Enumerated(EnumType.STRING) private MaritalStatus maritalStatus; - private String residenceAddress; private String phoneNumber; private String personalEmail; - private String emergencyCName; private String emergencyCAddress; private String emergencyCPhone; private String emergencyCEmail; - @Enumerated(EnumType.STRING) private Status status; - public enum Status { ACTIVE, INACTIVE } - public enum MaritalStatus { SINGLE, MARRIED, WIDOWED, DIVORCED } - public Status getStatus() { return status; } - public void setStatus(Status status) { this.status = status; } diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index 55c2218..da815d9 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -1,5 +1,4 @@ package com.primefactorsolutions.service; - import com.primefactorsolutions.model.Employee; import org.apache.commons.beanutils.BeanComparator; import com.primefactorsolutions.repositories.EmployeeRepository; @@ -16,50 +15,37 @@ import java.util.Collections; @Data public class EmployeeService { private final EmployeeRepository employeeRepository; - private List pagedBase; public EmployeeService(EmployeeRepository employeeRepository) { this.employeeRepository = employeeRepository; } - private void initializePagedBase() { - if (pagedBase == null) { - this.pagedBase = employeeRepository.findAll(); - } - } - public List findEmployees(int start, int pageSize, String sortProperty, boolean asc) { - initializePagedBase(); // Asegurarse de que pagedBase esté inicializada - System.err.println("findAll " + start + " " + pageSize + " sort " + sortProperty + " asc:" + asc ); - int end = (int) (start + pageSize); - if (end > pagedBase.size()) { - end = pagedBase.size(); - } - Collections.sort(pagedBase, new BeanComparator(sortProperty)); + List employees = employeeRepository.findAll(); - if(!asc) { - Collections.reverse(pagedBase); + int end = Math.min(start + pageSize, employees.size()); + employees.sort(new BeanComparator<>(sortProperty)); + + if (!asc) { + Collections.reverse(employees); } - return pagedBase.subList((int) start, end); + + return employees.subList(start, end); } public List findEmployees(int start, int pageSize) { - initializePagedBase(); // Asegurarse de que pagedBase esté inicializada - System.err.println("findAll " + start + " " + pageSize); - int end = (int) (start + pageSize); - if (end > pagedBase.size()) { - end = pagedBase.size(); - } - return pagedBase.subList((int) start, end); + List employees = employeeRepository.findAll(); + + int end = Math.min(start + pageSize, employees.size()); + return employees.subList(start, end); } public Employee createOrUpdate(final Employee employee) { - final Employee saved = employeeRepository.save(employee); - return saved; + return employeeRepository.save(employee); } public Employee getEmployee(final UUID id) { Optional employee = employeeRepository.findById(id); return employee.orElse(null); } -} +} \ No newline at end of file diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 3b0e664..e8adeb4 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -43,22 +43,11 @@ public class EmployeesListView extends Main { private void configureTable() { table.setColumns("firstName", "lastName", "status"); - addStatusColumn(); addEditButtonColumn("Edit", this::navigateToEditView); addEditButtonColumn("Save", this::navigateToSaveChangeStatus); setupPagingGrid(); } - private void addStatusColumn() { - table.addComponentColumn(this::createStatusCheckbox) - .setHeader("Change Status"); - } - - private Checkbox createStatusCheckbox(Employee employee) { - Checkbox statusCheckbox = new Checkbox( employee.getStatus() == Employee.Status.ACTIVE); - return statusCheckbox; - } - private void updateEmployeeStatus(Employee employee, boolean isActive) { employee.setStatus(isActive ? Employee.Status.ACTIVE : Employee.Status.INACTIVE); employeeService.createOrUpdate(employee); From dd95b70c66d042a79b17b79b8433b9da85e8fddc Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 3 Sep 2024 20:11:44 -0400 Subject: [PATCH 3/4] #7 Perfil de Personal Administrativo - Listado de empleados (correcciones v2) --- .../com/primefactorsolutions/views/EmployeesListView.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index e8adeb4..b91c03c 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -3,7 +3,6 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.service.EmployeeService; import com.vaadin.flow.component.button.Button; -import com.vaadin.flow.component.checkbox.Checkbox; import com.vaadin.flow.component.html.H2; import com.vaadin.flow.component.html.Main; import com.vaadin.flow.router.PageTitle; @@ -44,7 +43,6 @@ public class EmployeesListView extends Main { private void configureTable() { table.setColumns("firstName", "lastName", "status"); addEditButtonColumn("Edit", this::navigateToEditView); - addEditButtonColumn("Save", this::navigateToSaveChangeStatus); setupPagingGrid(); } @@ -76,10 +74,6 @@ public class EmployeesListView extends Main { getUI().ifPresent(ui -> ui.navigate(EmployeeView.class, "new")); } - private void navigateToSaveChangeStatus(Employee employee) { - // no-op - } - private void setupPagingGrid() { table.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); table.setPageSize(5); From 49dc6421f52a43c451f1977577fc79673e201b99 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 4 Sep 2024 12:44:47 -0400 Subject: [PATCH 4/4] Correccion de estilo de codigo --- .../primefactorsolutions/model/Employee.java | 10 +++------- .../service/EmployeeService.java | 7 ++++--- .../views/EmployeeView.java | 4 ++-- .../views/EmployeesListView.java | 18 ++++++++++-------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index 94fce40..c6d918b 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -1,16 +1,12 @@ package com.primefactorsolutions.model; - - import io.hypersistence.utils.hibernate.type.json.JsonType; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; - import org.hibernate.annotations.Type; - + import java.time.LocalDate; - import java.util.List; - + @Data @Entity @AllArgsConstructor @@ -45,7 +41,7 @@ public Status getStatus() { return status; } - public void setStatus(Status status) { + public void setStatus(final Status status) { this.status = status; } } diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index da815d9..993eecd 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -16,11 +16,12 @@ import java.util.Collections; public class EmployeeService { private final EmployeeRepository employeeRepository; - public EmployeeService(EmployeeRepository employeeRepository) { + public EmployeeService(final EmployeeRepository employeeRepository) { this.employeeRepository = employeeRepository; } - public List findEmployees(int start, int pageSize, String sortProperty, boolean asc) { + public List findEmployees( + final int start, final int pageSize, final String sortProperty, final boolean asc) { List employees = employeeRepository.findAll(); int end = Math.min(start + pageSize, employees.size()); @@ -33,7 +34,7 @@ public class EmployeeService { return employees.subList(start, end); } - public List findEmployees(int start, int pageSize) { + public List findEmployees(final int start, final int pageSize) { List employees = employeeRepository.findAll(); int end = Math.min(start + pageSize, employees.size()); diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index d2a570e..9e49fe4 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -145,11 +145,11 @@ public class EmployeeView extends BeanValidationForm implements HasUrl setSavedHandler((SavedHandler) employee -> { if (validateForm()) { final Employee saved = employeeService.createOrUpdate(employee); - Notification.show("Empleado guardado exitosamente."); + Notification.show("Employee saved successfully."); getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class)); setEntityWithEnabledSave(saved); } else { - Notification.show("Acción inválida. Por favor, complete todos los campos requeridos correctamente.", 3000, Notification.Position.MIDDLE); + Notification.show("Please complete the required fields correctly.", 3000, Notification.Position.MIDDLE); } }); diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index b91c03c..489ded8 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -27,7 +27,7 @@ public class EmployeesListView extends Main { private final EmployeeService employeeService; private final PagingGrid table = new PagingGrid<>(Employee.class); - public EmployeesListView(EmployeeService employeeService) { + public EmployeesListView(final EmployeeService employeeService) { this.employeeService = employeeService; setupView(); refreshGrid(); @@ -46,17 +46,17 @@ public class EmployeesListView extends Main { setupPagingGrid(); } - private void updateEmployeeStatus(Employee employee, boolean isActive) { + private void updateEmployeeStatus(final Employee employee, final boolean isActive) { employee.setStatus(isActive ? Employee.Status.ACTIVE : Employee.Status.INACTIVE); employeeService.createOrUpdate(employee); refreshGrid(); } - private void addEditButtonColumn(String label, ButtonClickHandler handler) { + private void addEditButtonColumn(final String label, final ButtonClickHandler handler) { table.addComponentColumn(employee -> createButton(label, () -> handler.handle(employee))); } - private Button createButton(String label, Runnable onClickAction) { + private Button createButton(final String label, final Runnable onClickAction) { Button button = new Button(label); button.addClickListener(event -> onClickAction.run()); return button; @@ -66,7 +66,7 @@ public class EmployeesListView extends Main { return createButton("Add Employee", this::navigateToAddEmployeeView); } - private void navigateToEditView(Employee employee) { + private void navigateToEditView(final Employee employee) { getUI().ifPresent(ui -> ui.navigate(EmployeeView.class, employee.getId().toString())); } @@ -83,7 +83,7 @@ public class EmployeesListView extends Main { table.setPagingDataProvider((page, pageSize) -> fetchEmployees((int) page, pageSize)); } - private List fetchEmployees(int page, int pageSize) { + private List fetchEmployees(final int page, final int pageSize) { int start = page * pageSize; if (hasSortOrder()) { return fetchSortedEmployees(start, pageSize); @@ -95,9 +95,11 @@ public class EmployeesListView extends Main { return !table.getSortOrder().isEmpty(); } - private List fetchSortedEmployees(int start, int pageSize) { + private List fetchSortedEmployees(final int start, final int pageSize) { GridSortOrder sortOrder = table.getSortOrder().getFirst(); - return employeeService.findEmployees(start, pageSize, sortOrder.getSorted().getKey(), sortOrder.getDirection() == SortDirection.ASCENDING); + return employeeService.findEmployees(start, pageSize, + sortOrder.getSorted().getKey(), + sortOrder.getDirection() == SortDirection.ASCENDING); } @FunctionalInterface