Author: abelevich
Date: 2007-05-24 14:35:20 -0400 (Thu, 24 May 2007)
New Revision: 875
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/AjaxFunctionBuilder.java
Removed:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/OnCompleteFunctionBuilder.java
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
Log:
Copied:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/AjaxFunctionBuilder.java
(from rev 853,
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/OnCompleteFunctionBuilder.java)
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/AjaxFunctionBuilder.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/AjaxFunctionBuilder.java 2007-05-24
18:35:20 UTC (rev 875)
@@ -0,0 +1,47 @@
+/**
+ *
+ */
+package org.richfaces.renderkit.html;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.framework.renderer.RendererBase;
+import org.ajax4jsf.framework.util.javascript.JSFunction;
+import org.ajax4jsf.framework.util.javascript.JSFunctionDefinition;
+import org.ajax4jsf.framework.util.javascript.JSReference;
+import org.richfaces.component.UIScrollableGrid;
+
+
+public class AjaxFunctionBuilder {
+
+// public static final String DATA_READY = ;
+
+ private static final JSReference request = new JSReference("request");
+ private static final JSReference event = new JSReference("event");
+ private static final JSReference data = new JSReference("data");
+
+ public static JSFunction createFunction(String name) {
+ JSFunction function = new JSFunction(name);
+ function.addParameter(request);
+ function.addParameter(event);
+ function.addParameter(data);
+
+ return function;
+ }
+
+ public static JSFunctionDefinition getOnDataReady(FacesContext context, UIScrollableGrid
grid, RendererBase renderer) {
+
+ ScrollableGridBaseRenderer sr = (ScrollableGridBaseRenderer)renderer;
+ JSFunction function = createFunction(sr.getJavaScriptVarName(context, grid) +
".onCompleteGridInvalidation");
+// JSFunction function = createFunction(sr.getJavaScriptVarName(context, grid) +
".getModel().fireEvent");
+ JSFunctionDefinition functionDefinition = new JSFunctionDefinition();
+ functionDefinition.addToBody(function);
+ functionDefinition.addParameter(request);
+ functionDefinition.addParameter(event);
+ functionDefinition.addParameter(data);
+
+ return functionDefinition;
+ }
+
+
+}
\ No newline at end of file
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java 2007-05-24
18:34:56 UTC (rev 874)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java 2007-05-24
18:35:20 UTC (rev 875)
@@ -218,6 +218,9 @@
* @return Returns the rowIndex.
*/
public int getRowIndex() {
+ if(_rowIndex >= _loadedRowsCount){
+ _rowIndex = 0;
+ }
return _rowIndex;
}
@@ -226,12 +229,7 @@
* @return new row number.
*/
public int nextRow(){
- if(_rowIndex > _loadedRowsCount)
- _rowIndex = 0;
- else{
- _rowIndex ++;
- }
-
+ _rowIndex = _rowIndex + 1;
return _rowIndex;
}
@@ -359,12 +357,12 @@
this.sumWidth = sumWidth;
}
- public int get_loadedRowsCount() {
+ public int getLoadedRowsCount() {
return _loadedRowsCount;
}
- public void set_loadedRowsCount(int rowsCount) {
- _loadedRowsCount = rowsCount;
+ public void setLoadedRowsCount(int loadedRowsCount) {
+ _loadedRowsCount = loadedRowsCount;
}
public Integer getSepOffset() {
Deleted:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/OnCompleteFunctionBuilder.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/OnCompleteFunctionBuilder.java 2007-05-24
18:34:56 UTC (rev 874)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/OnCompleteFunctionBuilder.java 2007-05-24
18:35:20 UTC (rev 875)
@@ -1,48 +0,0 @@
-/**
- *
- */
-package org.richfaces.renderkit.html;
-
-import java.util.Map;
-
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.framework.renderer.RendererBase;
-import org.ajax4jsf.framework.util.javascript.JSFunction;
-import org.ajax4jsf.framework.util.javascript.JSFunctionDefinition;
-import org.ajax4jsf.framework.util.javascript.JSReference;
-import org.richfaces.component.UIScrollableGrid;
-
-
-public class OnCompleteFunctionBuilder {
-
-// public static final String DATA_READY = ;
-
- private static final JSReference request = new JSReference("request");
- private static final JSReference event = new JSReference("event");
- private static final JSReference data = new JSReference("data");
-
- public static JSFunction createFunction(String name) {
- JSFunction function = new JSFunction(name);
- function.addParameter(request);
- function.addParameter(event);
- function.addParameter(data);
-
- return function;
- }
-
- public static JSFunctionDefinition getOnDataReady(FacesContext context, UIScrollableGrid
grid, RendererBase renderer) {
-
- ScrollableGridBaseRenderer sr = (ScrollableGridBaseRenderer)renderer;
- JSFunction function = createFunction(sr.getJavaScriptVarName(context, grid) +
".onCompleteGridInvalidation");
-// JSFunction function = createFunction(sr.getJavaScriptVarName(context, grid) +
".getModel().fireEvent");
- JSFunctionDefinition functionDefinition = new JSFunctionDefinition();
- functionDefinition.addToBody(function);
- functionDefinition.addParameter(request);
- functionDefinition.addParameter(event);
- functionDefinition.addParameter(data);
-
- return functionDefinition;
- }
-
-}
\ No newline at end of file
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-05-24
18:34:56 UTC (rev 874)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-05-24
18:35:20 UTC (rev 875)
@@ -17,8 +17,10 @@
import org.ajax4jsf.framework.renderer.RendererBase;
import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
import org.ajax4jsf.framework.util.javascript.JSFunction;
+import org.ajax4jsf.framework.util.javascript.JSReference;
import org.richfaces.component.UIScrollableGrid;
import org.richfaces.component.UIScrollableGridColumn;
+import org.richfaces.event.sort.SortEvent;
import org.richfaces.renderkit.CompositeRenderer;
import org.richfaces.utils.TemplateLoader;
@@ -134,6 +136,7 @@
public void renderContent(FacesContext context, UIScrollableGridColumn column,
ResponseWriter writer, GridRendererState state) throws IOException {
String cell_id = state.getRowIndex()+ "_" + state.getCellIndex();
+ System.out.println("cell_index: " + cell_id);
String client_id = state.getClientId();
int cell_index = state.getCellIndex();
cellTemplate = getCellTemplate();
@@ -169,8 +172,12 @@
state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
getUtils().writeAttribute(writer, "id",row_id);
getUtils().writeAttribute(writer, "class","ClientUI_Grid_BR");
+
+ System.out.println("rowIndex : " + index);
+
ColumnWalker.iterateOverColumns(context, grid, cellRenderer, writer, state);
writer.endElement(HTML.TR_ELEMENT);
+ state.nextRow();
}
}
@@ -193,8 +200,7 @@
String cell_id = state.getClientId() + ":" + CELL_ID_PREFFIX +
state.getRowIndex()+ "_" + state.getCellIndex();
getUtils().writeAttribute(writer, "id",cell_id);
getUtils().writeAttribute(writer, "class",
"ClientUI_Grid_BCBody");
-// getUtils().writeAttribute(writer, "style", "width:" +
columnWidth);
-// System.out.println("cell index: " + cell_id);
+ System.out.println("cell index: " + cell_id);
renderChildren(context, column);
writer.endElement(HTML.SPAN_ELEM);
AjaxContext ajaxContext = state.getAjaxContext();
@@ -242,9 +248,14 @@
state.setColumType(COLUMN_NORMAL_TYPE);
}
+ System.out.println("");
+ System.out.println("ScrollableGridBaseRenderer.renderGridBody()");
+ System.out.println("");
+
state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
state.setFrozenPart(isFrozen);
state.setClientId(grid.getClientId(context));
+ state.setLoadedRowsCount(grid.getRows());
grid.walk(context, rowsRenderer, state);
grid.setRowKey(null);
}
@@ -304,13 +315,33 @@
JSFunction function = AjaxRendererUtils.buildAjaxFunction(grid, context);
Map options = AjaxRendererUtils.buildEventOptions(context, grid);
- options.put("oncomplete", OnCompleteFunctionBuilder.getOnDataReady(context,
grid, this));
+ options.put("oncomplete", AjaxFunctionBuilder.getOnDataReady(context, grid,
this));
function.addParameter(options);
-
String completeFunction = function.toScript()+"; return false;";
+
return completeFunction;
}
+
+ public String onSortAjaxUpdate(FacesContext context, UIScrollableGrid grid){
+
+ JSReference index = new JSReference("index");
+ JSReference order = new JSReference("order");
+ Map options = AjaxRendererUtils.buildEventOptions(context, grid);
+
+ Map parametersMap = (Map)options.get("parameters");
+ String id = grid.getClientId(context);
+ parametersMap.put(id + ":index", index);
+ parametersMap.put(id + ":order", order);
+
+ options.put("parameters", parametersMap);
+
+ JSFunction function = AjaxRendererUtils.buildAjaxFunction(grid, context);
+ function.addParameter(options);
+ String completeFunction = function.toScript() + "; return false;";
+
+ return completeFunction;
+ }
protected void doDecode(FacesContext context, UIComponent component) {
@@ -320,21 +351,25 @@
UIScrollableGrid grid = (UIScrollableGrid)component;
ExternalContext externalContext = context.getExternalContext();
- String clientId = grid.getClientId(context) + "_state_input";
+ String clientId = grid.getClientId(context);
Map parameters = externalContext.getRequestParameterMap();
- if(parameters.containsKey(clientId)){
+
+ if(parameters.containsKey(clientId + ":order") &&
parameters.containsKey(clientId + ":index")){
+
+ boolean isAsc = false;
+ String order = (String)parameters.get(clientId + ":order");
+ int index = Integer.parseInt((String)parameters.get(clientId + ":index"));
+ if(order.equals("asc")){
+ isAsc = true;
+ }
+ SortEvent sortEvent = new SortEvent(grid,index, isAsc);
+ grid.queueEvent(sortEvent);
+ }
- String submitedState = (String)parameters.get(clientId);
- String [] values = submitedState.split(",");
- grid.setRow_count(new Integer(Integer.parseInt(values[0])));
- grid.setDataIndex(new Integer(Integer.parseInt(values[1])));
- grid.setStartRow(new Integer(Integer.parseInt(values[2])));
-
- System.out.println("row count: " + grid.getRow_count());
- System.out.println("data index: " + grid.getDataIndex());
- System.out.println("start row: " + grid.getStartRow());
-
+ if(parameters.containsKey(clientId + "_state_input")){
+ String submitedState = (String)parameters.get(clientId + "_state_input");
+ decodeScrolling(submitedState, grid);
grid.queueEvent(new AjaxEvent(grid));
}
@@ -343,16 +378,40 @@
}
+ private void decodeScrolling(String submitedState, UIScrollableGrid grid){
+
+ boolean isEmpty = true;
+
+
+ String [] values = submitedState.split(",");
+ for (int i = 0; i < values.length; i++) {
+ isEmpty = isEmpty && values[i].equals("");
+ }
+
+ if(!isEmpty){
+ grid.setRow_count(new Integer(Integer.parseInt(values[0])));
+ grid.setDataIndex(new Integer(Integer.parseInt(values[1])));
+ grid.setStartRow(new Integer(Integer.parseInt(values[2])));
+ }else{
+ grid.setRow_count(new Integer(grid.getRows()));
+ grid.setDataIndex(new Integer(0));
+ grid.setStartRow(new Integer(grid.getFirst()));
+ }
+ System.out.println("");
+ System.out.println("row count: " + grid.getRow_count());
+ System.out.println("data index: " + grid.getDataIndex());
+ System.out.println("start row: " + grid.getStartRow());
+ }
+
+
public void renderAjaxChildren(FacesContext context, UIComponent component)throws
IOException{
UIScrollableGrid grid = (UIScrollableGrid)component;
-
GridRendererState state = GridRendererState.createState(context, grid);
grid.setFirst(grid.getDataIndex().intValue());
int old = grid.getRows();
- state.set_loadedRowsCount(old);
-
- grid.setRows(grid.getRow_count().intValue());
+ state.setLoadedRowsCount(old);
+ grid.setRows(grid.getRow_count().intValue() + 1);
int start_row = grid.getStartRow().intValue();
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
@@ -360,6 +419,11 @@
state.setClientId(client_id);
state.setAjaxContext(ajaxContext);
state.setRowIndex(start_row);
+
+ System.out.println("");
+ System.out.println("ScrollableGridBaseRenderer.renderAjaxChildren()");
+ System.out.println("");
+
grid.walk(context, ajaxRowsRenderer, state);
ajaxContext.getAjaxRenderedAreas().remove(grid.getClientId(context));
grid.setRows(old);