fix table column bindings using lambdas

This commit is contained in:
2026-04-09 23:18:14 -06:00
parent e3eaeb0b99
commit ff97839cb7

View File

@@ -13,7 +13,6 @@ import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Modality;
import javafx.stage.Stage;
import org.example.petshopdesktop.api.dto.user.UserResponse;
@@ -69,25 +68,13 @@ public class StaffAccountsController {
@FXML
public void initialize() {
colUsername.setCellValueFactory(new PropertyValueFactory<>("username"));
colName.setCellValueFactory(new PropertyValueFactory<>("fullName"));
colEmail.setCellValueFactory(new PropertyValueFactory<>("email"));
colPhone.setCellValueFactory(new PropertyValueFactory<>("phone"));
colRole.setCellValueFactory(new PropertyValueFactory<>("role"));
colStatus.setCellValueFactory(new PropertyValueFactory<>("active"));
colStatus.setCellFactory(column -> new javafx.scene.control.TableCell<UserResponse, String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty || getTableRow() == null || getTableRow().getItem() == null) {
setText(null);
} else {
Boolean active = getTableRow().getItem().getActive();
setText(active != null && active ? "Active" : "Inactive");
}
}
});
colCreated.setCellValueFactory(new PropertyValueFactory<>("createdAt"));
colUsername.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getUsername()));
colName.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getFullName()));
colEmail.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getEmail()));
colPhone.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getPhone()));
colRole.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getRole()));
colStatus.setCellValueFactory(data -> new javafx.beans.property.SimpleStringProperty(data.getValue().getActive() != null && data.getValue().getActive() ? "Active" : "Inactive"));
colCreated.setCellValueFactory(data -> new javafx.beans.property.SimpleObjectProperty<>(data.getValue().getCreatedAt()));
filtered = new FilteredList<>(staffAccounts, a -> true);
tvStaff.setItems(filtered);