Author: abelevich
Date: 2007-05-21 07:19:07 -0400 (Mon, 21 May 2007)
New Revision: 813
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
Removed:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java
Log:
Deleted:
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-21
11:18:50 UTC (rev 812)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-05-21
11:19:07 UTC (rev 813)
@@ -1,435 +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 javax.faces.model.DataModel;
-
-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;
-
-
-
-/**
- * @author Anton Belevich
- *
- */
-
-public abstract class ScrollableGridBaseRenderer extends CompositeRenderer {
-
- private final String FOOTER_PART = "footer";
-
- private final String HEADER_PART = "header";
-
- private final String CELL_ID_PREFFIX ="bc_";
-
- private final String COLUMN_FROZEN_TYPE = "frozen";
-
- private final String COLUMN_NORMAL_TYPE = "normal";
-
- private RendererBase cellTemplate = null;
-
-
-
- private final ColumnVisitor headerFooterRenderer = new ExtendedColumnVisitor(){
-
-
- public int visit(FacesContext context, UIScrollableGridColumn column,
- ResponseWriter writer, GridRendererState state) throws IOException {
-
- renderContent(context, column, writer, state);
-
- if(state.isFrozenColumn()){
- int i = state.getFrozenColumnCount();
- state.setFrozenColumnCount(i-1);
- }
-
- return 1;
- }
-
- public void renderContent(FacesContext context, UIScrollableGridColumn column,
ResponseWriter writer, GridRendererState state) throws IOException {
-
- writer.startElement(HTML.td_ELEM, column);
- String frozen = Boolean.toString(state.isFrozenColumn());
- getUtils().writeAttribute(writer, "frozen",frozen );
- getUtils().writeAttribute(writer,
"width",column.getAttributes().get("width"));
- writer.writeText("\n", null);
-
- if(state.isHeader() && (column.getFacet(HEADER_PART) != null)){
-
- UIComponent component = column.getFacet(HEADER_PART);
- renderChild(context, component);
-
- }else if(!state.isHeader()&& (column.getFacet(FOOTER_PART) != null)){
-
- UIComponent component = column.getFacet(FOOTER_PART);
- renderChild(context, component);
-
- }
-
- writer.endElement(HTML.td_ELEM);
- writer.writeText("\n", null);
- }
- };
-
- private final ColumnVisitor cellRenderer = 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);
- if(state.isFrozenPart()){
- renderContent(context, column, writer,state);
- }
- }else if(!state.isFrozenColumn()&& !state.isFrozenPart()){
- renderContent(context, column, writer,state);
- }
-
- return 0;
- }
-
- public void renderContent(FacesContext context, UIScrollableGridColumn column,
ResponseWriter writer, GridRendererState state) throws IOException {
-
- String cell_id = state.getColumnType()+ ":" + state.getRowIndex()+
":" + state.getCellIndex();
- String client_id = state.getClientId();
-
- cellTemplate = getCellTemplate();
- ComponentVariables variables = ComponentsVariableResolver.getVariables(cellTemplate,
column);
- variables.setVariable("cell_id",cell_id);
- variables.setVariable("client_id", client_id);
- 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 = state.getClientId() + ":" + "row_" +
state.getColumnType() + ":" + 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 ColumnVisitor(){
-
- public int visit(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);
-
- return 0;
- }
-
- };
-
- 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);
-// setUpScriptModel(context, grid);
- 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;
- }
-
- protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
- UIComponent component) throws IOException {
- if(component instanceof UIScrollableGrid){
- renderGridBody(context, (UIScrollableGrid)component, writer);
- }
- }
-
- public void renderGridBody(FacesContext context, UIScrollableGrid
component,ResponseWriter writer) throws IOException{
-
- final UIScrollableGrid grid = component;
-
- final GridRendererState state = GridRendererState.getRendererState(context);
-
-
- writer.startElement(HTML.DIV_ELEM, grid);
- getUtils().writeAttribute(writer, "class","GridDataColumns");
- getUtils().writeAttribute(writer, "id","FrozenBox");
- getUtils().writeAttribute(writer, "style","position: absolute; left:
0px; top: 0px; display: block; width: 100px");
- writer.writeText("\n", null);
- writer.startElement("table", grid);
- getUtils().writeAttribute(writer, "id","GridDataFrozen");
- getUtils().writeAttribute(writer, "cellpadding","0");
- getUtils().writeAttribute(writer, "cellspacing","0");
- 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);
- state.setClientId(grid.getClientId(context));
-
- state.setFrozenPart(true);
- state.setColumType(COLUMN_FROZEN_TYPE);
-
- grid.walk(context, rowsRenderer, state);
-
- writer.endElement("tbody");
- writer.endElement("table");
- writer.endElement(HTML.DIV_ELEM);
-
- writer.startElement(HTML.DIV_ELEM, grid);
- getUtils().writeAttribute(writer, "class","GridDataColumns");
- getUtils().writeAttribute(writer, "id","NormalBox");
- getUtils().writeAttribute(writer, "style","position: absolute; left:
300px; top: 0px; display: block; width: 700px");
- writer.writeText("\n", null);
- writer.startElement("table", grid);
- getUtils().writeAttribute(writer, "id","GridDataNormal");
- getUtils().writeAttribute(writer, "cellpadding","0");
- getUtils().writeAttribute(writer, "cellspacing","0");
- getUtils().writeAttribute(writer, "style","position: absolute; left:
0px; top: 0px; display: block; width: 100%");
- writer.writeText("\n", null);
-
- state.setColumType(COLUMN_NORMAL_TYPE);
- state.setFrozenPart(false);
-
- grid.walk(context, rowsRenderer, state);
-
- writer.endElement("tbody");
- writer.endElement("table");
- writer.endElement(HTML.DIV_ELEM);
- grid.setRowKey(null);
-
- }
-
- public void renderHeaders(FacesContext context, UIScrollableGrid component
- )throws IOException{
-
- ResponseWriter writer = context.getResponseWriter();
- final GridRendererState state = GridRendererState.getRendererState(context);
- state.setFrozenColumnCount(((Integer)component.getAttributes().get("frozenColCount")).intValue());
-
- writer.startElement(HTML.TR_ELEMENT, component);
- writer.writeText("\n", null);
- state.setHeader(true);
- ColumnWalker.iterateOverColumns(context, component, headerFooterRenderer, writer,
state);
-
- writer.endElement(HTML.TR_ELEMENT);
- writer.writeText("\n", null);
-
- }
-
- public void renderFooters(FacesContext context, UIScrollableGrid component
- ) throws IOException{
-
- ResponseWriter writer = context.getResponseWriter();
- final GridRendererState state = GridRendererState.getRendererState(context);
- state.setFrozenColumnCount(((Integer)component.getAttributes().get("frozenColCount")).intValue());
-
- writer.startElement(HTML.TR_ELEMENT, component);
- writer.writeText("\n", null);
-
- state.setHeader(false);
-
- int colsCount = ColumnWalker.iterateOverColumns(context, component,
headerFooterRenderer, writer, state);
- int rowsCount = component.getRowCount();
-
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this,
component);
- variables.setVariable("rows_count", new Integer(rowsCount));
- variables.setVariable("columns_count", new Integer(colsCount));
-
- writer.endElement(HTML.TR_ELEMENT);
- writer.writeText("\n", null);
-
- }
-
- 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;
- grid.setFirst(grid.getDataIndex().intValue());
- grid.setRows(grid.getRow_count().intValue());
- int start_row = grid.getStartRow().intValue();
-
- //remode scripts
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
- String client_id = grid.getClientId(context);
- String script_id = client_id + "_model_create_scripts";
- ajaxContext.removeRenderedArea(client_id);
- ajaxContext.removeRenderedArea(script_id);
- script_id = client_id + "_model_create_scripts";
- ajaxContext.removeRenderedArea(script_id);
-
- GridRendererState state = GridRendererState.createState(context, grid);
- state.setClientId(client_id);
- state.setAjaxContext(ajaxContext);
- state.setRowIndex(start_row);
- state.setFrozenPart(true);
- state.setCellIdPrefix(CELL_ID_PREFFIX + COLUMN_FROZEN_TYPE);
-
- grid.walk(context, ajaxRowsRenderer, state);
-
- state.setRowIndex(start_row);
- grid.setFirst(grid.getDataIndex().intValue());
- grid.setRows(grid.getRow_count().intValue());
- state.setFrozenPart(false);
- state.setCellIdPrefix(CELL_ID_PREFFIX + COLUMN_NORMAL_TYPE);
- 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 setUpScriptModel(FacesContext context, UIScrollableGrid grid) throws
IOException{
-
- DataModel dataModel = grid.getStoredDataModel();
- Integer rows_count = new Integer(dataModel.getRowCount());
-
- ColumnVisitor visitor = new ColumnVisitor(){
- public int visit(FacesContext context, UIScrollableGridColumn column, ResponseWriter
writer, GridRendererState state) throws IOException {
- return 1;
- }
- };
-
- Integer columns_count = new Integer(ColumnWalker.iterateOverColumns(context, grid,
visitor, null, null));
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this, grid);
- variables.setVariable("rows_count", rows_count);
- variables.setVariable("column_count", columns_count);
- }
-
- private RendererBase getCellTemplate() {
- if (cellTemplate == null) {
- cellTemplate =
TemplateLoader.loadTemplate("org.richfaces.renderkit.html.ScrollableGridCellRenderer");
- }
-
- return cellTemplate;
- }
-}
Added:
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
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-05-21
11:19:07 UTC (rev 813)
@@ -0,0 +1,426 @@
+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;
+
+
+
+/**
+ * @author Anton Belevich
+ *
+ */
+
+public abstract class ScrollableGridBaseRenderer extends CompositeRenderer {
+
+ private final String FOOTER_PART = "footer";
+
+ private final String HEADER_PART = "header";
+
+ private final String CELL_ID_PREFFIX ="bc_";
+
+ 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();
+
+ headerCellTemplate = getHeaderCellTemplate();
+
+ ComponentVariables variables =
ComponentsVariableResolver.getVariables(headerCellTemplate, column);
+ String widthPx = (String)column.getAttributes().get("width");
+ int width = Integer.parseInt(widthPx.substring(0, widthPx.indexOf("px")));
+
+
+ int sepOffset = 0;
+
+ if(state.isFrozenColumn()){
+ sepOffset = state.getSepOffset().intValue() + width;
+ }else{
+ sepOffset = state.getSepOffset().intValue() + width + 1;
+ state.setSepOffset(new Integer(sepOffset));
+ }
+
+ variables.setVariable("client_id", client_id);
+ variables.setVariable("cell_index", new Integer(cell_index));
+ variables.setVariable("sepOffset", new Integer(sepOffset));
+
+ 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 client_id = state.getClientId();
+
+ footerCellTemplate = getFooterCellTemplate();
+
+ ComponentVariables variables =
ComponentsVariableResolver.getVariables(footerCellTemplate, column);
+ 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 {
+
+ String cell_id = state.getRowIndex()+ "_" + state.getCellIndex();
+ String client_id = state.getClientId();
+ int cell_index = state.getCellIndex();
+ cellTemplate = getCellTemplate();
+
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(cellTemplate,
column);
+ variables.setVariable("cell_id",cell_id);
+ 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 {
+ int i = state.getFrozenColumnCount();
+ state.setFrozenColumnCount(i-1);
+ 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() + ":" + 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);
+ 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));
+ state.setSepOffset(new Integer(0));
+ 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());
+ int old = grid.getRows();
+ state.set_loadedRowsCount(old);
+
+ 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);
+ grid.setRows(old);
+ }
+
+ 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;
+ }
+}