All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.rpgframework.jfx.NumericalValueTableCell Maven / Gradle / Ivy

package de.rpgframework.jfx;

import java.util.function.Function;

import de.rpgframework.genericrpg.NumericalValue;
import de.rpgframework.genericrpg.NumericalValueController;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.control.TableCell;

/**
 * @author Stefan
 *
 * T = Type (e.g. Attribute), C = ValueType (e.g. AttributeValue), R = RowType
 */
public class NumericalValueTableCell> extends TableCell {

	private ObjectProperty> ctrl;
	/**
	 * Use table cell value instead of NumericalValue
	 */
	private boolean useItem;
	private Function visibilityCallback;

	//--------------------------------------------------------------------
	public NumericalValueTableCell(ObjectProperty> ctrl, Function visibilityCallback) {
		this.ctrl = ctrl;
		this.visibilityCallback = visibilityCallback;
	}

	//--------------------------------------------------------------------
	public NumericalValueTableCell(ObjectProperty> ctrl) {
		this.ctrl = ctrl;
	}

	//--------------------------------------------------------------------
	public NumericalValueTableCell(NumericalValueController data) {
		this.ctrl = new SimpleObjectProperty>(data);
	}

	//--------------------------------------------------------------------
	public NumericalValueTableCell(NumericalValueController data, boolean useItem) {
		this.ctrl = new SimpleObjectProperty>(data);
		this.useItem = useItem;
	}

	//--------------------------------------------------------------------
	public NumericalValueTableCell(NumericalValueController data, Function visibilityCallback) {
		this.ctrl = new SimpleObjectProperty>(data);
		this.visibilityCallback = visibilityCallback;
	}

	//--------------------------------------------------------------------
	/**
	 * @see javafx.scene.control.Cell#updateItem(java.lang.Object, boolean)
	 */
	@Override
	public void updateItem(Number item, boolean empty) {
		super.updateItem(item, empty);

		if (empty) {
			setGraphic(null);
		} else {
			if (getTableRow()!=null && getTableRow().getItem()!=null) {
				NumericalValueField val = new NumericalValueField( ()->getTableRow().getItem(), ctrl.get());
				val.setController(ctrl.get());
				if (useItem) {
//					val.setOverrideValue((Integer) item);

					val.refresh();
				}
				setGraphic(val);

				if (visibilityCallback==null) {
					setVisible(true);
				} else {
					setVisible(visibilityCallback.apply(getTableRow().getItem()));
				}
			}
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy