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

org.wicketstuff.egrid.column.AbstractEditablePropertyColumn Maven / Gradle / Ivy

There is a newer version: 10.3.0
Show newest version
package org.wicketstuff.egrid.column;

import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
/**
 * 
 * @author Nadeem Mohammad
 *
 */
public abstract class AbstractEditablePropertyColumn extends PropertyColumn implements IEditableGridColumn
{

	private static final long serialVersionUID 	= 1L;
	private boolean isEditable 					= true;

	public AbstractEditablePropertyColumn(IModel displayModel, String propertyExpression)
	{
		super(displayModel, propertyExpression);		
	}
	
	public AbstractEditablePropertyColumn(IModel displayModel, String propertyExpression, boolean isEditable)
	{
		super(displayModel, propertyExpression);
		this.isEditable = isEditable;
	}

	@SuppressWarnings("unchecked")
	@Override
	public final void populateItem(final Item> item, final String componentId, final IModel rowModel)
	{

		final Item rowItem = ((Item) item.findParent(Item.class));
		
		if (inEditiingMode(rowItem) && isEditable)
		{
			EditableCellPanel provider 			= getEditableCellPanel(componentId);
			FormComponent editorComponent 	= provider.getEditableComponent();
			editorComponent.setDefaultModel((IModel) getDataModel(rowModel));
			item.add(provider);
		}
		else 
		{
			super.populateItem(item, componentId, rowModel);
		}		
	}

	private boolean inEditiingMode(Item rowItem)
	{
		return rowItem.getMetaData(EditableGridActionsPanel.EDITING);
	}
	 
	protected void addBehaviors(FormComponent editorComponent) 
	{

	}	
}