Author: konstantin.mishin
Date: 2008-05-08 12:37:18 -0400 (Thu, 08 May 2008)
New Revision: 8506
Modified:
trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent.java
trunk/framework/api/src/main/java/org/richfaces/model/SortField.java
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/ObjectWrapperFactoryTest.java
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanComparatorTest.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
trunk/ui/scrollableDataTable/src/main/templates/org/richfaces/scrollable-data-table-header-cell.jspx
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/component/AbstractScrollableDataTableTestCase.java
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/event/sort/MultiColumnSortListenerTest.java
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/event/sort/SingleColumnSortListenerTest.java
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ComponentSortableDataModelTest.java
Log:
RF-2854
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 2008-05-08
16:10:34 UTC (rev 8505)
+++ trunk/framework/api/src/main/java/org/richfaces/event/sort/SortEvent.java 2008-05-08
16:37:18 UTC (rev 8506)
@@ -24,11 +24,11 @@
private static final long serialVersionUID = -1453867412542792281L;
- private int sortColumn;
+ private String sortColumn;
private Boolean suggestedOrder = null;
- public SortEvent(UIComponent component, int sortColumn, int rows, int first) {
+ public SortEvent(UIComponent component, String sortColumn, int rows, int first) {
super(component, rows, first);
this.sortColumn = sortColumn;
@@ -46,7 +46,7 @@
/**
* @return the sortField
*/
- public int getSortColumn() {
+ public String getSortColumn() {
return sortColumn;
}
@@ -57,7 +57,7 @@
return "SortEvent: {sortColumn: " + sortColumn + "}";
}
- public void setSortColumn(int sortColumn) {
+ public void setSortColumn(String sortColumn) {
this.sortColumn = sortColumn;
}
Modified: trunk/framework/api/src/main/java/org/richfaces/model/SortField.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/SortField.java 2008-05-08
16:10:34 UTC (rev 8505)
+++ trunk/framework/api/src/main/java/org/richfaces/model/SortField.java 2008-05-08
16:37:18 UTC (rev 8506)
@@ -16,15 +16,13 @@
*/
private static final long serialVersionUID = 1L;
private String name = null;
- private int index = -1;
private Boolean ascending = null;
- public SortField(String name, int index, Boolean ascending) {
+ public SortField(String name, Boolean ascending) {
super();
this.name = name;
- this.index = index;
this.ascending = ascending;
}
@@ -36,14 +34,6 @@
this.name = name;
}
- public int getIndex() {
- return index;
- }
-
- public void setIndex(int index) {
- this.index = index;
- }
-
public Boolean getAscending() {
return ascending;
}
@@ -52,16 +42,17 @@
this.ascending = ascending;
}
+ @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((ascending == null) ? 0 : ascending.hashCode());
- result = prime * result + index;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
+ @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
@@ -69,14 +60,12 @@
return false;
if (getClass() != obj.getClass())
return false;
- final SortField other = (SortField) obj;
+ SortField other = (SortField) obj;
if (ascending == null) {
if (other.ascending != null)
return false;
} else if (!ascending.equals(other.ascending))
return false;
- if (index != other.index)
- return false;
if (name == null) {
if (other.name != null)
return false;
@@ -84,7 +73,4 @@
return false;
return true;
}
-
-
-
}
Modified:
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/ObjectWrapperFactoryTest.java
===================================================================
---
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/ObjectWrapperFactoryTest.java 2008-05-08
16:10:34 UTC (rev 8505)
+++
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/ObjectWrapperFactoryTest.java 2008-05-08
16:37:18 UTC (rev 8506)
@@ -57,9 +57,9 @@
public void setUp() throws Exception {
super.setUp();
sortFields = new SortField[3];
- sortFields[0] = new SortField("_id1", 0, Boolean.TRUE);
- sortFields[1] = new SortField("name", 1, Boolean.FALSE);
- sortFields[2] = new SortField("#{" +var + ".name}", 2,
Boolean.TRUE);
+ sortFields[0] = new SortField("_id1", Boolean.TRUE);
+ sortFields[1] = new SortField("name", Boolean.FALSE);
+ sortFields[2] = new SortField("#{" +var + ".name}", Boolean.TRUE);
sortOrder = new SortOrder(sortFields);
factory = new ObjectWrapperFactory(facesContext, var, sortOrder);
Modified:
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanComparatorTest.java
===================================================================
---
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanComparatorTest.java 2008-05-08
16:10:34 UTC (rev 8505)
+++
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanComparatorTest.java 2008-05-08
16:37:18 UTC (rev 8506)
@@ -54,8 +54,8 @@
super.setUp();
sortFields = new SortField[2];
- sortFields[0] = new SortField("a", 1, Boolean.FALSE);
- sortFields[1] = new SortField("b", 2, Boolean.TRUE);
+ sortFields[0] = new SortField("a", Boolean.FALSE);
+ sortFields[1] = new SortField("b", Boolean.TRUE);
comparator = new WrappedBeanComparator(sortFields);
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 2008-05-08
16:10:34 UTC (rev 8505)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/MultiColumnSortListener.java 2008-05-08
16:37:18 UTC (rev 8506)
@@ -33,10 +33,9 @@
*/
public void processSort(SortEvent e) {
UIScrollableDataTable grid = (UIScrollableDataTable) e.getComponent();
- int columnIndex = e.getSortColumn();
+ String sortColumn = e.getSortColumn();
- UIComponent column =
- grid.getChildren().get(columnIndex);
+ UIComponent column = grid.findComponent(sortColumn);
String name = ColumnUtil.getColumnSorting(column);
@@ -57,7 +56,7 @@
if (fields == null) {
//If no sorting was applied at all, set sorting to current
- fields = new SortField[] {new SortField(name, columnIndex, nextSortOrder(null,
suggested))};
+ fields = new SortField[] {new SortField(name, nextSortOrder(null, suggested))};
} else {
List<SortField> newFields = new
LinkedList<SortField>(Arrays.asList(fields));
@@ -65,14 +64,11 @@
for (Iterator<SortField> iterator = newFields.iterator(); iterator.hasNext()
&& newField == null; ) {
SortField sortField = (SortField) iterator.next();
- if (sortField.getIndex() == columnIndex ||
- (sortField.getName() != null &&
- name != null &&
- name.equals(sortField.getName()))) {
+ if (name != null && name.equals(sortField.getName())) {
Boolean asc = sortField.getAscending();
- newField = new SortField(name, columnIndex, nextSortOrder(asc, suggested));
+ newField = new SortField(name, nextSortOrder(asc, suggested));
iterator.remove();
}
@@ -80,7 +76,7 @@
if (newField == null) {
- newField = new SortField(name, columnIndex, nextSortOrder(null, suggested));
+ newField = new SortField(name, 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 2008-05-08
16:10:34 UTC (rev 8505)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/event/sort/SingleColumnSortListener.java 2008-05-08
16:37:18 UTC (rev 8506)
@@ -27,9 +27,9 @@
*/
public void processSort(SortEvent e) {
UIScrollableDataTable grid = (UIScrollableDataTable) e.getComponent();
- int columnIndex = e.getSortColumn();
- UIComponent column =
- grid.getChildren().get(columnIndex);
+ String sortColumn = e.getSortColumn();
+
+ UIComponent column = grid.findComponent(sortColumn);
String name = ColumnUtil.getColumnSorting(column);
@@ -46,19 +46,16 @@
SortField[] fields = sortOrder.getFields();
- SortField newField = new SortField(name, columnIndex, nextSortOrder(null,
e.getSuggestedOrder()));
+ SortField newField = new SortField(name, nextSortOrder(null, e.getSuggestedOrder()));
if (fields != null) {
for (int i = 0; i < fields.length; i++) {
SortField sortField = fields[i];
- if (sortField.getIndex() == columnIndex ||
- (sortField.getName() != null &&
- name != null &&
- name.equals(sortField.getName()))) {
+ if (name != null && name.equals(sortField.getName())) {
Boolean asc = nextSortOrder(sortField.getAscending(), e.getSuggestedOrder()) ;
- newField = new SortField(name, columnIndex, asc);
+ newField = new SortField(name, 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 2008-05-08
16:10:34 UTC (rev 8505)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/ScrollableDataTableBaseRenderer.java 2008-05-08
16:37:18 UTC (rev 8506)
@@ -158,7 +158,7 @@
variables.setVariable("sepOffset", new Integer(sepOffset));
variables.setVariable("headerColumnClass", state.getColumnClass());
variables.setVariable("columnWidth", width);
- Boolean sorting = getColumnSorting(state.getGrid(), cell_index);
+ Boolean sorting = getColumnSorting(state.getGrid(), column.getId());
if (sorting != null) {
if (sorting.booleanValue()) {
variables.setVariable("headerColumnSortClass",
"rich-sdt-header-sort-up");
@@ -185,7 +185,7 @@
int cell_index = state.getCellIndex();
String client_id = state.getClientId();
- Boolean sorting = getColumnSorting(state.getGrid(), cell_index);
+ Boolean sorting = getColumnSorting(state.getGrid(), column.getId());
if (sorting != null) {
if (sorting.booleanValue()) {
@@ -227,7 +227,7 @@
variables.setVariable("cell_index", new Integer(cell_index));
variables.setVariable("footerColumnClass", state.getColumnClass());
- Boolean sorting = getColumnSorting(state.getGrid(), cell_index);
+ Boolean sorting = getColumnSorting(state.getGrid(), column.getId());
if (sorting != null) {
if (sorting.booleanValue()) {
variables.setVariable("footerColumnSortClass",
"rich-sdt-footer-sort-up");
@@ -263,7 +263,7 @@
variables.setVariable("client_id", client_id);
variables.setVariable("cell_index", new Integer(cell_index));
variables.setVariable("columnClass", state.getColumnClass());
- Boolean sorting = getColumnSorting(state.getGrid(), cell_index);
+ Boolean sorting = getColumnSorting(state.getGrid(), column.getId());
if (sorting != null) {
if (sorting.booleanValue()) {
variables.setVariable("columnSortClass",
"rich-sdt-column-sort-up");
@@ -628,7 +628,7 @@
parameters.containsKey(clientId + ":sortStartRow") &&
parameters.containsKey(clientId + ":sortIndex")){
- int sortColumn = Integer.parseInt((String)parameters.get(clientId +
":sortColumn"));
+ String sortColumn = (String)parameters.get(clientId + ":sortColumn");
int sortDataIndex = Integer.parseInt((String)parameters.get(clientId +
":sortIndex"));
Integer sortStartRow = Integer.valueOf((String)parameters.get(clientId +
":sortStartRow"));
@@ -648,7 +648,7 @@
}
- UIComponent column = (UIComponent)grid.getChildren().get(sortColumn);
+ UIComponent column = grid.findComponent(sortColumn);
if(ColumnUtil.isSortable(column)){
@@ -940,12 +940,11 @@
}
}
- private Boolean getColumnSorting(UIScrollableDataTable grid, int columnIndex) {
+ private Boolean getColumnSorting(UIScrollableDataTable grid, String sortColumn) {
Boolean sorting = null;
- UIComponent column =
- grid.getChildren().get(columnIndex);
+ UIComponent column = grid.findComponent(sortColumn);
String name = ColumnUtil.getColumnSorting(column);
@@ -958,8 +957,7 @@
for (int i = 0; i < sortFields.length && sorting == null; i++) {
SortField sortField = sortFields[i];
- if ((name != null && name.equals(sortField.getName()))
- || columnIndex == sortField.getIndex()) {
+ if (name != null && name.equals(sortField.getName())) {
sorting = sortField.getAscending();
}
}
Modified:
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/GridHeader.js
===================================================================
---
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/GridHeader.js 2008-05-08
16:10:34 UTC (rev 8505)
+++
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/GridHeader.js 2008-05-08
16:37:18 UTC (rev 8506)
@@ -334,8 +334,8 @@
}
if(el) {
- var index = parseInt(el.getAttribute("columnindex"));
- if(index>=0) {
+ var sortColumnId = el.getAttribute("columnid");
+ if(sortColumnId) {
/*
var dir = this.getColumns()[index].sorted;
dir = (dir == "asc") ? "desc" : "asc";
@@ -358,7 +358,7 @@
*/
var rows = this.grid.getBody().templFrozen.getElement().rows;
var startRow = rows && rows.length>0 ?
this.grid.getBody()._getRowIndex(rows[0].id) : 0;
- this.grid.element.fire("grid:onsort",{ column: index,
+ this.grid.element.fire("grid:onsort",{ column: sortColumnId,
startRow: startRow,
index: this.grid.getBody().currRange.start
});
Modified:
trunk/ui/scrollableDataTable/src/main/templates/org/richfaces/scrollable-data-table-header-cell.jspx
===================================================================
---
trunk/ui/scrollableDataTable/src/main/templates/org/richfaces/scrollable-data-table-header-cell.jspx 2008-05-08
16:10:34 UTC (rev 8505)
+++
trunk/ui/scrollableDataTable/src/main/templates/org/richfaces/scrollable-data-table-header-cell.jspx 2008-05-08
16:37:18 UTC (rev 8506)
@@ -12,7 +12,7 @@
component="javax.faces.component.UIComponent"
- <th class="dr-sdt-hc rich-sdt-header-cell #{headerColumnClass}
#{headerColumnSortClass}" id="#{client_id}:hc_#{cell_index}"
columnindex="#{cell_index}"
sortable="#{component.attributes['sortable']}">
+ <th class="dr-sdt-hc rich-sdt-header-cell #{headerColumnClass}
#{headerColumnSortClass}" id="#{client_id}:hc_#{cell_index}"
columnid="#{component.attributes['id']}"
sortable="#{component.attributes['sortable']}">
<jsp:scriptlet>
if(org.richfaces.component.util.ColumnUtil.isSortable(component)) {
Modified:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/component/AbstractScrollableDataTableTestCase.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/component/AbstractScrollableDataTableTestCase.java 2008-05-08
16:10:34 UTC (rev 8505)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/component/AbstractScrollableDataTableTestCase.java 2008-05-08
16:37:18 UTC (rev 8506)
@@ -89,8 +89,8 @@
protected SortOrder createTestData_0_sortOrder() {
SortField[] fields = new SortField[] {
- new SortField("aaa", 1, Boolean.TRUE),
- new SortField("bb", 0, Boolean.FALSE)
+ new SortField("aaa", Boolean.TRUE),
+ new SortField("bb", Boolean.FALSE)
};
return new SortOrder(fields);
}
@@ -103,9 +103,9 @@
protected SortOrder createTestData_1_sortOrder() {
SortField[] fields = new SortField[] {
- new SortField("column3", 2, null),
- new SortField("column1", 1, Boolean.TRUE),
- new SortField("column2", 0, Boolean.FALSE)
+ new SortField("column3", null),
+ new SortField("column1", Boolean.TRUE),
+ new SortField("column2", Boolean.FALSE)
};
return new SortOrder(fields);
}
@@ -139,7 +139,7 @@
SortListener1 sortListener = new SortListener1();
table.setSortListener(sortListener);
- table.broadcast(new SortEvent(table, 0, 20, 30));
+ table.broadcast(new SortEvent(table, "0", 20, 30));
assertTrue(sortListener.triggered);
}
@@ -176,7 +176,7 @@
table.setSortListener(sortListener1);
- SortEvent sortEvent = new SortEvent(table, 0, 20, 30);
+ SortEvent sortEvent = new SortEvent(table, "0", 20, 30);
table.processSortingChange(sortEvent);
Modified:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/event/sort/MultiColumnSortListenerTest.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/event/sort/MultiColumnSortListenerTest.java 2008-05-08
16:10:34 UTC (rev 8505)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/event/sort/MultiColumnSortListenerTest.java 2008-05-08
16:37:18 UTC (rev 8506)
@@ -75,7 +75,7 @@
* Test method for {@link
org.richfaces.event.sort.SingleColumnSortListener#processSort(org.richfaces.event.sort.SortEvent)}.
*/
public final void testProcessSort() {
- SortEvent event = new SortEvent(table, 0, 0, 0);
+ SortEvent event = new SortEvent(table, "col1", 0, 0);
listener.processSort(event);
@@ -92,7 +92,6 @@
assertEquals("col1", field.getName());
assertEquals(Boolean.TRUE, field.getAscending());
- assertEquals(0, field.getIndex());
listener.processSort(event);
@@ -109,9 +108,8 @@
assertEquals("col1", field.getName());
assertEquals(Boolean.FALSE, field.getAscending());
- assertEquals(0, field.getIndex());
- event = new SortEvent(table, 1, 0, 0);
+ event = new SortEvent(table, "col2", 0, 0);
listener.processSort(event);
@@ -128,13 +126,11 @@
assertEquals("col1", field.getName());
assertEquals(Boolean.FALSE, field.getAscending());
- assertEquals(0, field.getIndex());
field = fields[1];
assertEquals("col2", field.getName());
assertEquals(Boolean.TRUE, field.getAscending());
- assertEquals(1, field.getIndex());
}
}
Modified:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/event/sort/SingleColumnSortListenerTest.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/event/sort/SingleColumnSortListenerTest.java 2008-05-08
16:10:34 UTC (rev 8505)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/event/sort/SingleColumnSortListenerTest.java 2008-05-08
16:37:18 UTC (rev 8506)
@@ -72,7 +72,7 @@
* Test method for {@link
org.richfaces.event.sort.SingleColumnSortListener#processSort(org.richfaces.event.sort.SortEvent)}.
*/
public final void testProcessSort() {
- SortEvent event = new SortEvent(table, 0, 0, 0);
+ SortEvent event = new SortEvent(table, "col1", 0, 0);
listener.processSort(event);
@@ -89,7 +89,6 @@
assertEquals("col1", field.getName());
assertEquals(Boolean.TRUE, field.getAscending());
- assertEquals(0, field.getIndex());
listener.processSort(event);
@@ -106,9 +105,8 @@
assertEquals("col1", field.getName());
assertEquals(Boolean.FALSE, field.getAscending());
- assertEquals(0, field.getIndex());
- event = new SortEvent(table, 1, 0, 0);
+ event = new SortEvent(table, "col2", 0, 0);
listener.processSort(event);
@@ -125,7 +123,6 @@
assertEquals("col2", field.getName());
assertEquals(Boolean.TRUE, field.getAscending());
- assertEquals(1, field.getIndex());
}
Modified:
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ComponentSortableDataModelTest.java
===================================================================
---
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ComponentSortableDataModelTest.java 2008-05-08
16:10:34 UTC (rev 8505)
+++
trunk/ui/scrollableDataTable/src/test/java/org/richfaces/model/internal/ComponentSortableDataModelTest.java 2008-05-08
16:37:18 UTC (rev 8506)
@@ -66,7 +66,7 @@
o = o(20);
- sortOrder = new SortOrder(new SortField[] {new SortField("name", 0,
Boolean.TRUE)});
+ sortOrder = new SortOrder(new SortField[] {new SortField("name",
Boolean.TRUE)});
//model = new ComponentSortableDataModel()
}