use of com.liferay.faces.util.model.Sortable in project liferay-faces-alloy by liferay.
the class DataTableRenderer method decodeSortCriteria.
protected void decodeSortCriteria(FacesContext facesContext, Map<String, String> requestParameterMap, DataTable dataTable, String dataTableClientId) {
Object dataTableValue = dataTable.getValue();
if ((dataTableValue != null) && (dataTableValue instanceof Sortable)) {
String sortColumnClientIdParamName = dataTableClientId.concat("_sortColumnClientId");
String sortColumnClientId = requestParameterMap.get(sortColumnClientIdParamName);
if (sortColumnClientId != null) {
List<Column> alloySortColumns = new ArrayList<Column>();
String eventMetaKeyParamName = dataTableClientId.concat("_eventMetaKey");
boolean eventMetaKey = BooleanHelper.toBoolean(requestParameterMap.get(eventMetaKeyParamName));
boolean multiColumnSort = dataTable.isMultiColumnSort();
List<UIComponent> children = dataTable.getChildren();
for (UIComponent child : children) {
if (child instanceof Column) {
Column alloyColumn = (Column) child;
String alloyColumndId = alloyColumn.getClientId(facesContext);
String alloyColumnSortOrder = alloyColumn.getSortOrder();
Map<String, Object> alloyColumnAttributes = alloyColumn.getAttributes();
if (alloyColumndId.equals(sortColumnClientId)) {
// Toggle the value from ascending->descending or from descending->ascending.
SortCriterion.Order sortCriterionOrder;
if ("ASCENDING".equals(alloyColumnSortOrder)) {
sortCriterionOrder = SortCriterion.Order.DESCENDING;
} else {
sortCriterionOrder = SortCriterion.Order.ASCENDING;
}
// Set the state of the column so that the sort indicator will appear correctly.
alloyColumn.setSortOrder(sortCriterionOrder.toString());
alloyColumnAttributes.put("sortTime", System.currentTimeMillis());
// Add the sort criterion to the list of sort criteria.
alloySortColumns.add(alloyColumn);
} else {
if (multiColumnSort && eventMetaKey) {
if (alloyColumnSortOrder != null) {
alloySortColumns.add(alloyColumn);
}
} else {
alloyColumn.setSortOrder(null);
alloyColumnAttributes.remove("sortTime");
}
}
}
}
Collections.sort(alloySortColumns, new ColumnSortTimeComparator());
List<SortCriterion> sortCriteria = new ArrayList<SortCriterion>();
for (Column alloyColumn : alloySortColumns) {
String alloyColumnFieldName = getAlloyColumnFieldName(alloyColumn);
String alloyColumnSortOrder = alloyColumn.getSortOrder();
SortCriterion.Order sortCriterionOrder;
if ("ASCENDING".equals(alloyColumnSortOrder)) {
sortCriterionOrder = SortCriterion.Order.ASCENDING;
} else {
sortCriterionOrder = SortCriterion.Order.DESCENDING;
}
SortCriterion sortCriterion = new SortCriterion(alloyColumnFieldName, sortCriterionOrder);
sortCriteria.add(sortCriterion);
}
if (logger.isDebugEnabled()) {
for (SortCriterion sortCriterion : sortCriteria) {
logger.debug("sortCriterion columnId=[{0}], order=[{1}]", sortCriterion.getColumnId(), sortCriterion.getOrder());
}
}
Sortable sortable = (Sortable) dataTableValue;
sortable.setSortCriteria(sortCriteria);
}
}
}
Aggregations