package org.javafxdata.control.cell;

import javafx.scene.control.ProgressBar;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;

/**
 * A class containing cell factories that use {@link ProgressBar progress bars}. 
 * Be sure to read the API documentation for each static method before using it!
 * 
 * @author <a href="http://www.jonathangiles.net">Jonathan Giles</a>
 */
public class ProgressBarCellFactory {
    
    private ProgressBarCellFactory() { }
    
    /**
     * Provides a {@link ProgressBar} that allows easy visualisation of a Number value
     * as it proceeds from 0.0 to 1.0. If the value is -1, the progress bar will
     * appear indeterminate.
     * 
     * @return A {@link Callback} that can be inserted into the {@link TableColumn#cellFactoryProperty() cell
     *      factory property} of a TableColumn, that enables visualisation of a Number
     *      as it progresses from 0.0 to 1.0.
     */
    public static <S> Callback<TableColumn<S,Number>, TableCell<S,Number>> forTableColumn() {
        return new Callback<TableColumn<S, Number>, TableCell<S, Number>>() {
            @Override public TableCell<S, Number> call(TableColumn<S, Number> param) {
                return new ProgressBarTableCell<S, Number>();
            }
        };
    }
}
