package org.javafxdata.control.cell;

import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyBooleanWrapper;
import javafx.scene.control.TableCell;

/**
 *
 * @author Jonathan Giles
 */
public class ExpandingTableCell<S,T> extends TableCell<S,T> {
    
    private int lastExpandedIndex = -1;
    
    private ReadOnlyBooleanWrapper expandedProperty = new ReadOnlyBooleanWrapper(this, "expanded");
    public final ReadOnlyBooleanProperty expandedProperty() { return expandedProperty.getReadOnlyProperty(); }
    public final boolean isExpanded() { return expandedProperty.get(); }
    private final void setExpanded(boolean e) { expandedProperty.set(e); }
    
    public void updateExpanded(boolean isExpanded) {
        setExpanded(isExpanded);
    }

//    @Override protected void updateItem(T item, boolean empty) {
//        super.updateItem(item, empty);
//        setText(item == null ? "" : item.toString());
//    }

    @Override public void updateIndex(int i) {
        int oldIndex = getIndex();
        super.updateIndex(i);
        
        updateExpanded(oldIndex == i || i == lastExpandedIndex);
    }
}
