public class RowGroupingRenderer extends RendererBase {
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
super.encodeBegin(context, component);
RowGrouping rowGrouping = (RowGrouping) component;
UIComponent parent = rowGrouping.getParent();
if (!(parent instanceof DataTable))
throw new IllegalStateException("<o:columnResizing> can only be placed as a child component inside of " +
"a <o:dataTable> component. Though the following parent component has been encountered: " +
parent.getClass().getName());
DataTable table = (DataTable) rowGrouping.getParent();
TableStructure tableStructure = TableStructure.getCurrentInstance(table);
Set<BaseColumn> visibleAndGroupedColumns = new LinkedHashSet<BaseColumn>(tableStructure.getColumns());
List<GroupingRule> groupingRules = rowGrouping.getGroupingRules();
if (groupingRules != null)
for (GroupingRule groupingRule : groupingRules) {
String columnId = groupingRule.getColumnId();
BaseColumn column = table.getColumnById(columnId);
visibleAndGroupedColumns.add(column);
}
String tableClientId = table.getClientId(context);
List<String> activeColumnIds = new ArrayList<String>();
List<String> groupableColumnIds = new ArrayList<String>();
for (BaseColumn column : visibleAndGroupedColumns) {
Object headerContent = TableHeader.getHeaderOrFooterCellContent(column, true);
HeaderCell cell = new HeaderCell(column, headerContent, "div",
CellKind.COL_HEADER, true, HeaderCell.SortingToggleMode.AUTODETECT);
String columnId = column.getId();
activeColumnIds.add(columnId);
cell.setId(tableClientId + "::groupingHeaderCell:" + columnId);
cell.setTableStructure(tableStructure);
cell.render(context, null);
if (column.isColumnGroupable())
groupableColumnIds.add(columnId);
}
ScriptBuilder buf = new ScriptBuilder();
boolean foldingRequired = AbstractTableRenderer.encodeFoldingSupport(context, buf, table);
Rendering.renderInitScript(context, buf.initScript(context, table, "O$.Table._initRowGrouping",
activeColumnIds,
groupableColumnIds,
groupingRules,
AbstractTableRenderer.DEFAULT_SORTABLE_HEADER_CLASS,
rowGrouping.getGroupOnHeaderClick(),
rowGrouping.getHideGroupingColumns()
).semicolon(), foldingRequired
? new String[]{AbstractTableRenderer.treeTableJsURL(context)}
: new String[0]);
}