package be.iminds.ilabt.jfed.experimenter_gui.call_gui;

import be.iminds.ilabt.jfed.highlevel.controller.JavaFXTaskThread;
import be.iminds.ilabt.jfed.ui.javafx.FXMLUtil;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;

/**
 * CallList
 */
public class TaskList extends ListView<JavaFXTaskThread.FXTaskExecution> {
    public TaskList() {
        FXMLUtil.injectFXML(this);

        this.setCellFactory(callListView -> new CallCell());

    }

    private static class CallCell extends ListCell<JavaFXTaskThread.FXTaskExecution> {
        private final TaskLabel label = new TaskLabel();

        @Override
        public void updateItem(final JavaFXTaskThread.FXTaskExecution item, boolean empty) {
            super.updateItem(item, empty);

            if (item == null) {
                label.setTask(null);
                setGraphic(null);
            } else {
                label.setTask(item);
                setGraphic(label);
            }
        }
    }
}
