Author: konstantin.mishin
Date: 2010-04-27 09:32:45 -0400 (Tue, 27 Apr 2010)
New Revision: 16818
Modified:
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/convert/selection/ClientSelectionConverter.java
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/model/selection/ClientSelection.java
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/Selection.js
Log:
RFPL-557
Modified:
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java
===================================================================
---
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java 2010-04-27
12:16:15 UTC (rev 16817)
+++
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java 2010-04-27
13:32:45 UTC (rev 16818)
@@ -465,6 +465,8 @@
public abstract Object getActiveRowKey();
public abstract void setActiveRowKey(Object activeRowKey);
+ public abstract int getShiftRowIndex();
+ public abstract void setShiftRowIndex(int shiftRowIndex);
/* (non-Javadoc)
* @see org.ajax4jsf.component.UIDataAdaptor#setRowIndex(int)
*/
Modified:
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/convert/selection/ClientSelectionConverter.java
===================================================================
---
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/convert/selection/ClientSelectionConverter.java 2010-04-27
12:16:15 UTC (rev 16817)
+++
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/convert/selection/ClientSelectionConverter.java 2010-04-27
13:32:45 UTC (rev 16818)
@@ -89,7 +89,12 @@
clientSelection.setSelectionFlag(selections[length-1]);
length--;
}
- clientSelection.setActiveRowIndex(Integer.parseInt(selections[length-1]));
+ String[] rows = selections[length-1].split("\\|");
+ clientSelection.setActiveRowIndex(Integer.parseInt(rows[0]));
+ String shiftRowIndex = rows[1];
+ if (shiftRowIndex.charAt(0) > '0') {
+ clientSelection.setShiftRowIndex(Integer.parseInt(shiftRowIndex));
+ }
length--;
for (int i = 0; i < length; i++) {
Modified:
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/model/selection/ClientSelection.java
===================================================================
---
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/model/selection/ClientSelection.java 2010-04-27
12:16:15 UTC (rev 16817)
+++
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/model/selection/ClientSelection.java 2010-04-27
13:32:45 UTC (rev 16818)
@@ -39,10 +39,16 @@
public static final String FLAG_ALL = "a";
+ public static final String FLAG_ADD2SELECTION_AFTER_RANGE = "d";
+
+ public static final String FLAG_ADD2SELECTION_BEFORE_RANGE = "u";
+
private String selectionFlag;
private int activeRowIndex = -1;
+ private int shiftRowIndex = -1;
+
private List<SelectionRange> ranges = new ArrayList<SelectionRange>();
public ClientSelection() {
@@ -145,17 +151,24 @@
if (FLAG_ALL.equals(selectionFlag)) {
selectAll = true;
- } else if (FLAG_RESET.equals(selectionFlag)) {
+ } else if (FLAG_RESET.equals(selectionFlag) ||
FLAG_ADD2SELECTION_AFTER_RANGE.equals(selectionFlag)
+ || FLAG_ADD2SELECTION_BEFORE_RANGE.equals(selectionFlag)) {
reset = true;
}
}
+ public int getShiftRowIndex() {
+ return shiftRowIndex;
+ }
+ public void setShiftRowIndex(int shiftRowIndex) {
+ this.shiftRowIndex = shiftRowIndex;
+ }
+
public int getActiveRowIndex() {
return activeRowIndex;
}
-
public void setActiveRowIndex(int activeRowIndex) {
this.activeRowIndex = activeRowIndex;
}
Modified:
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java
===================================================================
---
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java 2010-04-27
12:16:15 UTC (rev 16817)
+++
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java 2010-04-27
13:32:45 UTC (rev 16818)
@@ -81,7 +81,8 @@
.getAsObject(context, grid, value);
final ScrollableDataTableRendererState state = ScrollableDataTableRendererState
.createState(context, grid);
- state.setRowIndex(ScrollableDataTableUtils.getClientRowIndex(grid));
+ int clientRowIndex = ScrollableDataTableUtils.getClientRowIndex(grid);
+ state.setRowIndex(clientRowIndex);
final SimpleSelection simpleSelection = grid.getSelection() == null ? new
SimpleSelection()
: (SimpleSelection) grid.getSelection();
if (clientSelection.isReset() || clientSelection.isSelectAll()) {
@@ -117,6 +118,39 @@
} catch (IOException e) {
throw new FacesException(e);
}
+ int shiftRowIndex = clientSelection.getShiftRowIndex();
+ if (shiftRowIndex != -1) {
+ int rows = grid.getRows();
+ grid.setShiftRowIndex(grid.getFirst() + (rows + shiftRowIndex - clientRowIndex) %
rows);
+ }
+ int oldFirst = grid.getFirst();
+ int oldRows = grid.getRows();
+ int newFirst = -1;
+ int newRows = -1;
+
+ if
(ClientSelection.FLAG_ADD2SELECTION_BEFORE_RANGE.equals(clientSelection.getSelectionFlag()))
{
+ newFirst = grid.getShiftRowIndex();
+ newRows = oldFirst - newFirst;
+ } else if
(ClientSelection.FLAG_ADD2SELECTION_AFTER_RANGE.equals(clientSelection.getSelectionFlag()))
{
+ newFirst = oldFirst + oldRows;
+ newRows = grid.getShiftRowIndex() - newFirst + 1;
+ }
+ if (newFirst != -1) {
+ grid.setFirst(newFirst);
+ grid.setRows(newRows);
+ try {
+ grid.walk(context, new DataVisitor() {
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+ simpleSelection.addKey(rowKey);
+ }
+ }, null);
+ } catch (IOException e) {
+ throw new FacesException(e);
+ }
+ grid.setFirst(oldFirst);
+ grid.setRows(oldRows);
+ }
grid.setSelection(simpleSelection);
ValueExpression selectionBinding = grid
.getValueExpression("selection");
@@ -277,7 +311,20 @@
string = "";
}
- string += selection.getActiveRowIndex();
+ int first = grid.getFirst();
+ int rows = grid.getRows();
+ int shiftRowIndex = grid.getShiftRowIndex();
+ String shiftRow = "|.";
+ if (shiftRowIndex > 0) {
+ if (shiftRowIndex < first) {
+ shiftRow = "|-";
+ } else if (shiftRowIndex > first + rows) {
+ shiftRow = "|+";
+ } else {
+ shiftRow = "|" + (rows + shiftRowIndex - first +
ScrollableDataTableUtils.getClientRowIndex(grid)) % rows;
+ }
+ }
+ string += selection.getActiveRowIndex() + shiftRow;
String id = getSelectionInputName(context, grid);
Modified:
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/Selection.js
===================================================================
---
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/Selection.js 2010-04-27
12:16:15 UTC (rev 16817)
+++
branches/enterprise/3.3.X/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/Selection.js 2010-04-27
13:32:45 UTC (rev 16818)
@@ -248,11 +248,21 @@
restoreState: function() {
this.selectionFlag = null;
var selStrAr = $(this.inputElement).value.split(";");
- var activeRow = NaN;
- while (selStrAr.length != 0 && selStrAr[selStrAr.length -
1].indexOf(",") == -1 &&
- isNaN(activeRow = Number(selStrAr.pop())));
- if (!isNaN(activeRow)) {
- this.setActiveRow(activeRow);
+ var rowsString = "";
+ while (selStrAr.length != 0 && (rowsString =
selStrAr.pop()).indexOf("|") == -1);
+ var rows = rowsString.split("|");
+ if (rows.length == 2) {
+ var activeRow = Number(rows[0]);
+ if (!isNaN(activeRow)) {
+ this.setActiveRow(activeRow);
+ }
+ var shiftRowString = rows[1];
+ var shiftRow = Number(shiftRowString);
+ if (!isNaN(shiftRow)) {
+ this.shiftRow = shiftRow;
+ } else if ("+-".indexOf(shiftRowString) != -1 ) {
+ this.shiftRow = shiftRowString;
+ }
}
this.selection.initRanges(selStrAr);
// this.firstIndex = Number($(this.prefix +
":f").rows[0].id.split(this.prefix)[1].split(":")[2]);;
@@ -321,7 +331,7 @@
processKeyDown: function(event) {
if ($(this.prefix + ":n").rows.length > 0) {
- if(!event.shiftKey) {
+ if(!event.shiftKey && (event.keyCode || event.charCode) != 16) {
this.shiftRow = null;
}
var range, rowIndex;
@@ -407,13 +417,25 @@
var range;
if ( event.shiftKey && !event.ctrlKey && !event.altKey &&
!this.isSingleMode) {
this.firstIndex = Number($(this.prefix +
":n").rows[0].id.split(this.prefix)[1].split(":")[2]);;
- this.selectionFlag = "x";
if(!this.shiftRow) {
- this.shiftRow = this.activeRow;
+ if (this.activeRow == -1) {
+ this.shiftRow = rowIndex;
+ } else {
+ this.shiftRow = this.activeRow;
+ }
}
- this.startRow = this.shiftRow;
+ if (this.shiftRow == "-") {
+ this.selectionFlag = "u";
+ this.startRow = this.firstIndex;
+ } else if (this.shiftRow == "+") {
+ this.selectionFlag = "d";
+ this.startRow = this.firstIndex ? this.firstIndex - 1 : this.rowCount - 1;
+ } else {
+ this.selectionFlag = "x";
+ this.startRow = this.shiftRow;
+ }
if (((this.startRow <= rowIndex) && (this.firstIndex <= this.startRow ||
rowIndex < this.firstIndex))
- || (this.startRow > rowIndex && this.firstIndex < this.startRow
&& rowIndex < this.firstIndex)) {
+ || (this.startRow > rowIndex && this.firstIndex <= this.startRow
&& rowIndex < this.firstIndex)) {
this.endRow = rowIndex;
} else {
this.endRow = this.startRow;
@@ -444,7 +466,8 @@
},
selectionChanged: function(event) {
- $(this.inputElement).value = this.selection.inspectRanges() + this.activeRow +
";" + (this.selectionFlag ? this.selectionFlag : "") ;
+ $(this.inputElement).value = this.selection.inspectRanges() + this.activeRow +
"|"
+ + (this.shiftRow ? this.shiftRow : this.activeRow) + ";" +
(this.selectionFlag ? this.selectionFlag : "") ;
var state = this.selection.getState();
event.oldSelection = this.oldState;
event.newSelection = state;