[richfaces-svn-commits] JBoss Rich Faces SVN: r752 - trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon May 14 14:06:16 EDT 2007


Author: abelevich
Date: 2007-05-14 14:06:16 -0400 (Mon, 14 May 2007)
New Revision: 752

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-14 18:05:06 UTC (rev 751)
+++ trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ColumnWalker.java	2007-05-14 18:06:16 UTC (rev 752)
@@ -41,11 +41,11 @@
 					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() - 1;
-								state.setFrozenColumnCount(i);
+								int i = state.getFrozenColumnCount();
+								state.setFrozenColumnCount(i-1);
 							}
-							visitor.visit(context, (UIScrollableGridColumn)kid, writer, state);
 						}
 					}
 				}	
@@ -56,38 +56,64 @@
 	}
 	
 	static void iterateOverCells(FacesContext context, UIComponent component, ColumnVisitor visitor, 
-								 ResponseWriter writer, GridRendererState state) throws IOException{
-		
-			
+			 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 ;
 		}
-		
+
 		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();
-							i--;
-							state.setFrozenColumnCount(i);
-							visitor.visit(context, column, writer,state);
-						
-						} else if(!state.isFrozenColumn()){
-							visitor.visit(context,column, writer, state);
-						}
+						visitor.visit(context, column, writer,state);
 						state.nextCell();
-					}
+					}	
 				}
 			}
-			state.setCellIndex(0);
 		}
+	
+		state.setCellIndex(0);
 	}
 }

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-14 18:05:06 UTC (rev 751)
+++ trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/GridRendererState.java	2007-05-14 18:06:16 UTC (rev 752)
@@ -9,7 +9,9 @@
 import javax.faces.FacesException;
 import javax.faces.component.NamingContainer;
 import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
 
+import org.ajax4jsf.framework.ajax.AjaxContext;
 import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
 import org.apache.commons.digester.xmlrules.FromXmlRuleSet;
 import org.richfaces.component.UIScrollableGrid;
@@ -33,8 +35,18 @@
 	
 	private int _columns = 0;
 	
+	private String _cell_id_prefix;
+	
+	private String _column_type;
+	
 	private int _frozenColumnCount = -1;
-		
+	
+	private AjaxContext ajaxContext;
+	
+	private boolean _frozenPart = false;
+	
+	private ResponseWriter writer;
+	
 	private UIScrollableGrid _grid;
 	
 	private String _cachedClientId;
@@ -203,6 +215,9 @@
 	 * @return new row number.
 	 */
 	public int nextRow(){
+		if(_rowIndex > _grid.getRows())
+			_rowIndex = 0;
+				
 		return ++_rowIndex;
 	}
 
@@ -262,7 +277,7 @@
 	}
 
 	public boolean isFrozenColumn() {
-		return _frozenColumnCount < 0 ? false:true;
+		return _frozenColumnCount <= 0 ? false:true;
 	}
 
 	public void setFrozenColumnCount(int columnCount) {
@@ -273,4 +288,43 @@
 		return _frozenColumnCount;
 	}
 
+	public boolean isFrozenPart() {
+		return _frozenPart;
+	}
+
+	public void setFrozenPart(boolean part) {
+		_frozenPart = part;
+	}
+
+	public String getCellIdPrefix() {
+		return _cell_id_prefix;
+	}
+
+	public void setCellIdPrefix(String _id_prefix) {
+		this._cell_id_prefix = _id_prefix;
+	}
+	
+	public String getColumnType() {
+		return _column_type;
+	}
+
+	public void setColumType(String _column_type) {
+		this._column_type = _column_type;
+	}
+
+	public AjaxContext getAjaxContext() {
+		return ajaxContext;
+	}
+
+	public void setAjaxContext(AjaxContext ajaxContext) {
+		this.ajaxContext = ajaxContext;
+	}
+
+	public ResponseWriter getWriter() {
+		return writer;
+	}
+
+	public void setWriter(ResponseWriter writer) {
+		this.writer = writer;
+	}
 }

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-14 18:05:06 UTC (rev 751)
+++ trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/renderkit/html/ScrollableGridBaseRenderer.java	2007-05-14 18:06:16 UTC (rev 752)
@@ -34,10 +34,14 @@
 	
 	private final String  HEADER_PART = "header";
 	
-	private final RendererBase cellTemplate = TemplateLoader.loadTemplate("org.richfaces.renderkit.html.ScrollableGridCellRenderer");
+	private final String CELL_ID_PREFFIX ="bc_";
 	
-
+	private final String COLUMN_FROZEN_TYPE = "frozen"; 
 	
