Author: maksimkaszynski
Date: 2007-06-08 10:38:45 -0400 (Fri, 08 Jun 2007)
New Revision: 1099
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridUtils.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/ScrollableGrid.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUILib.js
Log:
selection - correct order
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridUtils.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridUtils.java 2007-06-08
14:12:06 UTC (rev 1098)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridUtils.java 2007-06-08
14:38:45 UTC (rev 1099)
@@ -3,6 +3,8 @@
*/
package org.richfaces.renderkit.html;
+import javax.faces.component.UIComponent;
+
import org.richfaces.component.UIScrollableGrid;
/**
@@ -12,9 +14,24 @@
public class GridUtils {
public static final String FROZEN_COL_COUNT_ATTR = "frozenColCount";
+ public static final String CLIENT_ROW_KEY = "clientIndex";
public static int getFrozenColumnsCount(UIScrollableGrid grid) {
- return ((Integer)grid.getAttributes().get(FROZEN_COL_COUNT_ATTR)).intValue();
+ return getIntOr0(grid, FROZEN_COL_COUNT_ATTR);
}
+ public static int getClientRowIndex(UIScrollableGrid grid) {
+ return getIntOr0(grid, CLIENT_ROW_KEY);
+ }
+
+ public static int getIntOr0(UIComponent grid, String attribute) {
+ Object value = grid.getAttributes().get(attribute);
+ int i = 0;
+ if (value instanceof Number) {
+ i = ((Number) value).intValue();
+ }
+
+ return i;
+ }
+
}
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-06-08
14:12:06 UTC (rev 1098)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-06-08
14:38:45 UTC (rev 1099)
@@ -49,7 +49,6 @@
private final String COLUMN_NORMAL_TYPE = "normal";
- private String CLIENT_ROW_KEY = "clientIndex";
private RendererBase cellTemplate = null;
@@ -505,13 +504,17 @@
if(column.isSortable()){
- grid.getAttributes().put(CLIENT_ROW_KEY,sortStartRow);
+ grid.getAttributes().put(GridUtils.CLIENT_ROW_KEY,sortStartRow);
grid.setFirst(sortDataIndex);
grid.setRows(grid.getDefaultRows());
- System.out.println("rows " + grid.getRows() );
- System.out.println("client start index" +
grid.getAttributes().get(CLIENT_ROW_KEY));
- System.out.println("data index " + grid.getFirst());
+ if (log.isDebugEnabled()) {
+
+ log.debug("rows " + grid.getRows() );
+ log.debug("client start index" +
grid.getAttributes().get(GridUtils.CLIENT_ROW_KEY));
+ log.debug("data index " + grid.getFirst());
+
+ }
sorted = true;
SortEvent sortEvent = new SortEvent(grid,sortColumn, sortStartRow.intValue(),
sortDataIndex, asc );
@@ -544,16 +547,16 @@
grid.setRows(Integer.parseInt(values[0]));
grid.setFirst(Integer.parseInt(values[1]));
- grid.getAttributes().put(CLIENT_ROW_KEY,Integer.valueOf(values[2]));
+ grid.getAttributes().put(GridUtils.CLIENT_ROW_KEY,Integer.valueOf(values[2]));
}else{
- grid.getAttributes().put(CLIENT_ROW_KEY, new Integer(0));
+ grid.getAttributes().put(GridUtils.CLIENT_ROW_KEY, new Integer(0));
}
if (log.isDebugEnabled()) {
log.debug("");
log.debug("row count: " + grid.getRows());
log.debug("data index: " + grid.getFirst()) ;
- log.debug("start row: " + grid.getAttributes().get(CLIENT_ROW_KEY));
+ log.debug("start row: " +
grid.getAttributes().get(GridUtils.CLIENT_ROW_KEY));
}
}
@@ -568,7 +571,7 @@
state.setClientId(client_id);
state.setAjaxContext(ajaxContext);
- state.setRowIndex(((Integer)grid.getAttributes().get(CLIENT_ROW_KEY)).intValue());
+ state.setRowIndex(GridUtils.getClientRowIndex(grid));
if (log.isDebugEnabled()) {
log.debug("ScrollableGridBaseRenderer.renderAjaxChildren()");
@@ -605,7 +608,7 @@
private GridScrollSettings createOptions(UIScrollableGrid grid){
int index = grid.getFirst();
- int startRow = ((Integer)grid.getAttributes().get(CLIENT_ROW_KEY)).intValue();
+ int startRow = GridUtils.getClientRowIndex(grid);
int count = grid.getRows();
GridScrollSettings options = new GridScrollSettings(index, startRow, count);
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java 2007-06-08
14:12:06 UTC (rev 1098)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/SelectionRendererContributor.java 2007-06-08
14:38:45 UTC (rev 1099)
@@ -73,8 +73,10 @@
final GridRendererState state =
GridRendererState.createState(context, grid);
- final SimpleSelection simpleSelection = new SimpleSelection();
+ state.setRowIndex(GridUtils.getClientRowIndex(grid));
+ final SimpleSelection simpleSelection = grid.getSelection() == null ? new
SimpleSelection() : (SimpleSelection) grid.getSelection();
+
try {
grid.walk(context,
new DataVisitor() {
@@ -93,6 +95,8 @@
}
+ state.nextRow();
+
}
},
state);
@@ -100,6 +104,7 @@
throw new FacesException(e);
}
+ grid.setSelection(simpleSelection);
GridRendererState.restoreState(context);
}
@@ -163,19 +168,24 @@
//Decide whether to add new row to selection based on comparison with old one
private boolean shouldAddToSelection(int i, ClientSelection oldSelection,
ClientSelection newSelection) {
- return false;
+ return newSelection.isSelected(i) && !oldSelection.isSelected(i);
}
//Decide whether to remove new row to selection based on comparison with old one
private boolean shouldRemoveFromSelection(int i, ClientSelection oldSelection,
ClientSelection newSelection) {
- return false;
+ return !newSelection.isSelected(i) && oldSelection.isSelected(i);
}
private void encodeSelection(FacesContext context, UIScrollableGrid grid) throws
IOException {
final GridRendererState state = GridRendererState.createState(context, grid);
- final Selection gridSelection = new SimpleSelection();
+ state.setRowIndex(GridUtils.getClientRowIndex(grid));
+
+ final Selection gridSelection =
+ grid.getSelection() == null ?
+ new SimpleSelection() :
+ grid.getSelection();
final ClientSelection clientSelection = new ClientSelection();
grid.walk(context,
@@ -191,8 +201,8 @@
}
+ state.nextRow();
-
}
},
state);
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js 2007-06-08
14:12:06 UTC (rev 1098)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/common/utils/Utils.js 2007-06-08
14:38:45 UTC (rev 1099)
@@ -63,18 +63,19 @@
target.parentNode.replaceChild(src, target);
+ return src;
}
},
AJAX : {
- updateRows: function(options,request,grid,clientid){
+ updateRows: function(options,request,grid,clientid, callbacks){
var theDoc = document;
var getEl = theDoc.getElementById;
var localOptions = options;
var rowCount = grid.getBody().templFrozen.getElement().rows.length;
var startRow = localOptions.startRow;
var count = localOptions.count;
- var row, id, rowindex, i, el;
+ var rowindex, i, el;
var dataModel = grid.dataModel;
var baseid = clientid;
@@ -83,14 +84,29 @@
if(rowindex >= rowCount){
rowindex -= rowCount;
}
+ var id = baseid + ":f:" + rowindex;
+ var row = Utils.DOM.replaceNode(id, request);
+ id = baseid + ":n:" + rowindex;
+ row = Utils.DOM.replaceNode(id, request);
+
+
+ [":f:", ":n:"].each(
+ function(suffix) {
+ var id = baseid + suffix + rowindex;
+ var row = Utils.DOM.replaceNode(id, request);
+
+ if (callbacks) {
+ callbacks.each(
+ function(callback) {
+ callback.call(grid, {index : rowindex, row : row});
+ }
+ );
+ }
+
+ }
+ );
- id = baseid + ":f:" + rowindex;
- Utils.DOM.replaceNode(id, request);
-
- id = baseid + ":n:" + rowindex;
-
- Utils.DOM.replaceNode(id, request);
}
dataModel.eventDataReady.fire(localOptions);
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid.js
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid.js 2007-06-08
14:12:06 UTC (rev 1098)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid.js 2007-06-08
14:38:45 UTC (rev 1099)
@@ -60,6 +60,7 @@
this.eventOnResizeColumn = new
ClientUI.common.utils.CustomEvent('OnResizeColumn');
this.createControl();
+
},
createControl: function() {
//TODO: delete
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody.js
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody.js 2007-06-08
14:12:06 UTC (rev 1098)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody.js 2007-06-08
14:38:45 UTC (rev 1099)
@@ -54,7 +54,6 @@
this.createControl(template);
this.registerEvents();
this.updateLayout();
- this.selectionManager = new ClientUI.controls.grid.SelectionManager(this.grid);
},
registerEvents: function() {
Event.observe(this.scrollBox.eventHScroll, "grid body hscroll",
this._eventOnHScroll);
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/ScrollableGrid.js
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/ScrollableGrid.js 2007-06-08
14:12:06 UTC (rev 1098)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/ScrollableGrid.js 2007-06-08
14:38:45 UTC (rev 1099)
@@ -25,6 +25,9 @@
];
this.init2 = this.init.bindAsEventListener(this);
+
+ this.rowCallbacks = [];
+
// this.init()
},
@@ -35,20 +38,27 @@
var progress = new ClientUI.common.box.SplashBox(this.splash_id, null, 300, true);
this.setProgressCtrl(progress);
Event.observe(this.eventOnSort, "on sort",
this.onSorted.bindAsEventListener(this));
+ this.selectionManager = new ClientUI.controls.grid.SelectionManager(this);
},
onSortComplete : function(request, event, data){
var options = request.getJSON("options");
- Utils.AJAX.updateRows(options,request, this, this.client_id);
+ Utils.AJAX.updateRows(options,request,this,this.client_id,
[this.updateSelectionCallBack]);
+ this.selectionManager.restoreState();
},
onScrollComplete : function(request, event, data){
var options = this.dataModel.getCurrentOptions();
- Utils.AJAX.updateRows(options,request,this,this.client_id);
+ Utils.AJAX.updateRows(options,request,this,this.client_id,
[this.updateSelectionCallBack]);
+ this.selectionManager.restoreState();
},
onSorted: function(sortEvent) {
this.options.onSortAjaxUpdate(sortEvent);
+ },
+
+ updateSelectionCallBack: function(argMap) {
+ this.selectionManager.addListener(argMap.row, argMap.index);
}
});
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js 2007-06-08
14:12:06 UTC (rev 1098)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Selection.js 2007-06-08
14:38:45 UTC (rev 1099)
@@ -190,6 +190,9 @@
var gridElement = grid.getElement();
this.prefix = gridElement.id;
this.selection = new ClientUI.controls.grid.Selection();
+
+ this.inputElement = grid.options.selectionInput;
+
this.restoreState();
this.eventKeyPress = this.processKeyDown.bindAsEventListener(this);
Event.observe(document, "keypress", this.eventKeyPress);
@@ -213,6 +216,7 @@
Event.observe(gridElement, "click", this.eventPreventLostFocus);
+
// var selChangeHandler = this.grid.options.onselectionchange;
// if (selChangeHandler) {
// IL.Event.observe(this.grid.element, "selectionchange", selChangeHandler);
@@ -225,7 +229,7 @@
},
restoreState: function() {
- this.selection.initRanges($(this.prefix+":s").value);
+ this.selection.initRanges($(this.inputElement).value);
var i = 0;
var j;
while(i < this.selection.ranges.length) {
Modified: trunk/sandbox/scrollable-grid/src/main/javascript/ClientUILib.js
===================================================================
--- trunk/sandbox/scrollable-grid/src/main/javascript/ClientUILib.js 2007-06-08 14:12:06
UTC (rev 1098)
+++ trunk/sandbox/scrollable-grid/src/main/javascript/ClientUILib.js 2007-06-08 14:38:45
UTC (rev 1099)
@@ -10,6 +10,7 @@
packages: [],
load: function(showLog) {
// Check for Prototype JavaScript framework
+ /*
if((typeof Prototype=='undefined') ||
(typeof Element == 'undefined') ||
(typeof Element.Methods=='undefined') ||
@@ -27,11 +28,11 @@
}).each( function(s) {
LibraryPath = s.src.replace(/ClientUILib\.js(\?.*)?$/,'');
});
-
- if(showLog) {
+ */
+ /*if(showLog) {
ClientUILogger.create("ClientUILogger");
this.startTime = (new Date()).getTime();
- }
+ }*/
this.initBrowser();
},
@@ -81,8 +82,21 @@
ClientUILib.log(ClientUILogger.INFO, "ClientUILib::declarePackage '" +
libName + "'");
},
log: function(level, infoText) {
- if(ClientUILogger.isCreated)
- ClientUILogger.log(level, infoText);
+ //if(ClientUILogger.isCreated)
+ //ClientUILogger.log(level, infoText);
+ switch(level) {
+ case ClientUILogger.INFO:
+ LOG.info(infoText);
+ break;
+ case ClientUILogger.WARNING:
+ LOG.warn(infoText);
+ break;
+ case ClientUILogger.ERROR:
+ LOG.error(infoText);
+ break;
+ default:
+ LOG.debug(infoText);
+ }
},
initBrowser: function() {
var ua = navigator.userAgent.toLowerCase();