boolean filtering = false;
boolean isGroupingOn = table.isGroupingOn();
boolean sortByGroupingColumn = false;
// String groupingColumnId = null;
UIColumn groupingColumn = null;
if (isGroupingOn) {
groupingColumn = table.getGroupByColumn();
sortByGroupingColumn = (groupingColumn == null ? false
: groupingColumn.getClientId(context).equals(
sortColumnId));
// groupingColumnId = table.getGroupingColumnId();
}
for (Iterator<UIColumn> columns = table.getChildColumns(); columns
.hasNext();) {
UIColumn column = columns.next();
String id = column.getId();
column.setId(id);
if (sortColumnId != null) {
sorting = true;
boolean isGroupingColumn = (isGroupingOn && column
.equals(groupingColumn));
if (sortColumnId.equals(column.getClientId(context))) {
// set sort order
if (map.containsKey(SORT_DIR_PARAMETER)) {
String sortDir = (String) map
.get(SORT_DIR_PARAMETER);
column
.setSortOrder((sortDir
.equals(SORT_DIR_PARAMETER_ASC) ? Ordering.ASCENDING
: (sortDir
.equals(SORT_DIR_PARAMETER_DESC) ? Ordering.DESCENDING
: Ordering.UNSORTED)));
} else {
column.toggleSortOrder();
}
Collection<Object> sortPriority = table
.getSortPriority();
// clear sort priority in case of single sort mode
if (isSingleSortMode) {
sortPriority.clear();
}
// add column to sort priority if is not added yet
if (!sortPriority.contains(id)) {
sortPriority.add(id);
}
if (isGroupingColumn) {
// set as grouping column to mark that grouping
// order has changed
table.setGroupByColumn(column);
}
} else if (isSingleSortMode) { // in case of single
// sort mode
if (!isGroupingColumn) { // grouping is not by
// this column
if (!sortByGroupingColumn) {// sort not by
// grouping column
// disable sort by this column
column.setSortOrder(Ordering.UNSORTED);
}
}
}
}
UIInput filterValueInput = (UIInput) column
.getFacet(FILTER_INPUT_FACET_NAME);
if (null != filterValueInput) {
filterValueInput.decode(context);
String oldFilterValue = column.getFilterValue();
Object submittedValue = filterValueInput
.getSubmittedValue();
String newFilterValue = null;
if (null != submittedValue) {
newFilterValue = filterValueInput
.getSubmittedValue().toString();
if ((newFilterValue != null)
&& (newFilterValue.length() == 0)) {
newFilterValue = null;
}
column.setFilterValue(newFilterValue);
}
boolean filterChanged = (newFilterValue == null ? (oldFilterValue != null)
: !newFilterValue.equals(oldFilterValue));
// if (filterChanged) {
// //set focus on changed field
// AjaxContext.getCurrentInstance().getResponseDataMap().put(AjaxActionComponent.FOCUS_DATA_ID, filterValueInput.getClientId(context));
// }
filtering = (filtering || filterChanged);
}
}
// AjaxContext.getCurrentInstance().addComponentToAjaxRender(component);
if (sorting){
new ExtTableSortEvent(component).queue();
}
if (filtering){
new ExtTableFilterEvent(component).queue();
}
}
// GROUP COLUMNS
if (GROUP_FILTER_PARAMETER.equals(map.get(clientId))) {
String groupColumnId = map.get(GROUP_FILTER_PARAMETER);
// turn off grouping
table.disableGrouping();
if (groupColumnId != null) {
// turn off sorting by all columns
table.getSortPriority().clear();
for (Iterator<UIColumn> columns = table.getChildColumns(); columns
.hasNext();) {
UIColumn column = columns.next();
// child.setId(child.getId());
if (groupColumnId.equals(column.getClientId(context))) { // group
// by
// this
// column
// set sort order if is not set
if (column.getSortOrder().equals(Ordering.UNSORTED)) {
column.setSortOrder(Ordering.ASCENDING);
}
// set as grouping column
table.setGroupByColumn(column);
} else { // grouping is not by this column
// turn off sorting by this column
column.setSortOrder(Ordering.UNSORTED);
}
}// for columns
}// if
// AjaxContext.getCurrentInstance().addComponentToAjaxRender(component);