+	private final String COLUMN_NORMAL_TYPE = "normal";
+	
+	private final RendererBase cellTemplate = TemplateLoader.loadTemplate("org.richfaces.renderkit.html.ScrollableGridCellRenderer");
+		
 	private final ColumnVisitor headerRenderer = new ColumnVisitor(){
 
 		public void visit(FacesContext context, UIScrollableGridColumn column, 
@@ -46,9 +50,8 @@
 			writer.startElement(HTML.td_ELEM, column);
 			String frozen = Boolean.toString(state.isFrozenColumn());
 			getUtils().writeAttribute(writer, "frozen",frozen );
-			getUtils().writeAttribute(writer, "style",column.getAttributes().get("style"));
+			getUtils().writeAttribute(writer, "width",column.getAttributes().get("width"));
 			writer.writeText("\n", null);
-			
 			if(column.getFacet(HEADER_PART) != null){
 				UIComponent component = column.getFacet(HEADER_PART);
 				renderChild(context, component);
@@ -83,30 +86,65 @@
 						  ResponseWriter writer, GridRendererState state) throws IOException {
 						
 			ComponentVariables variables = ComponentsVariableResolver.getVariables(cellTemplate, column);
-			variables.setVariable("row_index",Integer.valueOf(state.getRowIndex()));
-			variables.setVariable("cell_index",Integer.valueOf(state.getCellIndex()));
+			variables.setVariable("cell_index",state.getColumnType()+ ":" + state.getRowIndex()+ ":" + state.getCellIndex());
 			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();
-			int index = ((Integer)rowIndex).intValue();
+			GridRendererState state = (GridRendererState)argument;
+			UIScrollableGrid  grid = state.getGrid();
+			ResponseWriter writer = context.getResponseWriter();
 			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);
+			
+			if(grid.isRowAvailable()){
+				int index = ((Integer)rowIndex).intValue();
+				state.setRowIndex(index);
+				
+				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, "class","ClientUI_Grid_BR");
+				ColumnWalker.iterateOverCells(context, grid, cellRenderer, writer, state);
+			}	
+			
 			writer.endElement(HTML.TR_ELEMENT);	
 		}
 	};
+	
+	private final ColumnVisitor ajaxCellRenderer = new ColumnVisitor(){
 		
+		public void 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);
+			renderChildren(context, column);
+			writer.endElement(HTML.SPAN_ELEM);
+			AjaxContext ajaxContext = state.getAjaxContext();
+			ajaxContext.addRenderedArea(cell_index);
+			
+		}
+	};
+	
+	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.iterateOverAjaxCells(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_]", "_");
@@ -134,9 +172,8 @@
 		final GridRendererState state = GridRendererState.getRendererState(context);
 		
 		ComponentVariables variables = ComponentsVariableResolver.getVariables(this, component);
-//		variables.setVariable("column_count", variable);
-		variables.setVariable("rows_count", new Integer(component.getRows()));
-				
+//		variables.setVariable("rows_count", new Integer(component.getRows()));
+		
 		writer.startElement(HTML.DIV_ELEM, grid);
 		getUtils().writeAttribute(writer, "class","GridDataColumns");
 		getUtils().writeAttribute(writer, "id","FrozenBox");
@@ -149,24 +186,11 @@
 		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.setGrid(grid);
 		
-		DataVisitor rowsRenderer = new DataVisitor(){
-
-			public void process(FacesContext context, Object rowIndex, Object argument) throws IOException {
-			
-				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);	
-			}
-		};
 		
-		state.setFrozenColumnCount(((Integer)grid.getAttributes().get("frozenColCount")).intValue());
+		state.setFrozenPart(true);
+		state.setColumType(COLUMN_FROZEN_TYPE);
 		
 		grid.walk(context, rowsRenderer, state);
 		
@@ -186,8 +210,8 @@
 		getUtils().writeAttribute(writer, "style","position: absolute; left: 0px; top: 0px; display: block; width: 100%");
 		writer.writeText("\n", null);
 		
-		state.setFrozenColumnCount(-1);
-		
+		state.setColumType(COLUMN_NORMAL_TYPE);
+		state.setFrozenPart(false);
 		grid.walk(context, rowsRenderer, state);
 		writer.endElement("tbody");
 		writer.endElement("table");
@@ -245,9 +269,10 @@
 			if(parameters.containsKey(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.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));
 			}
 			
@@ -255,38 +280,32 @@
 	}
 	
 	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();
+		
 		GridRendererState state = GridRendererState.getRendererState(context);
-		grid.walk(context, rowsRenderer, state);
+		state.setAjaxContext(AjaxContext.getCurrentInstance(context));
+		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);
 	}
 	
-	
-//	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 {
 		AjaxContext ajaxContext = AjaxContext.getCurrentInstance();
 		if(ajaxContext.isAjaxRequest()){
-//			renderAjaxChildren(context, component);
+			renderAjaxChildren(context, component);
 		}else{
 			super.encodeChildren(context, component);
 		}




More information about the richfaces-svn-commits mailing list