Author: maksimkaszynski
Date: 2007-09-28 12:34:32 -0400 (Fri, 28 Sep 2007)
New Revision: 3167
Added:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/AbstractSortListener.java
Modified:
trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/MultiColumnSortListener.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/SingleColumnSortListener.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/ScrollableDataTableBaseRenderer.java
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/GridHeader.js
Log:
http://jira.jboss.com/jira/browse/RF-1037
Modified: trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent.java 2007-09-28
16:20:16 UTC (rev 3166)
+++ trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent.java 2007-09-28
16:34:32 UTC (rev 3167)
@@ -13,7 +13,6 @@
import javax.faces.component.UIComponent;
import javax.faces.event.FacesListener;
-import org.richfaces.event.AttributedEvent;
import org.richfaces.event.ScrollableGridViewEvent;
/**
@@ -27,6 +26,8 @@
private int sortColumn;
+ private Boolean suggestedOrder = null;
+
public SortEvent(UIComponent component, int sortColumn, int rows, int first) {
super(component, rows, first);
@@ -59,4 +60,12 @@
public void setSortColumn(int sortColumn) {
this.sortColumn = sortColumn;
}
+
+ public Boolean getSuggestedOrder() {
+ return suggestedOrder;
+ }
+
+ public void setProposedOrder(Boolean proposedOrder) {
+ this.suggestedOrder = proposedOrder;
+ }
}
Added:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/AbstractSortListener.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/AbstractSortListener.java
(rev 0)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/AbstractSortListener.java 2007-09-28
16:34:32 UTC (rev 3167)
@@ -0,0 +1,46 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.event.sort;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public abstract class AbstractSortListener implements SortListener {
+
+ /**
+ * Encapsulate sorting toggle here
+ * @param current
+ * @param suggested
+ * @return
+ */
+ protected Boolean nextSortOrder(Boolean current, Boolean suggested) {
+
+ if (suggested != null) {
+ return suggested;
+ } else {
+ return (current == null) ? Boolean.TRUE : (current.booleanValue() ? Boolean.FALSE :
Boolean.TRUE);
+ }
+
+ }
+
+}
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/MultiColumnSortListener.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/MultiColumnSortListener.java 2007-09-28
16:20:16 UTC (rev 3166)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/MultiColumnSortListener.java 2007-09-28
16:34:32 UTC (rev 3167)
@@ -21,7 +21,7 @@
* @author Maksim Kaszynski
*
*/
-public class MultiColumnSortListener implements SortListener {
+public class MultiColumnSortListener extends AbstractSortListener {
public static final MultiColumnSortListener INSTANCE = new MultiColumnSortListener();
@@ -51,11 +51,13 @@
}
+ Boolean suggested = e.getSuggestedOrder();
+
SortField[] fields = sortOrder.getFields();
if (fields == null) {
//If no sorting was applied at all, set sorting to current
- fields = new SortField[] {new SortField(name, columnIndex, Boolean.TRUE)};
+ fields = new SortField[] {new SortField(name, columnIndex, nextSortOrder(null,
suggested))};
} else {
List newFields = new LinkedList(Arrays.asList(fields));
@@ -69,16 +71,16 @@
name.equals(sortField.getName()))) {
Boolean asc = sortField.getAscending();
- asc = Boolean.TRUE.equals(asc) ? Boolean.FALSE : Boolean.TRUE;
- newField = new SortField(name, columnIndex, asc);
+ newField = new SortField(name, columnIndex, nextSortOrder(asc, suggested));
iterator.remove();
}
}
if (newField == null) {
- newField = new SortField(name, columnIndex, Boolean.TRUE);
+
+ newField = new SortField(name, columnIndex, nextSortOrder(null, suggested));
}
newFields.add(newField);
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/SingleColumnSortListener.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/SingleColumnSortListener.java 2007-09-28
16:20:16 UTC (rev 3166)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/SingleColumnSortListener.java 2007-09-28
16:34:32 UTC (rev 3167)
@@ -15,7 +15,7 @@
* @author Maksim Kaszynski
*
*/
-public class SingleColumnSortListener implements SortListener {
+public class SingleColumnSortListener extends AbstractSortListener {
public static final SingleColumnSortListener INSTANCE = new SingleColumnSortListener();
@@ -46,7 +46,7 @@
SortField[] fields = sortOrder.getFields();
- SortField newField = new SortField(name, columnIndex, Boolean.TRUE);
+ SortField newField = new SortField(name, columnIndex, nextSortOrder(null,
e.getSuggestedOrder()));
if (fields != null) {
for (int i = 0; i < fields.length; i++) {
@@ -56,8 +56,7 @@
name != null &&
name.equals(sortField.getName()))) {
- Boolean asc = sortField.getAscending();
- asc = Boolean.TRUE.equals(asc) ? Boolean.FALSE : Boolean.TRUE;
+ Boolean asc = nextSortOrder(sortField.getAscending(), e.getSuggestedOrder()) ;
newField = new SortField(name, columnIndex, asc);
break;
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/ScrollableDataTableBaseRenderer.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/ScrollableDataTableBaseRenderer.java 2007-09-28
16:20:16 UTC (rev 3166)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/ScrollableDataTableBaseRenderer.java 2007-09-28
16:34:32 UTC (rev 3167)
@@ -582,13 +582,28 @@
if(parameters.containsKey(clientId + ":sortColumn") &&
parameters.containsKey(clientId + ":sortStartRow") &&
- parameters.containsKey(clientId + ":sortIndex") &&
- parameters.containsKey(clientId + ":sortOrder")){
+ parameters.containsKey(clientId + ":sortIndex")){
int sortColumn = Integer.parseInt((String)parameters.get(clientId +
":sortColumn"));
int sortDataIndex = Integer.parseInt((String)parameters.get(clientId +
":sortIndex"));
Integer sortStartRow = Integer.valueOf((String)parameters.get(clientId +
":sortStartRow"));
+ String sortOrderString =
+ (String) parameters.get(clientId + ":sortOrder");
+
+ Boolean so = null;
+
+ if (sortOrderString != null && sortOrderString.length() > 0 ) {
+ sortOrderString = sortOrderString.toLowerCase();
+
+ if (sortOrderString.startsWith("a")) {
+ so = Boolean.TRUE;
+ } else if (sortOrderString.startsWith("d")){
+ so = Boolean.FALSE;
+ }
+ }
+
+
Column column = (Column)grid.getChildren().get(sortColumn);
if(column.isSortable()){
@@ -596,6 +611,8 @@
sorted = true;
SortEvent sortEvent = new SortEvent(grid,sortColumn, grid.getRows(),
sortDataIndex);
+ sortEvent.setProposedOrder(so);
+
sortEvent.setAttribute(ScrollableDataTableUtils.CLIENT_ROW_KEY,sortStartRow);
if (ajaxContext.isAjaxRequest()) {
Modified:
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/GridHeader.js
===================================================================
---
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/GridHeader.js 2007-09-28
16:20:16 UTC (rev 3166)
+++
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/GridHeader.js 2007-09-28
16:34:32 UTC (rev 3167)
@@ -195,7 +195,7 @@
frozen: false,
fixedWidth: Validators.getBoolean(cell.getAttribute("fixedWidth"), false),
sortable: Validators.getBoolean(cell.getAttribute("sortable"), false),
- sorted: Validators.getBoolean(cell.getAttribute("sorted"),
"desc")
+ sorted: null
};
if(columns[j].sortable)