Author: abelevich
Date: 2007-05-16 05:27:40 -0400 (Wed, 16 May 2007)
New Revision: 774
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ExtendedColumnVisitor.java
Modified:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnVisitor.java
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/ColumnVisitor.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnVisitor.java 2007-05-16
09:27:28 UTC (rev 773)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnVisitor.java 2007-05-16
09:27:40 UTC (rev 774)
@@ -15,6 +15,6 @@
*
*/
public interface ColumnVisitor {
- public void visit(FacesContext context, UIScrollableGridColumn component,
- ResponseWriter writer, GridRendererState state) throws IOException;
+
+ public int visit(FacesContext context, UIScrollableGridColumn column, ResponseWriter
writer, GridRendererState state) throws IOException;
}
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-16
09:27:28 UTC (rev 773)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnWalker.java 2007-05-16
09:27:40 UTC (rev 774)
@@ -10,7 +10,6 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
import org.richfaces.component.UIScrollableGrid;
import org.richfaces.component.UIScrollableGridColumn;
@@ -20,85 +19,17 @@
*/
public class ColumnWalker {
- static void iterateOverHeadersFooters(FacesContext context, UIComponent component,
- ColumnVisitor visitor, ResponseWriter writer, GridRendererState state) throws
IOException{
-
- if(context == null || component == null){
- throw new NullPointerException();
- }
+ static int iterateOverColumns(FacesContext context, UIComponent component, ColumnVisitor
visitor,
+ ResponseWriter writer, GridRendererState state) throws IOException{
- if(!component.isRendered()){
- return ;
- }
+ int columnsCount = 0;
- if(component instanceof UIScrollableGrid){
-
- if(null != component.getChildren()){
- writer.startElement(HTML.TR_ELEMENT, component);
- writer.writeText("\n", null);
-
- for (Iterator iter = component.getChildren().iterator(); iter.hasNext(); ) {
- UIComponent kid = (UIComponent) iter.next();
- if (kid.isRendered()) {
- if (kid instanceof UIScrollableGridColumn){
- visitor.visit(context, (UIScrollableGridColumn)kid, writer, state);
- if(state.isFrozenColumn()){
- int i = state.getFrozenColumnCount();
- state.setFrozenColumnCount(i-1);
- }
- }
- }
- }
- writer.endElement(HTML.TR_ELEMENT);
- writer.writeText("\n", null);
- }
- }
- }
-
- static void iterateOverCells(FacesContext context, UIComponent component, ColumnVisitor
visitor,
- ResponseWriter writer, GridRendererState state) throws IOException{
-
-
- if(context == null || component == null){
- throw new NullPointerException();
- }
-
- if(!component.isRendered()){
- return ;
- }
-
- if(component instanceof UIScrollableGrid){
- for (Iterator iter = component.getChildren().iterator(); iter.hasNext(); ) {
- UIComponent kid = (UIComponent) iter.next();
- if (kid.isRendered()) {
- if (kid instanceof UIScrollableGridColumn){
- UIScrollableGridColumn column = (UIScrollableGridColumn)kid;
- if(state.isFrozenColumn()){
- int i = state.getFrozenColumnCount();
- state.setFrozenColumnCount(i-1);
- if(state.isFrozenPart()){
- visitor.visit(context, column, writer,state);
- }
- }else if(!state.isFrozenColumn()&& !state.isFrozenPart()){
- visitor.visit(context, column, writer,state);
- }
- state.nextCell();
- }
- }
- }
- state.setCellIndex(0);
- }
- }
-
- static void iterateOverAjaxCells(FacesContext context, UIComponent component,
ColumnVisitor visitor,
- ResponseWriter writer, GridRendererState state) throws IOException{
-
if(context == null || component == null){
throw new NullPointerException();
}
if(!component.isRendered()){
- return ;
+ return 0;
}
if(component instanceof UIScrollableGrid){
@@ -107,13 +38,14 @@
if (kid.isRendered()) {
if (kid instanceof UIScrollableGridColumn){
UIScrollableGridColumn column = (UIScrollableGridColumn)kid;
- visitor.visit(context, column, writer,state);
+ columnsCount += visitor.visit(context, column, writer, state);
state.nextCell();
- }
+ }
}
}
+ state.setCellIndex(0);
}
-
- state.setCellIndex(0);
+
+ return columnsCount;
}
}
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ExtendedColumnVisitor.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ExtendedColumnVisitor.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ExtendedColumnVisitor.java 2007-05-16
09:27:40 UTC (rev 774)
@@ -0,0 +1,27 @@
+/**
+ *
+ */
+package org.richfaces.renderkit.html;
+
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.richfaces.component.UIScrollableGridColumn;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public interface ExtendedColumnVisitor extends ColumnVisitor {
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.renderkit.html.ColumnVisitor#visit(javax.faces.context.FacesContext,
org.richfaces.component.UIScrollableGridColumn, javax.faces.context.ResponseWriter,
org.richfaces.renderkit.html.GridRendererState)
+ */
+ public int visit(FacesContext context, UIScrollableGridColumn column,
+ ResponseWriter writer, GridRendererState state) throws IOException;
+
+ public void renderContent(FacesContext context, UIScrollableGridColumn column,
+ ResponseWriter writer, GridRendererState state) throws IOException;
+}
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-16
09:27:28 UTC (rev 773)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java 2007-05-16
09:27:40 UTC (rev 774)
@@ -13,7 +13,6 @@
import org.ajax4jsf.framework.ajax.AjaxContext;
import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
-import org.apache.commons.digester.xmlrules.FromXmlRuleSet;
import org.richfaces.component.UIScrollableGrid;
/**
@@ -37,6 +36,8 @@
private String _cell_id_prefix;
+ private boolean header = false;
+
private String _column_type;
private int _frozenColumnCount = -1;
@@ -49,13 +50,15 @@
private UIScrollableGrid _grid;
+ private String clientId;
+
private String _cachedClientId;
private GridRendererState _previousState = null;
// private AjaxContainer _region = null;
- private boolean _rowSelected;
+// private boolean _rowSelected;
private Object rowKey;
@@ -118,7 +121,7 @@
}
}
/**
- * Create state for current grig ( and store previsios state in field ).
+ * Create state for current grid ( and store previsios state in field ).
* @param previsiosState
*/
public GridRendererState(FacesContext context, GridRendererState previsiosState,
UIScrollableGrid grid) {
@@ -247,22 +250,7 @@
return buffer;
}
-
/**
- * @return the _rowSelected
- */
- public boolean isRowSelected() {
- return _rowSelected;
- }
-
- /**
- * @param selected the _rowSelected to set
- */
- public void setRowSelected(boolean selected) {
- _rowSelected = selected;
- }
-
- /**
* @return the rowKey
*/
public Object getRowKey() {
@@ -327,4 +315,21 @@
public void setWriter(ResponseWriter writer) {
this.writer = writer;
}
+
+ public String getClientId(){
+ return clientId;
+ }
+
+ public void setClientId(String clientId){
+ this.clientId = clientId;
+ }
+
+ public boolean isHeader() {
+ return header;
+ }
+
+ public void setHeader(boolean header) {
+ this.header = header;
+ }
+
}
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-16
09:27:28 UTC (rev 773)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java 2007-05-16
09:27:40 UTC (rev 774)
@@ -7,6 +7,7 @@
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;
@@ -23,6 +24,7 @@
import org.richfaces.utils.TemplateLoader;
+
/**
* @author Anton Belevich
*
@@ -40,95 +42,130 @@
private final String COLUMN_NORMAL_TYPE = "normal";
- private final RendererBase cellTemplate =
TemplateLoader.loadTemplate("org.richfaces.renderkit.html.ScrollableGridCellRenderer");
+ private RendererBase cellTemplate = null;
+
+
+
+ private final ColumnVisitor headerFooterRenderer = new ExtendedColumnVisitor(){
+
- private final ColumnVisitor headerRenderer = new ColumnVisitor(){
+ 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 0;
+ }
- public void visit(FacesContext context, UIScrollableGridColumn column,
- ResponseWriter writer, GridRendererState state) throws IOException {
-
+ 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(column.getFacet(HEADER_PART) != 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 footerRenderer = new ColumnVisitor(){
+ private final ColumnVisitor cellRenderer = new ExtendedColumnVisitor(){
- public void visit(FacesContext context, UIScrollableGridColumn column,
+ public int visit(FacesContext context, UIScrollableGridColumn column,
ResponseWriter writer, GridRendererState state) throws IOException {
- writer.startElement(HTML.td_ELEM, column);
- getUtils().writeAttribute(writer,
"style",column.getAttributes().get("style"));
- writer.writeText("\n", null);
-
- if(column.getFacet(FOOTER_PART) != null){
- UIComponent component = column.getFacet(FOOTER_PART);
- renderChild(context, component);
+
+ 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);
}
-
- writer.endElement(HTML.td_ELEM);
- writer.writeText("\n", null);
- }
- };
-
- private final ColumnVisitor cellRenderer = new ColumnVisitor(){
+
+ return 0;
+ }
- public void visit(FacesContext context, UIScrollableGridColumn column,
- ResponseWriter writer, GridRendererState state) throws IOException {
-
+ 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_index",state.getColumnType()+ ":" +
state.getRowIndex()+ ":" + state.getCellIndex());
+ 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();
- ResponseWriter writer = context.getResponseWriter();
+
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_" +
state.getColumnType() + ":" + index);
+ getUtils().writeAttribute(writer, "id",row_id);
getUtils().writeAttribute(writer, "class","ClientUI_Grid_BR");
- ColumnWalker.iterateOverCells(context, grid, cellRenderer, writer, state);
+ ColumnWalker.iterateOverColumns(context, grid, cellRenderer, writer, state);
+ writer.endElement(HTML.TR_ELEMENT);
+
}
-
- writer.endElement(HTML.TR_ELEMENT);
}
};
private final ColumnVisitor ajaxCellRenderer = new ColumnVisitor(){
- public void visit(FacesContext context, UIScrollableGridColumn column, ResponseWriter
writer, GridRendererState state) throws IOException {
+ public int visit(FacesContext context, UIScrollableGridColumn column, ResponseWriter
writer, GridRendererState state) throws IOException {
writer.startElement(HTML.SPAN_ELEM, column);
- String cell_index = state.getCellIdPrefix() + ":" +
state.getRowIndex()+":" + state.getCellIndex();
- getUtils().writeAttribute(writer, "id",cell_index);
+ 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_index);
+ ajaxContext.addRenderedArea(cell_id);
+ return 0;
}
+
};
private final DataVisitor ajaxRowsRenderer = new DataVisitor(){
@@ -140,13 +177,14 @@
grid.setRowKey(rowKey);
ResponseWriter writer = context.getResponseWriter();
state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
- ColumnWalker.iterateOverAjaxCells(context, grid, ajaxCellRenderer, writer, state);
+ 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_]",
"_");
}
@@ -171,8 +209,7 @@
final GridRendererState state = GridRendererState.getRendererState(context);
- ComponentVariables variables = ComponentsVariableResolver.getVariables(this,
component);
-// variables.setVariable("rows_count", new Integer(component.getRows()));
+// setUpScriptModel(context, grid);
writer.startElement(HTML.DIV_ELEM, grid);
getUtils().writeAttribute(writer, "class","GridDataColumns");
@@ -187,8 +224,8 @@
writer.writeText("\n", null);
writer.startElement("tbody", grid);
state.setGrid(grid);
+ state.setClientId(grid.getClientId(context));
-
state.setFrozenPart(true);
state.setColumType(COLUMN_FROZEN_TYPE);
@@ -226,7 +263,15 @@
ResponseWriter writer = context.getResponseWriter();
final GridRendererState state = GridRendererState.getRendererState(context);
state.setFrozenColumnCount(((Integer)component.getAttributes().get("frozenColCount")).intValue());
- ColumnWalker.iterateOverHeadersFooters(context, component, headerRenderer, writer,
state);
+
+ 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
@@ -235,7 +280,16 @@
ResponseWriter writer = context.getResponseWriter();
final GridRendererState state = GridRendererState.getRendererState(context);
state.setFrozenColumnCount(((Integer)component.getAttributes().get("frozenColCount")).intValue());
- ColumnWalker.iterateOverHeadersFooters(context, component, footerRenderer, writer,
state);
+
+ writer.startElement(HTML.TR_ELEMENT, component);
+ writer.writeText("\n", null);
+
+ state.setHeader(false);
+ ColumnWalker.iterateOverColumns(context, component, headerFooterRenderer, writer,
state);
+
+ writer.endElement(HTML.TR_ELEMENT);
+ writer.writeText("\n", null);
+
}
public void setUpState(FacesContext context, UIScrollableGrid grid) {
@@ -285,8 +339,10 @@
grid.setFirst(grid.getDataIndex().intValue());
grid.setRows(grid.getRow_count().intValue());
int start_row = grid.getStartRow().intValue();
+ String client_id = grid.getClientId(context);
GridRendererState state = GridRendererState.getRendererState(context);
+ state.setClientId(client_id);
state.setAjaxContext(AjaxContext.getCurrentInstance(context));
state.setRowIndex(start_row);
state.setFrozenPart(true);
@@ -311,4 +367,28 @@
}
}
+// 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;
+ }
}