Author: abelevich
Date: 2007-05-11 11:32:24 -0400 (Fri, 11 May 2007)
New Revision: 737
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnWalker.java
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:
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnWalker.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnWalker.java 2007-05-11
15:32:13 UTC (rev 736)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnWalker.java 2007-05-11
15:32:24 UTC (rev 737)
@@ -21,7 +21,7 @@
public class ColumnWalker {
static void iterateOverHeadersFooters(FacesContext context, UIComponent component,
- ColumnVisitor visitor, ResponseWriter writer) throws IOException{
+ ColumnVisitor visitor, ResponseWriter writer, GridRendererState state) throws
IOException{
if(context == null || component == null){
throw new NullPointerException();
@@ -41,7 +41,11 @@
UIComponent kid = (UIComponent) iter.next();
if (kid.isRendered()) {
if (kid instanceof UIScrollableGridColumn){
- visitor.visit(context, (UIScrollableGridColumn)kid, writer, null);
+ if(state.isFrozenColumn()){
+ int i = state.getFrozenColumnCount() - 1;
+ state.setFrozenColumnCount(i);
+ }
+ visitor.visit(context, (UIScrollableGridColumn)kid, writer, state);
}
}
}
@@ -68,14 +72,16 @@
UIComponent kid = (UIComponent) iter.next();
if (kid.isRendered()) {
if (kid instanceof UIScrollableGridColumn){
-
UIScrollableGridColumn column = (UIScrollableGridColumn)kid;
- Boolean frozen = ((Boolean)column.getAttributes().get("frozen"));
+
+ if(state.isFrozenColumn()){
+ int i = state.getFrozenColumnCount();
+ i--;
+ state.setFrozenColumnCount(i);
+ visitor.visit(context, column, writer,state);
- if(state.is_isFrozenColumn() && frozen.booleanValue()){
- visitor.visit(context, (UIScrollableGridColumn)kid, writer,state);
- } else if(!state.is_isFrozenColumn() && !frozen.booleanValue()){
- visitor.visit(context, (UIScrollableGridColumn)kid, writer, state);
+ } else if(!state.isFrozenColumn()){
+ visitor.visit(context,column, writer, state);
}
state.nextCell();
}
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-11
15:32:13 UTC (rev 736)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java 2007-05-11
15:32:24 UTC (rev 737)
@@ -11,6 +11,7 @@
import javax.faces.context.FacesContext;
import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
+import org.apache.commons.digester.xmlrules.FromXmlRuleSet;
import org.richfaces.component.UIScrollableGrid;
/**
@@ -32,7 +33,7 @@
private int _columns = 0;
- private boolean _isFrozenColumn = false;
+ private int _frozenColumnCount = -1;
private UIScrollableGrid _grid;
@@ -260,11 +261,16 @@
this.rowKey = rowKey;
}
- public boolean is_isFrozenColumn() {
- return _isFrozenColumn;
+ public boolean isFrozenColumn() {
+ return _frozenColumnCount < 0 ? false:true;
}
- public void set_isFrozenColumn(boolean frozenColumn) {
- _isFrozenColumn = frozenColumn;
+ public void setFrozenColumnCount(int columnCount) {
+ _frozenColumnCount = columnCount;
}
+
+ public int getFrozenColumnCount() {
+ return _frozenColumnCount;
+ }
+
}
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-11
15:32:13 UTC (rev 736)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-05-11
15:32:24 UTC (rev 737)
@@ -10,6 +10,7 @@
import org.ajax4jsf.ajax.repeat.DataVisitor;
import org.ajax4jsf.framework.ajax.AjaxContext;
+import org.ajax4jsf.framework.ajax.AjaxEvent;
import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
import org.ajax4jsf.framework.renderer.ComponentVariables;
import org.ajax4jsf.framework.renderer.ComponentsVariableResolver;
@@ -43,7 +44,8 @@
ResponseWriter writer, GridRendererState state) throws IOException {
writer.startElement(HTML.td_ELEM, column);
- getUtils().writeAttribute(writer, "frozen",
column.getAttributes().get("frozen"));
+ String frozen = Boolean.toString(state.isFrozenColumn());
+ getUtils().writeAttribute(writer, "frozen",frozen );
getUtils().writeAttribute(writer,
"style",column.getAttributes().get("style"));
writer.writeText("\n", null);
@@ -89,6 +91,21 @@
}
};
+ private final DataVisitor rowsRenderer = new DataVisitor(){
+
+ public void process(FacesContext context, Object rowIndex, Object argument) throws
IOException {
+ GridRendererState state = (GridRendererState)argument;
+ UIScrollableGrid grid = state.getGrid();
+ int index = ((Integer)rowIndex).intValue();
+ grid.setRowKey(rowIndex);
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement(HTML.TR_ELEMENT, grid);
+ getUtils().writeAttribute(writer, "id","row_"+ index);
+ getUtils().writeAttribute(writer, "class","ClientUI_Grid_BR");
+ ColumnWalker.iterateOverCells(context, grid, cellRenderer, writer, state);
+ writer.endElement(HTML.TR_ELEMENT);
+ }
+ };
protected String getJavaScriptVarName(FacesContext context, UIScrollableGrid grid) {
String id = grid.getBaseClientId(context);
@@ -132,13 +149,13 @@
getUtils().writeAttribute(writer, "style","position: absolute; left:
0px; top: 0px; display: block; width: 100%");
writer.writeText("\n", null);
writer.startElement("tbody", grid);
+// state.setGrid(grid);
DataVisitor rowsRenderer = new DataVisitor(){
public void process(FacesContext context, Object rowIndex, Object argument) throws
IOException {
-
+
int index = ((Integer)rowIndex).intValue();
- state.setRowIndex(index);
grid.setRowKey(rowIndex);
ResponseWriter writer = context.getResponseWriter();
writer.startElement(HTML.TR_ELEMENT, grid);
@@ -149,7 +166,8 @@
}
};
- state.set_isFrozenColumn(true);
+ state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
+
grid.walk(context, rowsRenderer, state);
writer.endElement("tbody");
@@ -168,7 +186,8 @@
getUtils().writeAttribute(writer, "style","position: absolute; left:
0px; top: 0px; display: block; width: 100%");
writer.writeText("\n", null);
- state.set_isFrozenColumn(false);
+ state.setFrozenColumnCount(-1);
+
grid.walk(context, rowsRenderer, state);
writer.endElement("tbody");
writer.endElement("table");
@@ -177,18 +196,22 @@
}
- public void renderHeaders(FacesContext context, UIComponent component
+ public void renderHeaders(FacesContext context, UIScrollableGrid component
)throws IOException{
ResponseWriter writer = context.getResponseWriter();
- ColumnWalker.iterateOverHeadersFooters(context, component, headerRenderer, writer);
+ final GridRendererState state = GridRendererState.getRendererState(context);
+ state.setFrozenColumnCount(((Integer)component.getAttributes().get("frozenColCount")).intValue());
+ ColumnWalker.iterateOverHeadersFooters(context, component, headerRenderer, writer,
state);
}
- public void renderFooters(FacesContext context, UIComponent component
+ public void renderFooters(FacesContext context, UIScrollableGrid component
) throws IOException{
ResponseWriter writer = context.getResponseWriter();
- ColumnWalker.iterateOverHeadersFooters(context, component, footerRenderer, writer);
+ final GridRendererState state = GridRendererState.getRendererState(context);
+ state.setFrozenColumnCount(((Integer)component.getAttributes().get("frozenColCount")).intValue());
+ ColumnWalker.iterateOverHeadersFooters(context, component, footerRenderer, writer,
state);
}
public void setUpState(FacesContext context, UIScrollableGrid grid) {
@@ -210,67 +233,63 @@
protected void doDecode(FacesContext context, UIComponent component) {
- String value = null;
+ super.doDecode(context, component);
if(component instanceof UIScrollableGrid){
+
UIScrollableGrid grid = (UIScrollableGrid)component;
ExternalContext externalContext = context.getExternalContext();
String clientId = grid.getClientId(context) + "_state_input";
Map parameters = externalContext.getRequestParameterMap();
if(parameters.containsKey(clientId)){
- value = (String)parameters.get(clientId);
-
+ String submitedState = (String)parameters.get(clientId);
+ String [] values = submitedState.split(",");
+ grid.setRow_count(Integer.getInteger(values[0]));
+ grid.setDataIndex(Integer.getInteger(values[1]));
+ grid.setStartRow(Integer.getInteger(values[2]));
+ grid.queueEvent(new AjaxEvent(grid));
}
+
}
- super.doDecode(context, component);
}
-
-// for benchmark
- public void encodeBegin(FacesContext context, UIComponent component
- ) throws IOException {
-
- if(AjaxContext.getCurrentInstance().isAjaxRequest()){
- }else{
- super.encodeBegin(context, component);
- }
+ public void renderAjaxChildren(FacesContext context, UIComponent component)throws
IOException{
+ UIScrollableGrid grid = (UIScrollableGrid)component;
+ grid.setFirst(grid.getDataIndex().intValue());
+ grid.setRows(grid.getRow_count().intValue());
+ GridRendererState state = GridRendererState.getRendererState(context);
+ grid.walk(context, rowsRenderer, state);
}
- public void encodeEnd(FacesContext context, UIComponent component
- ) throws IOException {
- if(AjaxContext.getCurrentInstance().isAjaxRequest()){
- }else{
- super.encodeEnd(context, component);
- }
- }
+// for benchmark
+// public void encodeBegin(FacesContext context, UIComponent component
+// ) throws IOException {
+//
+// if(AjaxContext.getCurrentInstance().isAjaxRequest()){
+// }else{
+// super.encodeBegin(context, component);
+// }
+// }
+//
+// public void encodeEnd(FacesContext context, UIComponent component
+// ) throws IOException {
+//
+// if(AjaxContext.getCurrentInstance().isAjaxRequest()){
+// }else{
+// super.encodeEnd(context, component);
+// }
+// }
-
-
public void encodeChildren(FacesContext context, UIComponent component
) throws IOException {
-
- ResponseWriter writer = context.getResponseWriter();
AjaxContext ajaxContext = AjaxContext.getCurrentInstance();
if(ajaxContext.isAjaxRequest()){
- writer.startElement("div", component);
- for (int i = 0; i < 100; i++) {
- for (int j = 0; j < 18; j++) {
- writer.startElement("span", component);
-
- String id = "bc_" + i + "_" + j;
- getUtils().writeAttribute(writer,"id", id);
- writer.writeText(i + ":" + j + " test" + i, null);
- writer.endElement("span");
- ajaxContext.addRenderedArea(id);
- }
-
- }
- writer.endElement("div");
-
+// renderAjaxChildren(context, component);
}else{
super.encodeChildren(context, component);
}
}
+
}