[richfaces-svn-commits] JBoss Rich Faces SVN: r15879 - in root/ui-sandbox/trunk/components/tables/ui/src/main: resources/META-INF/resources and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Nov 13 12:56:29 EST 2009


Author: konstantin.mishin
Date: 2009-11-13 12:56:29 -0500 (Fri, 13 Nov 2009)
New Revision: 15879

Added:
   root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js
Modified:
   root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
   root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.css
Log:
RF-7865

Modified: root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
===================================================================
--- root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java	2009-11-13 17:55:27 UTC (rev 15878)
+++ root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java	2009-11-13 17:56:29 UTC (rev 15879)
@@ -22,19 +22,27 @@
 package org.richfaces.renderkit;
 
 import java.io.IOException;
+import java.util.Iterator;
 
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 
-import org.ajax4jsf.renderkit.RendererBase;
 import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.UIDataTableBase;
+import org.richfaces.component.util.HtmlUtil;
 
-public class ExtendedDataTableRenderer extends RendererBase {
+ at ResourceDependencies({
+    @ResourceDependency(name = "extendedDataTable.js"),
+    @ResourceDependency(name = "extendedDataTable.css")
+})
+public class ExtendedDataTableRenderer extends AbstractTableRenderer {
 	
 	@Override
 	protected Class<? extends UIComponent> getComponentClass() {
-		return UIComponent.class;
+		return UIDataTableBase.class;
 	}
 	
 	@Override
@@ -42,7 +50,7 @@
 			UIComponent component) throws IOException {
 		writer.startElement(HTML.DIV_ELEM, component);
 		writer.writeAttribute(HTML.ID_ATTRIBUTE, component.getClientId(context), null);
-		writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable " + component.getAttributes().get("styleClass"), null);
+		writer.writeAttribute(HTML.CLASS_ATTRIBUTE, HtmlUtil.concatClasses("rich-extable", (String)component.getAttributes().get("styleClass")), null);
 		getUtils().writeAttribute(writer, HTML.STYLE_ATTRIBUTE, component.getAttributes().get("style"));
 		
 	}
@@ -50,13 +58,170 @@
 	@Override
 	protected void doEncodeChildren(ResponseWriter writer,
 			FacesContext context, UIComponent component) throws IOException {
-		// TODO Auto-generated method stub
-		super.doEncodeChildren(writer, context, component);
+		UIDataTableBase table = (UIDataTableBase) component;
+		Object key = table.getRowKey();
+		table.captureOrigValue(context);
+		table.setRowKey(context, null);
+		encodeStyle(writer, context, table);
+		encodeHeaderOrFooter(writer, context, table, "header");
+		encodeBody(writer, context, table);
+		encodeHeaderOrFooter(writer, context, table, "footer");
+		table.setRowKey(context,key);
+		table.restoreOrigValue(context);
 	}	
 	
 	@Override
 	protected void doEncodeEnd(ResponseWriter writer, FacesContext context,
 			UIComponent component) throws IOException {
-		context.getResponseWriter().endElement(HTML.DIV_ELEM);
+		writer.startElement(HTML.SCRIPT_ELEM, component);
+		writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+		writer.write("new RichFaces.ExtendedDataTable('" + component.getClientId(context) + "');");
+		writer.endElement(HTML.SCRIPT_ELEM);
+		writer.endElement(HTML.DIV_ELEM);
 	}
+	
+	private void encodeStyle(ResponseWriter writer, FacesContext context,
+			UIDataTableBase table) throws IOException {
+		writer.startElement("style", table);			
+		writer.writeAttribute(HTML.TYPE_ATTR, "text/css", null);
+		writer.writeText(".rich-extable-part-width{", null); //TODO getNormalizedId(context, state.getGrid())
+		writer.writeText("width: 100%;", "width");
+		writer.writeText("}", null);			
+		int columnIndex = 0;
+		Iterator<UIComponent> columns = table.columns();
+		while (columns.hasNext()) {
+			UIComponent column = (UIComponent) columns.next();
+			String width = getColumnWidth(column);
+			writer.writeText(".rich-extable-cell-width-" + columnIndex++ + " {", "width"); //TODO getNormalizedId(context, state.getGrid())
+			writer.writeText("width: " + width + ";", "width");
+			writer.writeText("}", "width");	
+		}
+		writer.endElement("style");
+	}
+	
+	private void encodeHeaderOrFooter(ResponseWriter writer, FacesContext context,
+		UIDataTableBase table, String name) throws IOException {
+		if (isColumnFacetPresent(table, name)) {
+			writer.startElement(HTML.DIV_ELEM, table);			
+			writer.writeAttribute(HTML.CLASS_ATTRIBUTE, HtmlUtil.concatClasses("rich-extable-" + name, (String)table.getAttributes().get(name + "Class")), null);
+			writer.startElement(HTML.TABLE_ELEMENT, table);			
+			writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0", null);
+			writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0", null);
+			writer.startElement(HTML.TBOBY_ELEMENT, table);			
+			writer.startElement(HTML.TR_ELEMENT, table);			
+			int columnIndex = 0;
+			Iterator<UIComponent> columns = table.columns();
+			writer.startElement(HTML.TD_ELEM, table);			
+			writer.startElement(HTML.DIV_ELEM, table);
+			writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) + ":n" + name.charAt(0) + "pe", null);
+			writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable" + ("footer".equals(name) ? "-footer" : "") + "-part rich-extable-part-width", null);
+			writer.startElement(HTML.TABLE_ELEMENT, table);			
+			writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0", null);
+			writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0", null);
+			writer.startElement(HTML.TBOBY_ELEMENT, table);			
+			writer.startElement(HTML.TR_ELEMENT, table);			
+			while (columns.hasNext()) {
+				encodeHeaderOrFooterCell(context, writer, columns.next(), "rich-extable-" + name + "-cell", "rich-extable-cell-width-" + columnIndex++, name);
+			}
+			writer.endElement(HTML.TR_ELEMENT);
+			writer.endElement(HTML.TBOBY_ELEMENT);
+			writer.endElement(HTML.TABLE_ELEMENT);
+			writer.endElement(HTML.DIV_ELEM);
+			writer.endElement(HTML.TD_ELEM);
+			writer.endElement(HTML.TR_ELEMENT);
+			writer.endElement(HTML.TBOBY_ELEMENT);
+			writer.endElement(HTML.TABLE_ELEMENT);
+			writer.endElement(HTML.DIV_ELEM);
+		}
+	}
+
+	private void encodeBody(ResponseWriter writer, FacesContext context,
+			UIDataTableBase table) throws IOException {
+		writer.startElement(HTML.DIV_ELEM, table);	
+		writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) + ":b", null);
+		writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable-body", null);
+		writer.startElement(HTML.DIV_ELEM, table);	
+		writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) + ":c", null);
+		writer.startElement(HTML.DIV_ELEM, table);	
+		writer.endElement(HTML.DIV_ELEM);
+		writer.startElement(HTML.TABLE_ELEMENT, table);			
+		writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0", null);
+		writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0", null);
+		writer.startElement(HTML.TBOBY_ELEMENT, table);			
+		writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) + ":tb", null);
+		writer.startElement(HTML.TR_ELEMENT, table);			
+		writer.startElement(HTML.TD_ELEM, table);			
+		writer.startElement(HTML.DIV_ELEM, table);
+		writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) + ":nbpe", null);
+		writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-extable-part rich-extable-part-width", null);
+		writer.startElement(HTML.TABLE_ELEMENT, table);			
+		writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context) + ":nbte", null);
+		writer.writeAttribute(HTML.CELLPADDING_ATTRIBUTE, "0", null);
+		writer.writeAttribute(HTML.CELLSPACING_ATTRIBUTE, "0", null);
+		writer.startElement(HTML.TBOBY_ELEMENT, table);			
+		encodeRows(context, table);
+		writer.endElement(HTML.TBOBY_ELEMENT);
+		writer.endElement(HTML.TABLE_ELEMENT);
+		writer.endElement(HTML.DIV_ELEM);
+		writer.endElement(HTML.TD_ELEM);
+		writer.endElement(HTML.TR_ELEMENT);
+		writer.endElement(HTML.TBOBY_ELEMENT);
+		writer.endElement(HTML.TABLE_ELEMENT);
+		writer.endElement(HTML.DIV_ELEM);
+		writer.endElement(HTML.DIV_ELEM);
+	}
+
+	private void encodeHeaderOrFooterCell(FacesContext context, ResponseWriter writer,
+			UIComponent column, String skinCellClass, String widthCellClass, 
+			String facetName) throws IOException {
+		if (column.isRendered()) {
+
+			String classAttribute = facetName + "Class";
+			writer.startElement(HTML.TD_ELEM, column);			
+			writer.startElement(HTML.DIV_ELEM, column);
+			writer.writeAttribute(HTML.CLASS_ATTRIBUTE, HtmlUtil.concatClasses(skinCellClass, widthCellClass,
+					(String) column.getAttributes().get(classAttribute)), null);
+
+
+			UIComponent facet = column.getFacet(facetName);
+			if (facet != null && facet.isRendered()) {
+				renderChild(context, facet);
+			}
+
+			writer.endElement(HTML.DIV_ELEM);
+			writer.endElement(HTML.TD_ELEM);
+		}
+	}
+
+	@Override
+	public void encodeRow(FacesContext context, RowHolder rowHolder)
+			throws IOException {
+		ResponseWriter writer = context.getResponseWriter();
+		UIDataTableBase table = (UIDataTableBase) rowHolder.getRow(); //TODO Don't use cast this
+		writer.startElement(HTML.TR_ELEMENT, table);			
+		writer.writeAttribute(HTML.ID_ATTRIBUTE, table.getClientId(context), null);
+		Iterator<UIComponent> columns = table.columns();
+		int columnIndex = 0;
+		while (columns.hasNext()) {
+			UIComponent column = (UIComponent) columns.next();
+			if (column.isRendered()) {
+				writer.startElement(HTML.TD_ELEM, table);
+				writer.startElement(HTML.DIV_ELEM, table);
+				writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-std2-cell rich-std2-cell-width-" + columnIndex++, null);
+				renderChildren(context, column);
+				writer.endElement(HTML.DIV_ELEM);
+				writer.endElement(HTML.TD_ELEM);
+			}
+		}
+		writer.endElement(HTML.TR_ELEMENT);
+	}
+
+	private String getColumnWidth(UIComponent column) {
+		String width = (String) column.getAttributes().get("width");
+		if (width == null ||  width.indexOf("%") != -1) {
+			width = "100px";
+		}
+		return width;
+	}
+
 }

