Author: konstantin.mishin
Date: 2007-09-20 09:26:44 -0400 (Thu, 20 Sep 2007)
New Revision: 3014
Removed:
trunk/framework/api/src/main/java/org/richfaces/model/selection/ClientSelection.java
trunk/framework/api/src/main/java/org/richfaces/model/selection/SelectionRange.java
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/convert/selection/ClientSelectionConverter.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/selection/ClientSelection.java
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/Selection.js
Log:
RF-943
Deleted:
trunk/framework/api/src/main/java/org/richfaces/model/selection/ClientSelection.java
===================================================================
---
trunk/framework/api/src/main/java/org/richfaces/model/selection/ClientSelection.java 2007-09-20
13:10:19 UTC (rev 3013)
+++
trunk/framework/api/src/main/java/org/richfaces/model/selection/ClientSelection.java 2007-09-20
13:26:44 UTC (rev 3014)
@@ -1,129 +0,0 @@
-/**
- *
- */
-package org.richfaces.model.selection;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class ClientSelection implements Serializable{
-
- private static final long serialVersionUID = 5855157282287053681L;
-
- public static final String FLAG_RESET = "x";
-
- public static final String FLAG_ALL = "a";
-
- private String selectionFlag;
-
- private List ranges = new ArrayList();
-
- public ClientSelection() {
- }
-
-
- public void addRange(SelectionRange range) {
- ranges.add(range);
- }
-
- public boolean isSelected(int i) {
- boolean result = false;
- Iterator iterator = ranges.iterator();
- while (iterator.hasNext() && !result) {
- result |= ((SelectionRange) iterator.next()).within(i);
- }
- return result;
- }
-
- public List getRanges() {
- return ranges;
- }
-
- public void addIndex(int j) {
- if(this.isSelected(j)) return;
-
-
-
- SelectionRange firstRange = null;
-
- int s = ranges.size();
-
- int insertPosition = 0;
-
- for(int i = 0; i < s && insertPosition >= 0 ; i++) {
-
- firstRange = (SelectionRange) ranges.get(i);
-
- if (firstRange.getStartIndex() == j + 1) {
-
- firstRange.setStartIndex(j);
- insertPosition = -1;
-
- } else if (firstRange.getEndIndex() == j - 1) {
-
- firstRange.setEndIndex(j);
-
- if (i + 1 < s) {
- SelectionRange range2 = (SelectionRange) ranges.get(i + 1);
-
- if (range2.getStartIndex() == j || range2.getStartIndex() == j + 1) {
-
- ranges.remove(i + 1);
-
- firstRange.setEndIndex(range2.getEndIndex());
- }
- }
-
- insertPosition = -1;
-
- } else if (firstRange.getStartIndex() > j) {
- insertPosition = i;
- }
-
- }
-
- if (insertPosition >= 0) {
- firstRange = new SelectionRange(j,j);
- ranges.add(insertPosition, firstRange);
-
- return;
- }
-
-
- }
-
- private boolean reset = false;
- public boolean isReset() {
- return reset;
- }
-
- private boolean selectAll = false;
- public boolean isSelectAll() {
- return selectAll;
- }
-
-
- public String getSelectionFlag() {
- return selectionFlag;
- }
-
-
- public void setSelectionFlag(String selectionFlag) {
- this.selectionFlag = selectionFlag;
-
- reset = false;
- selectAll = false;
-
- if (FLAG_ALL.equals(selectionFlag)) {
- selectAll = true;
- } else if (FLAG_RESET.equals(selectionFlag)) {
- reset = true;
- }
- }
-}
Deleted:
trunk/framework/api/src/main/java/org/richfaces/model/selection/SelectionRange.java
===================================================================
---
trunk/framework/api/src/main/java/org/richfaces/model/selection/SelectionRange.java 2007-09-20
13:10:19 UTC (rev 3013)
+++
trunk/framework/api/src/main/java/org/richfaces/model/selection/SelectionRange.java 2007-09-20
13:26:44 UTC (rev 3014)
@@ -1,64 +0,0 @@
-/**
- *
- */
-package org.richfaces.model.selection;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class SelectionRange {
- private int startIndex = -1;;
- private int endIndex = -1;
-
- public SelectionRange(int startIndex, int endIndex) {
- super();
- this.startIndex = startIndex;
- this.endIndex = endIndex;
- }
-
- public int getStartIndex() {
- return startIndex;
- }
-
- public void setStartIndex(int startIndex) {
- this.startIndex = startIndex;
- }
-
- public int getEndIndex() {
- return endIndex;
- }
-
- public void setEndIndex(int endIndex) {
- this.endIndex = endIndex;
- }
-
- public boolean within(int index) {
- return startIndex <= index && endIndex >= index;
- }
-
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + endIndex;
- result = prime * result + startIndex;
- return result;
- }
-
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- final SelectionRange other = (SelectionRange) obj;
- if (endIndex != other.endIndex)
- return false;
- if (startIndex != other.startIndex)
- return false;
- return true;
- }
-
-
-}
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java 2007-09-20
13:10:19 UTC (rev 3013)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/component/UIScrollableDataTable.java 2007-09-20
13:26:44 UTC (rev 3014)
@@ -370,6 +370,8 @@
public abstract String getSortMode();
public abstract void setSortMode(String mode);
+ public abstract Object getActiveRowKey();
+ public abstract void setActiveRowKey(Object activeRowKey);
/* (non-Javadoc)
* @see org.ajax4jsf.component.UIDataAdaptor#setRowIndex(int)
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/convert/selection/ClientSelectionConverter.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/convert/selection/ClientSelectionConverter.java 2007-09-20
13:10:19 UTC (rev 3013)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/convert/selection/ClientSelectionConverter.java 2007-09-20
13:26:44 UTC (rev 3014)
@@ -62,6 +62,9 @@
}
final ClientSelection clientSelection = new ClientSelection();
+ if(stringSelection == null || stringSelection.length() == 0) {
+ return clientSelection;
+ }
String [] selections = stringSelection.split(";");
int length = selections.length;
@@ -69,6 +72,8 @@
clientSelection.setSelectionFlag(selections[length-1]);
length--;
}
+ clientSelection.setActiveRowIndex(Integer.parseInt(selections[length-1]));
+ length--;
for (int i = 0; i < length; i++) {
String range = selections[i];
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/selection/ClientSelection.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/selection/ClientSelection.java 2007-09-20
13:10:19 UTC (rev 3013)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/model/selection/ClientSelection.java 2007-09-20
13:26:44 UTC (rev 3014)
@@ -24,6 +24,8 @@
private String selectionFlag;
+ private int activeRowIndex = -1;
+
private List ranges = new ArrayList();
public ClientSelection() {
@@ -57,8 +59,8 @@
int s = ranges.size();
int insertPosition = 0;
-
- for(int i = 0; i < s && insertPosition >= 0 ; i++) {
+ int i;
+ for(i = 0; i < s && insertPosition >= 0 ; i++) {
firstRange = (SelectionRange) ranges.get(i);
@@ -86,6 +88,8 @@
} else if (firstRange.getStartIndex() > j) {
insertPosition = i;
+ } else if (insertPosition == 0 && i == s - 1) {
+ insertPosition = s;
}
}
@@ -128,4 +132,14 @@
reset = true;
}
}
+
+
+ public int getActiveRowIndex() {
+ return activeRowIndex;
+ }
+
+
+ public void setActiveRowIndex(int activeRowIndex) {
+ this.activeRowIndex = activeRowIndex;
+ }
}
Modified:
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java
===================================================================
---
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java 2007-09-20
13:10:19 UTC (rev 3013)
+++
trunk/ui/scrollableDataTable/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java 2007-09-20
13:26:44 UTC (rev 3014)
@@ -45,7 +45,7 @@
public void decode(FacesContext context, UIComponent component,
CompositeRenderer compositeRenderer) {
- UIScrollableDataTable grid = (UIScrollableDataTable) component;
+ final UIScrollableDataTable grid = (UIScrollableDataTable) component;
ExternalContext externalContext = context.getExternalContext();
Map requestParamMap = externalContext.getRequestParameterMap();
@@ -103,6 +103,9 @@
}
+ if(i == clientSelection.getActiveRowIndex()) {
+ grid.setActiveRowKey(rowKey);
+ }
state.nextRow();
}
@@ -194,7 +197,7 @@
}
- private void encodeSelection(FacesContext context, UIScrollableDataTable grid) throws
IOException {
+ private void encodeSelection(FacesContext context, final UIScrollableDataTable grid)
throws IOException {
final ScrollableDataTableRendererState state =
ScrollableDataTableRendererState.createState(context, grid);
state.setRowIndex(ScrollableDataTableUtils.getClientRowIndex(grid));
@@ -217,6 +220,9 @@
clientSelection.addIndex(i);
}
+ if (rowKey.equals(grid.getActiveRowKey())) {
+ clientSelection.setActiveRowIndex(state.getRowIndex());
+ }
state.nextRow();
@@ -245,13 +251,16 @@
Converter converter =
application.createConverter(ClientSelection.class);
+ ClientSelection selection =
(ClientSelection)grid.getAttributes().get(CLIENT_SELECTION);
String string =
- converter.getAsString(context, grid, grid.getAttributes().get(CLIENT_SELECTION));
+ converter.getAsString(context, grid, selection);
if (string == null) {
string = "";
}
+ string += selection.getActiveRowIndex();
+
String id = getSelectionInputName(context, grid);
Modified:
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/Selection.js
===================================================================
---
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/Selection.js 2007-09-20
13:10:19 UTC (rev 3013)
+++
trunk/ui/scrollableDataTable/src/main/javascript/ClientUI/controls/grid/Selection.js 2007-09-20
13:26:44 UTC (rev 3014)
@@ -150,13 +150,12 @@
this.ranges = ranges;
},
- initRanges: function(rangesStr) {
- if(!rangesStr) {
+ initRanges: function(rangeStrRArray) {
+ if(rangeStrRArray.length == 0) {
this.ranges = [];
return;
}
- var rangeStrRArray = rangesStr.split(";");
- this.ranges = new Array(rangeStrRArray.length -1);
+ this.ranges = new Array(rangeStrRArray.length);
var indexStrRArray;
for(var i = 0; i < this.ranges.length; i++) {
indexStrRArray = rangeStrRArray[i].split(",");
@@ -222,6 +221,7 @@
this.grid = grid;
this.selectionFlag;
this.firstIndex;
+ this.activeRow = -1;
var gridElement = grid.getElement();
this.prefix = gridElement.id;
this.selection = new ClientUI.controls.grid.Selection();
@@ -260,7 +260,15 @@
restoreState: function() {
this.selectionFlag = null;
- this.selection.initRanges($(this.inputElement).value);
+ var selStrAr = $(this.inputElement).value.split(";");
+ if(selStrAr.length != 0) {
+ var activeRowStr = selStrAr[selStrAr.length - 1];
+ if(activeRowStr.indexOf(";") == -1) {
+ this.setActiveRow(activeRowStr);
+ selStrAr.pop();
+ }
+ }
+ this.selection.initRanges(selStrAr);
// this.firstIndex = Number($(this.prefix +
":f").rows[0].id.split(this.prefix)[1].split(":")[2]);;
var i = 0;
var j;
@@ -441,7 +449,7 @@
},
selectionChanged: function(event) {
- $(this.inputElement).value = this.selection.inspectRanges()+ (this.selectionFlag ?
this.selectionFlag : "") ;
+ $(this.inputElement).value = this.selection.inspectRanges() + this.activeRow +
";" + (this.selectionFlag ? this.selectionFlag : "") ;
var state = this.selection.getState();
event.oldSelection = this.oldState;
event.newSelection = state;