ContentEntryRowFactory.java

package ui.assembly64;

import javafx.beans.property.ObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.WeakChangeListener;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.Tooltip;
import javafx.util.Callback;

public class ContentEntryRowFactory implements Callback<TableView<ContentEntry>, TableRow<ContentEntry>> {
    private static final String CURRENTLY_PLAYED_FILE_ROW = "currentlyPlayedRow";

    private ObjectProperty<ContentEntry> currentlyPlayedContentEntryProperty;

    public ObjectProperty<ContentEntry> getCurrentlyPlayedContentEntryProperty() {
        return currentlyPlayedContentEntryProperty;
    }

    public void setCurrentlyPlayedContentEntryProperty(ObjectProperty<ContentEntry> currentlyPlayedHVSCEntryProperty) {
        this.currentlyPlayedContentEntryProperty = currentlyPlayedHVSCEntryProperty;
    }

    @Override
    public TableRow<ContentEntry> call(final TableView<ContentEntry> p) {
        return new TableRow<ContentEntry>() {
            private final ChangeListener<ContentEntry> listener = (observable, oldValue,
                                                                   newValue) -> getTableView().refresh();

            {
                currentlyPlayedContentEntryProperty.addListener(new WeakChangeListener<>(listener));
            }

            @Override
            public void updateItem(ContentEntry item, boolean empty) {
                super.updateItem(item, empty);
                setTooltip(item != null ? new Tooltip(getItem().getPath()) : null);

                getStyleClass().remove(CURRENTLY_PLAYED_FILE_ROW);
                if (!isEmpty() && currentlyPlayedContentEntryProperty.get() != null
                        && item == currentlyPlayedContentEntryProperty.get()) {
                    getStyleClass().add(CURRENTLY_PLAYED_FILE_ROW);
                }
            }
        };
    }
}