Modified: root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.css
===================================================================
--- root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.css	2009-11-13 17:55:27 UTC (rev 15878)
+++ root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.css	2009-11-13 17:56:29 UTC (rev 15879)
@@ -47,12 +47,12 @@
 	overflow: hidden;
 }
 
-.rich-extable-footer-part{
+/*.rich-extable-footer-part{
 	overflow-x: auto;
 	overflow-y: visible;
-}
+}*/
 
-.rich-extable-cell, .rich-extable-header-cell{
+.rich-extable-cell, .rich-extable-header-cell, .rich-extable-footer-cell{
 	height: 20px;
 	overflow: hidden;
 	border-bottom: 1px solid #C4C0C9;

Added: root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js
===================================================================
--- root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js	                        (rev 0)
+++ root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/extendedDataTable.js	2009-11-13 17:56:29 UTC (rev 15879)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */ 
+(function(richfaces, jQuery) {
+	richfaces.ExtendedDataTable = function(id) {
+		this.id = id;		
+		this.element = document.getElementById(id);
+		this.bodyElement = document.getElementById(id + ":b");
+		this.contentElement = document.getElementById(id + ":c");
+		this.marginElement = this.contentElement.firstChild;//TODO this.marginElement = Richfaces.firstDescendant(this.contentElement);
+		this.dataTableElement = this.contentElement.lastChild;//TODO this.dataTableElement = Richfaces.lastDescendant(this.contentElement);
+		this.frozenHeaderPartElement = document.getElementById(id + ":fhpe");
+		
+		this.normalPartStyle = Utils.getRule(".rich-std2-part-width").style;
+		this.resizerHolderStyle = Utils.getRule(".rich-std2-resizer-holder").style;
+		this.idSuffixs = [":nhpe", ":nbpe", ":nfpe"];
+		
+		this.scrollElement = document.getElementById(this.id + this.idSuffixs[2]);
+		
+		this.rows = document.getElementById(id + ":nbte").rows.length;
+
+		this.scrollListener = this.updateScrollPosition.bindAsEventListener(this);
+		Event.observe(this.scrollElement, 'scroll', this.scrollListener);
+		this.updateDataListener = this.updateData.bindAsEventListener(this);
+		Event.observe(this.bodyElement, 'scroll', this.updateDataListener);
+		this.resizeListener = this.updateLayout.bindAsEventListener(this);
+		Event.observe(window, 'resize', this.resizeListener);
+		
+		var table = this;
+		jQuery(document).ready(function(){
+				table.contentElement.style.height = (table.rowCount * table.dataTableElement.offsetHeight / table.rows) + "px";
+				table.updateLayout();
+			});
+	};
+}(window.RichFaces, jQuery));
+



More information about the richfaces-svn-commits mailing list