Author: abelevich
Date: 2007-05-21 07:20:20 -0400 (Mon, 21 May 2007)
New Revision: 815
Removed:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer2.java
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java
Log:
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-21
11:20:10 UTC (rev 814)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java 2007-05-21
11:20:20 UTC (rev 815)
@@ -34,6 +34,10 @@
private int _columns = 0;
+ private Integer sepOffset;
+
+ private int _loadedRowsCount;
+
private String _cell_id_prefix;
private int sumWidth = 0;
@@ -222,10 +226,13 @@
* @return new row number.
*/
public int nextRow(){
- if(_rowIndex > _grid.getRows())
+ if(_rowIndex > _loadedRowsCount)
_rowIndex = 0;
+ else{
+ _rowIndex ++;
+ }
- return ++_rowIndex;
+ return _rowIndex;
}
/**
@@ -351,4 +358,20 @@
public void setSumWidth(int sumWidth) {
this.sumWidth = sumWidth;
}
+
+ public int get_loadedRowsCount() {
+ return _loadedRowsCount;
+ }
+
+ public void set_loadedRowsCount(int rowsCount) {
+ _loadedRowsCount = rowsCount;
+ }
+
+ public Integer getSepOffset() {
+ return sepOffset;
+ }
+
+ public void setSepOffset(Integer sepOffset) {
+ this.sepOffset = sepOffset;
+ }
}
Deleted:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer2.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer2.java 2007-05-21
11:20:10 UTC (rev 814)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer2.java 2007-05-21
11:20:20 UTC (rev 815)
@@ -1,418 +0,0 @@
-package org.richfaces.renderkit.html;
-
-import java.io.IOException;
-import java.util.Map;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
-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;
-import org.ajax4jsf.framework.renderer.RendererBase;
-import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
-import org.ajax4jsf.framework.util.javascript.JSFunction;
-import org.richfaces.component.UIScrollableGrid;
-import org.richfaces.component.UIScrollableGridColumn;
-import org.richfaces.renderkit.CompositeRenderer;
-import org.richfaces.utils.TemplateLoader;
-
-import com.sun.org.apache.bcel.internal.generic.NEW;
-
-
-
-/**
- * @author Anton Belevich
- *
- */
-
-public abstract class ScrollableGridBaseRenderer2 extends CompositeRenderer {
-
- private final String FOOTER_PART = "footer";
-
- private final String HEADER_PART = "header";
-
- private final String CELL_ID_PREFFIX ="bcc_";
-
- private final String COLUMN_FROZEN_TYPE = "frozen";
-
- private final String COLUMN_NORMAL_TYPE = "normal";
-
- private RendererBase cellTemplate = null;
-
- private RendererBase headerCellTemplate = null;
-
- private RendererBase footerCellTemplate = null;
-
- private final ColumnVisitor columnsWidthCounter = new ColumnVisitor(){
-
- public int visit(FacesContext context, UIScrollableGridColumn column, ResponseWriter
writer, GridRendererState state) throws IOException {
-
- int prevWidth = 0;
- int width = 0;
-
-
- String widthPx = (String)column.getAttributes().get("width");
- prevWidth = state.getSumWidth();
-
- if(widthPx.endsWith("px")){
- width = prevWidth + Integer.parseInt(widthPx.substring(0,
widthPx.indexOf("px")));
- }
-
- state.setSumWidth(width);
- return 1;
- }
- };
-
- private final ColumnVisitor headerCellRenderer = new ExtendedColumnVisitor(){
-
- public void renderContent(FacesContext context, UIScrollableGridColumn column,
ResponseWriter writer, GridRendererState state) throws IOException {
-
-
- int cell_index = state.getCellIndex();
- String client_id = state.getClientId();
- String cell_id = state.getColumnType()+ ":" + state.getRowIndex()+
":" + cell_index;
- headerCellTemplate = getHeaderCellTemplate();
- ComponentVariables variables =
ComponentsVariableResolver.getVariables(headerCellTemplate, column);
- variables.setVariable("cell_id",cell_id);
- variables.setVariable("client_id", client_id);
- variables.setVariable("cell_index", new Integer(cell_index));
-
- headerCellTemplate.encodeBegin(context, column);
- UIComponent component = column.getFacet(HEADER_PART);
- if(component != null){
- renderChild(context, component);
- }
- headerCellTemplate.encodeEnd(context, column);
-
- }
- };
-
- private final ColumnVisitor footerCellRenderer = new ExtendedColumnVisitor(){
-
- public void renderContent(FacesContext context, UIScrollableGridColumn column,
ResponseWriter writer, GridRendererState state) throws IOException {
-
- int cell_index = state.getCellIndex();
- String cell_id = state.getColumnType()+ ":" + state.getRowIndex()+
":" + cell_index;
- String client_id = state.getClientId();
- footerCellTemplate = getFooterCellTemplate();
- ComponentVariables variables =
ComponentsVariableResolver.getVariables(footerCellTemplate, column);
- variables.setVariable("cell_id",cell_id);
- variables.setVariable("client_id", client_id);
- variables.setVariable("cell_index", new Integer(cell_index));
- footerCellTemplate.encodeBegin(context, column);
- UIComponent component = column.getFacet(FOOTER_PART);
- if(component != null){
- renderChild(context, component);
- }
- footerCellTemplate.encodeEnd(context, column);
-
- }
- };
-
- private final ColumnVisitor cellRenderer = new ExtendedColumnVisitor(){
-
- public void renderContent(FacesContext context, UIScrollableGridColumn column,
ResponseWriter writer, GridRendererState state) throws IOException {
-
- int cell_index = state.getCellIndex();
- String cell_id = state.getRowIndex()+ "_" + state.getCellIndex();
- String column_type = state.getColumnType();
- int row_index = state.getRowIndex();
- String client_id = state.getClientId();
-
- cellTemplate = getCellTemplate();
- ComponentVariables variables = ComponentsVariableResolver.getVariables(cellTemplate,
column);
- variables.setVariable("cell_id",cell_id);
- variables.setVariable("row_index",new Integer(row_index));
- variables.setVariable("column_type", column_type);
- variables.setVariable("client_id", client_id);
- variables.setVariable("cell_index",new Integer(cell_index));
- cellTemplate.encodeBegin(context, column);
- renderChildren(context, column);
- cellTemplate.encodeEnd(context, column);
- }
-
- };
-
- 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();
-
- grid.setRowKey(rowIndex);
-
- if(grid.isRowAvailable()){
-
- int index = ((Integer)rowIndex).intValue();
- state.setRowIndex(index);
- String row_id = "row_" + index;
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement(HTML.TR_ELEMENT, grid);
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
- getUtils().writeAttribute(writer, "id",row_id);
- getUtils().writeAttribute(writer, "class","ClientUI_Grid_BR");
- ColumnWalker.iterateOverColumns(context, grid, cellRenderer, writer, state);
- writer.endElement(HTML.TR_ELEMENT);
-
- }
- }
- };
-
- private final ColumnVisitor ajaxCellRenderer = new ExtendedColumnVisitor(){
-
- public int visit(FacesContext context, UIScrollableGridColumn column, ResponseWriter
writer, GridRendererState state) throws IOException {
-
- if(state.isFrozenColumn()){
- int i = state.getFrozenColumnCount();
- state.setFrozenColumnCount(i-1);
- state.setCellIdPrefix(COLUMN_FROZEN_TYPE +":"+ CELL_ID_PREFFIX);
- renderContent(context, column, writer,state);
- }else{
- state.setCellIdPrefix(COLUMN_NORMAL_TYPE + ":" + CELL_ID_PREFFIX);
- renderContent(context, column, writer,state);
- }
- return 1;
- }
-
- public void renderContent(FacesContext context, UIScrollableGridColumn column,
ResponseWriter writer, GridRendererState state) throws IOException {
- writer.startElement(HTML.SPAN_ELEM, column);
- String columnWidth = (String)column.getAttributes().get("width");
-
- String cell_id = state.getClientId() + ":" + state.getCellIdPrefix() +
state.getRowIndex()+ "_" + state.getCellIndex();
- getUtils().writeAttribute(writer, "id",cell_id);
- getUtils().writeAttribute(writer, "class",
"ClientUI_Grid_BCBody");
- getUtils().writeAttribute(writer, "style", "width:" +
columnWidth);
- renderChildren(context, column);
- writer.endElement(HTML.SPAN_ELEM);
- AjaxContext ajaxContext = state.getAjaxContext();
- ajaxContext.addRenderedArea(cell_id);
- }
-
- };
-
- private final DataVisitor ajaxRowsRenderer = new DataVisitor(){
-
- public void process(FacesContext context, Object rowKey, Object argument) throws
IOException {
-
- GridRendererState state = (GridRendererState)argument;
- UIScrollableGrid grid = state.getGrid();
- grid.setRowKey(rowKey);
- ResponseWriter writer = context.getResponseWriter();
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
- ColumnWalker.iterateOverColumns(context, grid, ajaxCellRenderer, writer, state);
- state.nextRow();
- }
- };
-
- protected String getJavaScriptVarName(FacesContext context, UIScrollableGrid grid) {
- String id = grid.getBaseClientId(context);
- return "Richfaces_ScrollableGrid_" + id.replaceAll("[^A-Za-z0-9_]",
"_");
- }
-
- protected String getScriptContributions(FacesContext context, UIScrollableGrid grid) {
- return super.getScriptContributions(getJavaScriptVarName(context, grid), context,
grid);
- }
-
- public boolean getRendersChildren() {
- return true;
- }
-
- public void renderGridBody(FacesContext context, UIScrollableGrid grid, boolean
isFrozen) throws IOException{
-
- final GridRendererState state = GridRendererState.getRendererState(context);
-
- if(isFrozen){
- state.setColumType(COLUMN_FROZEN_TYPE);
- }else{
- state.setColumType(COLUMN_NORMAL_TYPE);
- }
-
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
- state.setFrozenPart(isFrozen);
- state.setClientId(grid.getClientId(context));
- grid.walk(context, rowsRenderer, state);
- grid.setRowKey(null);
- }
-
- public void renderHeaders(FacesContext context, UIScrollableGrid grid, boolean
isFrozen)throws IOException{
-
- ResponseWriter writer = context.getResponseWriter();
- final GridRendererState state = GridRendererState.getRendererState(context);
-
- if(isFrozen){
- state.setColumType(COLUMN_FROZEN_TYPE);
- }else{
- state.setColumType(COLUMN_NORMAL_TYPE);
- }
-
- state.setClientId(grid.getClientId(context));
- state.setPart(HEADER_PART);
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
- state.setFrozenPart(isFrozen);
- state.setClientId(grid.getClientId(context));
- ColumnWalker.iterateOverColumns(context, grid, headerCellRenderer, writer, state);
- }
-
- public void renderFooters(FacesContext context, UIScrollableGrid grid, boolean isFrozen)
throws IOException{
-
- ResponseWriter writer = context.getResponseWriter();
- final GridRendererState state = GridRendererState.getRendererState(context);
-
- if(isFrozen){
- state.setColumType(COLUMN_FROZEN_TYPE);
- }else{
- state.setColumType(COLUMN_NORMAL_TYPE);
- }
-
- state.setClientId(grid.getClientId(context));
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
- state.setFrozenPart(isFrozen);
- int colsCount = ColumnWalker.iterateOverColumns(context, grid, footerCellRenderer,
writer, state);
- int rowsCount = grid.getRowCount();
-
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this, grid);
- variables.setVariable("rows_count", new Integer(rowsCount));
- variables.setVariable("columns_count", new Integer(colsCount));
-
- }
-
- public void setUpState(FacesContext context, UIScrollableGrid grid) {
- GridRendererState.createState(context, grid);
- }
-
- public void tearDownState(FacesContext context){
- GridRendererState.restoreState(context);
- }
-
- public String getRowsAjaxUpdate(FacesContext context, UIScrollableGrid grid){
-
- JSFunction function = AjaxRendererUtils.buildAjaxFunction(grid, context);
- Map options = AjaxRendererUtils.buildEventOptions(context, grid);
-
- function.addParameter(options);
- String completeFunction = function.toScript()+"; return false;";
- return completeFunction;
-
- }
-
- protected void doDecode(FacesContext context, UIComponent component) {
-
- 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)){
-
- 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])));
- grid.queueEvent(new AjaxEvent(grid));
-
- }
-
- }
-
- }
-
- public void renderAjaxChildren(FacesContext context, UIComponent component)throws
IOException{
-
- UIScrollableGrid grid = (UIScrollableGrid)component;
-
- GridRendererState state = GridRendererState.createState(context, grid);
- grid.setFirst(grid.getDataIndex().intValue());
- grid.setRows(grid.getRow_count().intValue());
- int start_row = grid.getStartRow().intValue();
-
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
- String client_id = grid.getClientId(context);
- state.setClientId(client_id);
- state.setAjaxContext(ajaxContext);
- state.setRowIndex(start_row);
-
- grid.walk(context, ajaxRowsRenderer, state);
-
- }
-
- public void encodeChildren(FacesContext context, UIComponent component
- ) throws IOException {
-
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance();
- if(ajaxContext.isAjaxRequest()){
- renderAjaxChildren(context, component);
- }else{
- super.encodeChildren(context, component);
- }
-
- }
-
- public void encodeBegin(FacesContext context, UIComponent component) throws IOException
{
-
- if(component instanceof UIScrollableGrid){
- UIScrollableGrid grid = (UIScrollableGrid)component;
- setUpState(context, grid);
- }
-
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance();
- if(ajaxContext.isAjaxRequest()){
- }else{
- super.encodeBegin(context, component);
- }
-
- }
-
- public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
-
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance();
- if(ajaxContext.isAjaxRequest()){
- }else{
- super.encodeEnd(context, component);
- }
-
- }
-
- public void setUpColumnsWidth(FacesContext context, UIScrollableGrid grid) throws
IOException{
- GridRendererState state = GridRendererState.getRendererState(context);
- state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
- ColumnWalker.iterateOverColumns(context, grid, columnsWidthCounter, null, state);
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this, grid);
- int sumWidth = state.getSumWidth() + 20;
- variables.setVariable("sumWidth", new Integer(sumWidth));
- }
-
- private RendererBase getCellTemplate() {
- if (cellTemplate == null) {
- cellTemplate =
TemplateLoader.loadTemplate("org.richfaces.renderkit.html.ScrollableGridCellRenderer");
- }
- return cellTemplate;
- }
-
- private RendererBase getHeaderCellTemplate() {
-
- if (headerCellTemplate == null) {
- headerCellTemplate =
TemplateLoader.loadTemplate("org.richfaces.renderkit.html.ScrollableGridHeaderCellRenderer");
- }
- return headerCellTemplate;
- }
-
- private RendererBase getFooterCellTemplate() {
-
- if (footerCellTemplate == null) {
- footerCellTemplate =
TemplateLoader.loadTemplate("org.richfaces.renderkit.html.ScrollableGridFooterCellRenderer");
- }
- return footerCellTemplate;
- }
-}