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

org.wicketstuff.lambda.table.FunctionColumn Maven / Gradle / Ivy

The newest version!
package org.wicketstuff.lambda.table;

import java.util.function.Function;

import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.LambdaColumn;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.wicketstuff.lambda.SerializableFunction;
import org.wicketstuff.lambda.model.LambdaModel;

/**
 * {@link AbstractColumn} where the {@link IModel} of a cell is provided by
 * applying a {@code dataFunction} to the {@link IModel} of the row.
 *
 * @param 
 *            - the type of the row
 * @param 
 *            - the type of the sort property
 * @param 
 *            - type type of the cell
 *            
 * @deprecated use {@link LambdaColumn} instead
 */
public class FunctionColumn extends AbstractColumn {

	/*
	 * Function that generates the model of the cell from the model of the row.
	 */
	private SerializableFunction dataFunction;

	/**
	 * @param displayModel
	 *            model used to generate header text
	 * @param dataFunction
	 *            function that generates the model of the cell from the model
	 *            of the row
	 */
	public FunctionColumn(IModel displayModel, Function dataFunction) {
		this(displayModel, dataFunction, null);
	}

	/**
	 * @param displayModel
	 *            model used to generate header text
	 * @param dataFunction
	 *            function that generates the model of the cell from the model
	 *            of the row
	 * @param sortProperty
	 *            sort property this column represents
	 */
	public FunctionColumn(IModel displayModel, Function dataFunction, S sortProperty) {
		super(displayModel, sortProperty);
		this.dataFunction = (SerializableFunction) dataFunction;
	}

	@Override
	public void populateItem(Item> cellItem, String componentId, IModel rowModel) {
		cellItem.add(new Label(componentId, getDataModel(rowModel)));
	}

	/**
	 * Returns the model for the cell from the model of the row.
	 * 
	 * @param rowModel
	 *            {@link IModel} of the row
	 * @return the model of the cell
	 */
	protected IModel getDataModel(IModel rowModel) {
		return new LambdaModel<>(rowModel, dataFunction);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy