Author: konstantin.mishin
Date: 2007-10-05 09:56:15 -0400 (Fri, 05 Oct 2007)
New Revision: 3283
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ComponentSortableDataModel.java
Log:
RF-1043
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ComponentSortableDataModel.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ComponentSortableDataModel.java 2007-10-05
13:29:41 UTC (rev 3282)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/internal/ComponentSortableDataModel.java 2007-10-05
13:56:15 UTC (rev 3283)
@@ -27,6 +27,7 @@
import java.util.List;
import javax.faces.context.FacesContext;
+import javax.faces.model.DataModel;
import org.richfaces.model.ScrollableTableDataModel;
import org.richfaces.model.SortField;
@@ -65,6 +66,7 @@
private List wrappedList;
+ DataModel model;
private String var;
public ComponentSortableDataModel(String var, Object value) {
@@ -76,12 +78,7 @@
* @see org.richfaces.model.ScrollableTableDataModel#loadData(int, int,
org.richfaces.model.SortOrder)
*/
public List loadData(int startRow, int endRow, SortOrder sortOrder) {
-
-
- List sortedCollection = sortOrder != null ?
- prepareCollection(FacesContext.getCurrentInstance(), new ArrayList(wrappedList),
sortOrder) : wrappedList;
-
-
+ List list = null;
int rc = getRowCount();
if (startRow < 0) {
startRow = 0;
@@ -90,24 +87,51 @@
if (endRow > rc) {
endRow = rc;
}
-
- return sortedCollection.subList(startRow, endRow);
+ if (sortOrder == null) {
+ if(model != null) {
+ list = new ArrayList(rc);
+ for (int i = startRow; i < endRow; i++) {
+ model.setRowIndex(i);
+ list.add(model.getRowData());
+ }
+ } else {
+ list = wrappedList.subList(startRow, endRow);
+ }
+ } else {
+ if(model != null) {
+ list = new ArrayList(rc);
+ for (int i = 0; i < rc; i++) {
+ model.setRowIndex(i);
+ list.add(model.getRowData());
+ }
+ } else {
+ list = new ArrayList(wrappedList);
+ }
+ list = prepareCollection(FacesContext.getCurrentInstance(), list,
sortOrder).subList(startRow, endRow);
+ }
+ return list;
}
/* (non-Javadoc)
* @see javax.faces.model.DataModel#getRowCount()
*/
public int getRowCount() {
- // TODO Auto-generated method stub
- return wrappedList.size();
+ if (model != null) {
+ return model.getRowCount();
+ } else {
+ return wrappedList.size();
+ }
}
/* (non-Javadoc)
* @see javax.faces.model.DataModel#getWrappedData()
*/
public Object getWrappedData() {
- // TODO Auto-generated method stub
- return wrappedList;
+ if (model != null) {
+ return model;
+ } else {
+ return wrappedList;
+ }
}
/* (non-Javadoc)
@@ -132,6 +156,8 @@
wrappedList = new ArrayList((Collection) value);
+ } else if (value instanceof DataModel) {
+ model = (DataModel)value;
} else {
wrappedList = new ArrayList(1);
wrappedList.add(value);