You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2008/01/27 12:18:47 UTC
svn commit: r615578 - in /myfaces/tobago/branches/tobago-1.0.x: ./
core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
Author: bommel
Date: Sun Jan 27 03:18:46 2008
New Revision: 615578
URL: http://svn.apache.org/viewvc?rev=615578&view=rev
Log:
Merged revisions 615257 via svnmerge from
https://svn.apache.org/repos/asf/myfaces/tobago/trunk
........
r615257 | weber | 2008-01-25 17:23:00 +0100 (Fr, 25 Jan 2008) | 4 lines
(TOBAGO-570) <tc:sheet> selection is not preserved in sortable sheet
<http://issues.apache.org/jira/browse/TOBAGO-570>
Thanks to Helmut Swaczinna for the patch
........
Modified:
myfaces/tobago/branches/tobago-1.0.x/ (props changed)
myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
Propchange: myfaces/tobago/branches/tobago-1.0.x/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Sun Jan 27 03:18:46 2008
@@ -1 +1 @@
-/myfaces/tobago/trunk:1-603371,609568-609629,612250-612251,612282,612518,613455,613939,614278,614291,614642
+/myfaces/tobago/trunk:1-603371,609568-609629,612250-612251,612282,612518,613455,613939,614278,614291,614642,615257
Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java?rev=615578&r1=615577&r2=615578&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/component/Sorter.java Sun Jan 27 03:18:46 2008
@@ -37,6 +37,8 @@
import javax.faces.el.MethodNotFoundException;
import javax.faces.el.ValueBinding;
import javax.faces.model.DataModel;
+
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
@@ -123,12 +125,52 @@
// Comparator comparator = Collator.getInstance();
// comparator = new RowComparator(ascending, method);
+ // memorize selected rows
+ List<Object> selectedDataRows = null;
+ if (sheetState.getSelectedRows() != null && sheetState.getSelectedRows().size() > 0) {
+ selectedDataRows = new ArrayList<Object>(sheetState.getSelectedRows().size());
+ Object dataRow;
+ for (Integer index : sheetState.getSelectedRows()) {
+ if (value instanceof List) {
+ dataRow = ((List) value).get(index);
+ } else {
+ dataRow = ((Object[]) value)[index];
+ }
+ selectedDataRows.add(dataRow);
+ }
+ }
+
+ // do sorting
if (value instanceof List) {
Collections.sort((List) value, actualComparator);
} else { // value is instanceof Object[]
Arrays.sort((Object[]) value, actualComparator);
}
+ // restore selected rows
+ if (selectedDataRows != null) {
+ sheetState.getSelectedRows().clear();
+ for (Object dataRow : selectedDataRows) {
+ int index = -1;
+ if (value instanceof List) {
+ for (int i = 0; i < ((List) value).size() && index < 0; i++) {
+ if (dataRow == ((List) value).get(i)) {
+ index = i;
+ }
+ }
+ } else {
+ for (int i = 0; i < ((Object[]) value).length && index < 0; i++) {
+ if (dataRow == ((Object[]) value)[i]) {
+ index = i;
+ }
+ }
+ }
+ if (index >= 0) {
+ sheetState.getSelectedRows().add(index);
+ }
+ }
+ }
+
} else { // DataModel?, ResultSet, Result or Object
LOG.warn("Sorting not supported for type "
+ (value != null ? value.getClass().toString() : "null"));