<commit_before>package ui.components.pickers;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Pos;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.util.Callback;
import javafx.util.StringConverter;

/**
 * Mostly a copy of CheckBoxListCell
 */

public class LabelPickerCell extends ListCell<LabelPicker.Label> {

    private final CheckBox checkBox;
    private ObservableValue<Boolean> booleanProperty;
    private ObjectProperty<Callback<LabelPicker.Label, ObservableValue<Boolean>>>
            selectedStateCallback =
            new SimpleObjectProperty<>(
                    this, "selectedStateCallback");
    private ObjectProperty<StringConverter<LabelPicker.Label>> converter =
            new SimpleObjectProperty<>(this, "converter");

    public static Callback<ListView<LabelPicker.Label>, ListCell<LabelPicker.Label>> forListView(
            final Callback<LabelPicker.Label, ObservableValue<Boolean>> getSelectedProperty,
            final StringConverter<LabelPicker.Label> converter) {
        return list -> new LabelPickerCell(getSelectedProperty, converter);
    }

    public LabelPickerCell(
            final Callback<LabelPicker.Label, ObservableValue<Boolean>> getSelectedProperty,
            final StringConverter<LabelPicker.Label> converter) {
        this.getStyleClass().add("check-box-list-cell");
        setSelectedStateCallback(getSelectedProperty);
        setConverter(converter);

        this.checkBox = new CheckBox();

        setAlignment(Pos.CENTER_LEFT);
        setContentDisplay(ContentDisplay.LEFT);

        // by default the graphic is null until the cell stops being empty
        setGraphic(null);
    }

    @Override public void updateItem(LabelPicker.Label item, boolean empty) {
        super.updateItem(item, empty);

        if (!empty) {
            StringConverter<LabelPicker.Label> c = getConverter();
            Callback<LabelPicker.Label, ObservableValue<Boolean>> callback = getSelectedStateCallback();
            if (callback == null) {
                throw new NullPointerException(
                        "The CheckBoxListCell selectedStateCallbackProperty can not be null");
            }
<commit_msg>LabelPickerCell now supports toggling of selection when clicked<commit_after>package ui.components.pickers;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Pos;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.util.Callback;
import javafx.util.StringConverter;

/**
 * Mostly a copy of CheckBoxListCell
 */

public class LabelPickerCell extends ListCell<LabelPicker.Label> {

    private final CheckBox checkBox;
    private ObservableValue<Boolean> booleanProperty;
    private ObjectProperty<Callback<LabelPicker.Label, ObservableValue<Boolean>>>
            selectedStateCallback =
            new SimpleObjectProperty<>(
                    this, "selectedStateCallback");
    private ObjectProperty<StringConverter<LabelPicker.Label>> converter =
            new SimpleObjectProperty<>(this, "converter");
    private LabelPicker.Label item;

    public static Callback<ListView<LabelPicker.Label>, ListCell<LabelPicker.Label>> forListView(
            final Callback<LabelPicker.Label, ObservableValue<Boolean>> getSelectedProperty,
            final StringConverter<LabelPicker.Label> converter) {
        return list -> new LabelPickerCell(getSelectedProperty, converter);
    }

    public LabelPickerCell(
            final Callback<LabelPicker.Label, ObservableValue<Boolean>> getSelectedProperty,
            final StringConverter<LabelPicker.Label> converter) {
        this.getStyleClass().add("check-box-list-cell");
        setSelectedStateCallback(getSelectedProperty);
        setConverter(converter);

        this.checkBox = new CheckBox();

        setAlignment(Pos.CENTER_LEFT);
        setContentDisplay(ContentDisplay.LEFT);

        // by default the graphic is null until the cell stops being empty
        setGraphic(null);

        setOnMouseClicked(e -> {
            item.toggleChecked();
            updateItem(item, false);
        });
    }

    @Override public void updateItem(LabelPicker.Label item, boolean empty) {
        super.updateItem(item, empty);

        if (!empty) {
            this.item = item;
            StringConverter<LabelPicker.Label> c = getConverter();
            Callback<LabelPicker.Label, ObservableValue<Boolean>> callback = getSelectedStateCallback();
            if (callback == null) {
                throw new NullPointerException(
                        "The CheckBoxListCell selectedStateCallbackProperty can not be null");
            }

{'fraction_non_alphanumeric': 0.08690591658583899, 'fraction_numerical': 0.0, 'mean_word_length': 3.4371772805507743, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6537820', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1244, 'n_words': 282}