Author: abelevich
Date: 2010-04-05 11:07:35 -0400 (Mon, 05 Apr 2010)
New Revision: 16720
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRowsRenderer.java
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/table.css
Log:
add "no data" facet support
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2010-04-05
13:58:25 UTC (rev 16719)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTableBase.java 2010-04-05
15:07:35 UTC (rev 16720)
@@ -44,7 +44,7 @@
public class UIDataTableBase extends UISequence implements Row {
protected enum PropertyKeys {
- filterVar, sortPriority, sortMode, first, rows
+ filterVar, sortPriority, sortMode, first, rows, noDataLabel
}
public Iterator<UIComponent> columns() {
@@ -68,7 +68,19 @@
public UIComponent getFooter() {
return getFacet("footer");
}
-
+
+ public UIComponent getNoData() {
+ return getFacet("noData");
+ }
+
+ public String getNoDataLabel() {
+ return (String)getStateHelper().eval(PropertyKeys.noDataLabel);
+ }
+
+ public String setNoDataLabel(String noDataLabel) {
+ return (String)getStateHelper().put(PropertyKeys.noDataLabel, noDataLabel,
"");
+ }
+
public boolean isColumnFacetPresent(String facetName) {
Iterator<UIComponent> columns = columns();
boolean result = false;
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2010-04-05
13:58:25 UTC (rev 16719)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2010-04-05
15:07:35 UTC (rev 16720)
@@ -63,54 +63,8 @@
return count;
}
- protected int getColumnsCount(Iterator<UIComponent> col) {
- int count = 0;
- int currentLength = 0;
- while (col.hasNext()) {
- UIComponent component = (UIComponent) col.next();
- if (component.isRendered()) {
- if (component instanceof Row) {
- // Store max calculated value of previsous rows.
- if (currentLength > count) {
- count = currentLength;
- }
- // Calculate number of columns in row.
- currentLength = getColumnsCount(((Row) component).columns());
- // Store max calculated value
- if (currentLength > count) {
- count = currentLength;
- }
- currentLength = 0;
- } else if (component instanceof org.richfaces.component.UIColumn) {
- // For new row, save length of previsous.
- Map<String, Object> attributes = component.getAttributes();
- if (Boolean.TRUE.equals(attributes.get("breakBefore"))) {
- if (currentLength > count) {
- count = currentLength;
- }
- currentLength = 0;
- }
- Integer colspan = (Integer) attributes.get("colspan");
- // Append colspan of this column
- if (null != colspan && colspan.intValue() !=
Integer.MIN_VALUE) {
- currentLength += colspan.intValue();
- } else {
- currentLength++;
- }
- } else if (component instanceof UIColumn) {
- // UIColumn always have colspan == 1.
- currentLength++;
- }
- }
- }
-
- if (currentLength > count) {
- count = currentLength;
- }
- return count;
- }
+
-
public void encodeTableStructure(ResponseWriter writer, FacesContext context,
UIDataTableBase dataTable) throws IOException {
}
@@ -142,7 +96,7 @@
}
-
+
@Override
protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
UIDataTableBase dataTable = (UIDataTableBase) component;
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRowsRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRowsRenderer.java 2010-04-05
13:58:25 UTC (rev 16719)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/DataTableRowsRenderer.java 2010-04-05
15:07:35 UTC (rev 16720)
@@ -1,6 +1,7 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.util.Iterator;
import java.util.Map;
import javax.faces.component.UIColumn;
@@ -9,6 +10,8 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.Row;
+import org.richfaces.component.UIDataTableBase;
public abstract class DataTableRowsRenderer extends AbstractRowsRenderer {
@@ -80,6 +83,43 @@
}
}
}
+
+ @Override
+ protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
+
+ if(component instanceof UIDataTableBase) {
+ UIDataTableBase dataTable = (UIDataTableBase)component;
+ int rowCount = dataTable.getRowCount();
+ if(rowCount > 0) {
+ super.doEncodeChildren(writer, context, component);
+ } else {
+ int columns = getColumnsCount(dataTable.columns());
+
+ writer.startElement(HTML.TR_ELEMENT, dataTable);
+ writer.startElement(HTML.TD_ELEM, dataTable);
+ writer.writeAttribute("colspan", columns, null);
+
+ String styleClass =
(String)dataTable.getAttributes().get("noDataStyleClass");
+ styleClass = styleClass != null ? "rich-nodata-cell " +
styleClass : "rich-nodata-cell";
+
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, styleClass, null);
+
+ UIComponent noDataFacet = dataTable.getNoData();
+ if(noDataFacet != null && noDataFacet.isRendered() ) {
+ noDataFacet.encodeAll(context);
+ } else {
+ String noDataLabel = dataTable.getNoDataLabel();
+ if(noDataLabel != null) {
+ writer.writeText(noDataLabel, "noDataLabel");
+ }
+ }
+
+ writer.endElement(HTML.TD_ELEM);
+ writer.endElement(HTML.TR_ELEMENT);
+ }
+ }
+
+ }
public void encodeColumnEnd(ResponseWriter writer, FacesContext context, String
parentId, UIComponent component) throws IOException {
writer.endElement(getCellElement(context, parentId));
@@ -182,6 +222,54 @@
}
}
+ protected int getColumnsCount(Iterator<UIComponent> col) {
+ int count = 0;
+ int currentLength = 0;
+ while (col.hasNext()) {
+ UIComponent component = (UIComponent) col.next();
+ if (component.isRendered()) {
+ if (component instanceof Row) {
+ // Store max calculated value of previsous rows.
+ if (currentLength > count) {
+ count = currentLength;
+ }
+ // Calculate number of columns in row.
+ currentLength = getColumnsCount(((Row) component).columns());
+ // Store max calculated value
+ if (currentLength > count) {
+ count = currentLength;
+ }
+ currentLength = 0;
+ } else if (component instanceof org.richfaces.component.UIColumn) {
+ // For new row, save length of previsous.
+ Map<String, Object> attributes = component.getAttributes();
+ if (Boolean.TRUE.equals(attributes.get("breakBefore"))) {
+ if (currentLength > count) {
+ count = currentLength;
+ }
+ currentLength = 0;
+ }
+ Integer colspan = (Integer) attributes.get("colspan");
+ // Append colspan of this column
+ if (null != colspan && colspan.intValue() !=
Integer.MIN_VALUE) {
+ currentLength += colspan.intValue();
+ } else {
+ currentLength++;
+ }
+ } else if (component instanceof UIColumn) {
+ // UIColumn always have colspan == 1.
+ currentLength++;
+ }
+ }
+ }
+
+ if (currentLength > count) {
+ count = currentLength;
+ }
+ return count;
+ }
+
+
public abstract String getTableSkinClass();
public abstract String getFirstRowSkinClass();
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/table.css
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/table.css 2010-04-05
13:58:25 UTC (rev 16719)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/table.css 2010-04-05
15:07:35 UTC (rev 16720)
@@ -21,6 +21,14 @@
padding:4px;
}
+.rich-nodata-cell{
+ border-bottom:1px solid #C0C0C0;
+ border-right:1px solid #C0C0C0;
+ color:#000000;
+ font-family:Arial,Verdana,sans-serif;
+ font-size:11px;
+ padding:4px;
+}
.rich-subtable-row{
}