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