org.wicketstuff.egrid.toolbar.EditableGridHeadersToolbar Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wicketstuff-editable-grid Show documentation
Show all versions of wicketstuff-editable-grid Show documentation
Add/Edit/Delete functionality all at once
package org.wicketstuff.egrid.toolbar;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortStateLocator;
import org.apache.wicket.extensions.markup.html.repeater.data.sort.OrderByBorder;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IStyledColumn;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.RefreshingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.wicketstuff.egrid.component.EditableDataTable;
import org.wicketstuff.egrid.component.EditableDataTable.CssAttributeBehavior;
/**
*
* @author Nadeem Mohammad
*
*/
public class EditableGridHeadersToolbar extends AbstractEditableGridToolbar
{
private static final long serialVersionUID = 1L;
/**
* Constructor
*
* @param
* the column data type
* @param table
* data table this toolbar will be attached to
* @param stateLocator
* locator for the ISortState implementation used by sortable headers
*/
public EditableGridHeadersToolbar(final EditableDataTable table, final ISortStateLocator stateLocator)
{
super(table);
RefreshingView> headers = new RefreshingView>("headers")
{
private static final long serialVersionUID = 1L;
@Override
protected Iterator>> getItemModels()
{
List>> columnsModels = new LinkedList>>();
for (IColumn column : table.getColumns())
{
columnsModels.add(Model.of(column));
}
return columnsModels.iterator();
}
@Override
protected void populateItem(Item> item)
{
final IColumn column = item.getModelObject();
WebMarkupContainer header = null;
if (column.isSortable())
{
header = newSortableHeader("header", column.getSortProperty(), stateLocator);
}
else
{
header = new WebMarkupContainer("header");
}
if (column instanceof IStyledColumn)
{
CssAttributeBehavior cssAttributeBehavior = new EditableDataTable.CssAttributeBehavior()
{
private static final long serialVersionUID = 1L;
@Override
protected String getCssClass()
{
return ((IStyledColumn, S>)column).getCssClass();
}
};
header.add(cssAttributeBehavior);
}
item.add(header);
item.setRenderBodyOnly(true);
header.add(column.getHeader("label"));
}
};
add(headers);
}
/**
* Factory method for sortable header components. A sortable header component must have id of
* headerId
and conform to markup specified in HeadersToolbar.html
*
* @param headerId
* header component id
* @param property
* property this header represents
* @param locator
* sort state locator
* @return created header component
*/
protected WebMarkupContainer newSortableHeader(final String headerId, final S property, final ISortStateLocator locator)
{
return new OrderByBorder(headerId, property, locator)
{
private static final long serialVersionUID = 1L;
@Override
protected void onSortChanged()
{
getTable().setCurrentPage(0);
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy