/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers.User;

import Models.User.ListUserDB;
import Models.User.ListUsers;

import java.net.URL;
import java.util.ResourceBundle;


import javafx.collections.ObservableList;

import javafx.event.EventHandler;
import javafx.fxml.FXML;

import javafx.fxml.Initializable;

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.scene.input.KeyEvent;


/**
 * FXML Controller class
 * @author Maher Ben Tili
 */
public class GestionUtilisateurController implements Initializable {
    
    @FXML
    private TableView<ListUsers> TableViewListUsers;
    
    @FXML
    private TableColumn<ListUsers ,Integer> id;
    @FXML
    private TableColumn<ListUsers ,String> type;
    @FXML
    private TableColumn<ListUsers ,String> login;
    @FXML
    private TableColumn<ListUsers ,String> nom;
    @FXML
    private TableColumn<ListUsers ,String> prenom;
    @FXML
    private TableColumn<ListUsers ,Integer> tele;
    
    @FXML
    private Label count ;
    
    @FXML
    private TextField rechercher;
    
    ListUserDB DataListe = new ListUserDB();
    
    ObservableList<ListUsers> data = DataListe.getdata();
    
    private void RechercerAction(){
        
            rechercher.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
            @Override
            public void handle(KeyEvent event) {
                ObservableList<ListUsers> data = DataListe.rechercheData(rechercher.getText());
                TableViewListUsers.setItems(data);
            
            }});
        
        
    }
   
    @Override
    public void initialize(URL url, ResourceBundle rb){
        
        id.setCellValueFactory(new PropertyValueFactory<ListUsers, Integer>("id"));
        type.setCellValueFactory(new PropertyValueFactory<ListUsers, String>("type"));
        login.setCellValueFactory(new PropertyValueFactory<ListUsers, String>("login"));
        nom.setCellValueFactory(new PropertyValueFactory<ListUsers, String>("nom"));
        prenom.setCellValueFactory(new PropertyValueFactory<ListUsers, String>("prenom"));
        tele.setCellValueFactory(new PropertyValueFactory<ListUsers, Integer>("tele"));
        TableViewListUsers.setItems(data);
        count.setText(DataListe.nbrUsers());
        
        this.RechercerAction();
    }    
    
}
