package com.imyeyu.fx.ui.components.table;

import com.imyeyu.fx.ui.TimiFXUI;
import javafx.beans.property.StringProperty;
import javafx.scene.control.TextField;
import javafx.scene.layout.Border;

/**
 * 表格可编辑单元格，相对原始的可编辑效果，此单元格没有输入框的样式，就像 Excel 那样
 *
 * <pre>
 * TableColumn&lt;String, String&gt; col = new TableColumn&lt;&gt;("col");
 * col.setCellFactory(cell -&gt; new TextFieldTableCell&lt;&gt;() {
 *
 *     &#064;Override
 *     protected StringProperty property(Item item) {
 *         // 给出此可编辑单元格的具体映射属性
 *         return item.valueProperty();
 *     }
 * });
 * </pre>
 *
 * @author 夜雨
 * @since 2022-05-09 22:21
 */
public abstract class TextFieldTableCell<S> extends BindingTableCell<S, String, StringProperty, TextField> implements TimiFXUI {

	@Override
	protected final TextField component() {
		TextField textField = new TextField();
		textField.setBorder(Border.EMPTY);
		return textField;
	}

	@Override
	protected final StringProperty componentValue(TextField textField) {
		return textField.textProperty();
	}
}
