package Controllers.Traitement;

import javafx.collections.ObservableList;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.text.Text;
import javafx.util.Callback;

/**
 * @author Maher Ben Tili
 */
public class TotalHeightTableColumn {
    
    public TableView<Object> tableView = new TableView<>();
    
    public float columnWidth;
    
    public TotalHeightTableColumn(float colwidth) 
    {
        columnWidth = colwidth;
        
        tableView.setEditable(true);
    }
    
    public float getTotalHeight(ObservableList<Object> data)
    {
        float total = 0;
        
        TableColumn Col = new TableColumn("First Name");
        
        Col.setMinWidth(columnWidth);
        
        Col.setCellValueFactory(new PropertyValueFactory<Object, String>("firstcolumn"));
        
        Col.setCellFactory(new Callback<TableColumn<Object, String>,TableCell<Object, String>>(){        
            @Override
            public TableCell<Object, String> call(TableColumn<Object, String> param) {                
                TableCell<Object, String> cell = new TableCell<Object, String>(){
                    @Override
                    public void updateItem(String item, boolean empty) {
                        
                        if (item == null) {
                            super.setText(null);
                            super.setGraphic(null);
                        } else {
                            Text text = new Text(item);
                            text.wrappingWidthProperty().bind(super.widthProperty());
                            super.setGraphic(text);
                            
                            //Person perss = ((Person)getTableRow().getItem());
                        
                            /*;System.out.println(perss.getFirstName());
                            System.out.println(item);
                            System.out.println(text.getLayoutBounds().getHeight());
                            System.out.println("===============");*/
                         
                        }
                    }
                };  
                return cell;
            }
        });
        
        tableView.setItems(data);
        tableView.getColumns().addAll(Col);
        
        return total;
    }
    
}
