Author: abelevich
Date: 2009-11-05 05:42:57 -0500 (Thu, 05 Nov 2009)
New Revision: 15831
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ProcessRowHolder.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowHolder.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/SimpleDataTableRenderer.java
Removed:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/CellEncodeEvent.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ElementEncodeEvent.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowEncodeEvent.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowEncoder.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/SimpleDataTableRendererBase.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/TableHolder.java
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/config/component/tables.xml
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumnGroup.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTable.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISimpleDataTable.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlColumnGroup.java
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.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/ElementEncodeListener.java
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/faces-config.xml
Log:
new renderer vision
Modified: root/ui-sandbox/trunk/components/tables/ui/src/main/config/component/tables.xml
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/config/component/tables.xml 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/config/component/tables.xml 2009-11-05
10:42:57 UTC (rev 15831)
@@ -55,9 +55,8 @@
<![CDATA[TODO: add description here]]>
</description>
- <renderer generate="true">
- <name>org.richfaces.renderkit.html.SimpleDataTableRenderer</name>
- <template>org/richfaces/renderkit/html/simpletable.template.xml</template>
+ <renderer generate="false" override="false">
+ <name>org.richfaces.renderkit.SimpleDataTableRenderer</name>
</renderer>
<tag>
<name>simpleDataTable</name>
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumnGroup.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumnGroup.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumnGroup.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -25,12 +25,16 @@
import javax.faces.component.UIComponent;
import javax.faces.component.UIPanel;
+import javax.faces.context.FacesContext;
+import org.ajax4jsf.model.DataVisitor;
+import org.richfaces.renderkit.RowHolder;
+
/**
* JSF component class
*
*/
-public abstract class UIColumnGroup extends UIPanel implements Row {
+public abstract class UIColumnGroup extends UIPanel implements Row, Column {
public static final String COMPONENT_TYPE = "org.richfaces.Colgroup";
@@ -48,4 +52,27 @@
throw new IllegalStateException("Property 'breakBefore' for subtable is
read-only");
}
+ public void setRowKey(FacesContext context, Object rowKey) {
+ // columnGroup doesn't have data model
+ }
+
+ public void walk(FacesContext context, DataVisitor visitor, Object argument) {
+ if(!(argument instanceof RowHolder)) {
+ return;
+ }
+
+ visitor.process(context, null, argument);
+ }
+
+ public String getCellSkinClass() {
+ return null;
+ }
+
+ public String getRowSkinClass() {
+ return null;
+ }
+
+ public String getFirstRowSkinClass() {
+ return null;
+ }
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTable.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTable.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIDataTable.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -4,7 +4,7 @@
import javax.faces.component.UIComponent;
-public class UIDataTable extends UISequence {
+public abstract class UIDataTable extends UISequence implements Row {
public Iterator<UIComponent> columns() {
return new ColumnsIterator(this);
@@ -37,4 +37,5 @@
public boolean getRendersChildren() {
return true;
}
+
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISimpleDataTable.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISimpleDataTable.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISimpleDataTable.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -11,4 +11,15 @@
public abstract class UISimpleDataTable extends UIDataTable {
+ public String getCellSkinClass() {
+ return "rich-table-cell";
+ }
+
+ public String getRowSkinClass() {
+ return "rich-table-row";
+ }
+
+ public String getFirstRowSkinClass() {
+ return "rich-table-firstrow";
+ }
}
\ No newline at end of file
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UISubTable.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -26,12 +26,14 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import org.ajax4jsf.model.DataVisitor;
+
/**
* JSF component class
*
*/
-public abstract class UISubTable extends UIDataTable implements Row {
+public abstract class UISubTable extends UIDataTable implements Row, Column {
public static final String COMPONENT_TYPE = "org.richfaces.SubTable";
@@ -56,20 +58,33 @@
return null;
}
- @Override
- public void resetDataModel(FacesContext context) {
- super.resetDataModel(context);
- }
-
public void setSortExpression(String sortExpression) {
// Do nothing - subtable is not sortable element;
//TODO nick - throw exception
}
+ @Override
+ public void walk(FacesContext context, DataVisitor visitor, Object argument) {
+ resetDataModel(context);
+ super.walk(context, visitor, argument);
+ }
@Override
public boolean getRendersChildren() {
//TODO nick - why "false"?
return false;
}
+
+ public String getCellSkinClass() {
+ return "rich-subtable-cell";
+ }
+
+ public String getRowSkinClass() {
+ return "rich-subtable-row";
+ }
+
+ public String getFirstRowSkinClass() {
+ return "rich-subtable-firstrow";
+ }
+
}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlColumnGroup.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlColumnGroup.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/html/HtmlColumnGroup.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -1,6 +1,7 @@
package org.richfaces.component.html;
import javax.el.MethodExpression;
+import javax.faces.context.FacesContext;
import org.richfaces.component.UIColumnGroup;
import org.richfaces.model.Ordering;
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractRowsRenderer.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -22,27 +22,21 @@
package org.richfaces.renderkit;
import java.io.IOException;
-import java.util.Map;
-import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
import org.ajax4jsf.model.DataVisitResult;
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.renderkit.RendererBase;
-import org.ajax4jsf.renderkit.RendererUtils;
-import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.UIDataAdaptor;
+import org.richfaces.component.Row;
import org.richfaces.component.UIDataTable;
-import org.richfaces.component.util.HtmlUtil;
/**
* @author shura
*
*/
-public abstract class AbstractRowsRenderer extends RendererBase implements DataVisitor,
ElementEncodeListener {
-
+public abstract class AbstractRowsRenderer extends RendererBase implements DataVisitor {
+ /*
public static final String[][] TABLE_EVENT_ATTRS = {
//TODO nick - clarify new names for attributes
{"onclick","onRowClick"},
@@ -54,94 +48,39 @@
{"onmouseout","onRowMouseOut"}
};
- public static final String ROW_CLASS_KEY = AbstractRowsRenderer.class.getName() +
".rowClass";
-
- public static final String SKIN_ROW_CLASS_KEY = AbstractRowsRenderer.class.getName() +
".skinRowClass";
-
- public static final String CELL_CLASS_KEY = AbstractRowsRenderer.class.getName() +
".cellClass";
-
- public static final String SKIN_CELL_CLASS_KEY = AbstractRowsRenderer.class.getName() +
".skinCellClass";
-
- public static final String SKIN_FIRST_ROW_CLASS_KEY =
AbstractRowsRenderer.class.getName() + ".firstRowSkinClass";
-
-
- protected abstract String getCellSkinClass();
+ */
- public abstract RowEncoder getRowEncoder(TableHolder holder);
+ public abstract void encodeRow(FacesContext context, RowHolder rowHolder) throws
IOException;
- protected String getCellStyleClasses(FacesContext context, UIComponent component) {
- StringBuffer styleClass = new StringBuffer();
-
- // Construct predefined classes
- //TODO nick - use FacesContext#attributes
- Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
- Object parentPredefined = requestMap.get(AbstractRowsRenderer.SKIN_CELL_CLASS_KEY);
- if (null != parentPredefined) {
- //TODO nick - use HtmlUtil.concatClasses(String ...);
- styleClass.append(parentPredefined).append(" ");
- } else {
- styleClass.append(getCellSkinClass());
- }
- // Append class from parent component.
- Object parent = requestMap.get(AbstractRowsRenderer.CELL_CLASS_KEY);
- if (null != parent) {
- styleClass.append(parent).append(" ");
- }
-
- Object custom = component.getAttributes().get("styleClass");
- if (null != custom) {
- styleClass.append(custom);
- }
- return styleClass.toString();
-
- }
-
public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
- TableHolder holder = (TableHolder) argument;
- UIDataAdaptor table = holder.getTable();
- table.setRowKey(context, rowKey);
+ RowHolder holder = (RowHolder) argument;
+ Row row = holder.getRow();
+ row.setRowKey(context, rowKey);
try {
- RowEncoder encoder = getRowEncoder(holder);
- encoder.setHeader(false);
- encoder.encodeRows(context, table);
+ encodeRow(context, holder);
} catch (IOException e) {
//TODO: seems we need add throws IOException ???
- }
+ }
+
holder.nextRow();
return DataVisitResult.CONTINUE;
}
+ //TODO remove
public void encodeRows(FacesContext facesContext, UIDataTable table) throws IOException
{
- TableHolder tableHolder = new TableHolder(table);
- encodeRows(facesContext, table, tableHolder);
+ RowHolder rowHolder = new RowHolder(table);
+ encodeRows(facesContext, table, rowHolder);
}
- protected void encodeRows(FacesContext context, UIDataTable table, TableHolder
tableHolder) throws IOException {
- Object key = table.getRowKey();
- table.captureOrigValue(context);
-
- table.walk(context, this, tableHolder);
-
- doCleanup(context, tableHolder);
- table.setRowKey(key);
- table.restoreOrigValue(context);
+ protected void encodeRows(FacesContext context, Row table, RowHolder rowHolder) throws
IOException {
+ table.walk(context, this, rowHolder);
}
- protected void doCleanup(FacesContext context, TableHolder tableHolder) throws
IOException {
- // Hoock method for perform encoding after all rows is rendered
- }
-
public boolean getRendersChildren() {
return true;
}
- public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
- //TODO nick - move this down by classes hierarchy
- if(component instanceof UIDataTable) {
- encodeRows(context, (UIDataTable)component);
- }
- }
-
+ /*
protected void encodeRowEvents(FacesContext context, UIDataAdaptor table) throws
IOException {
RendererUtils utils2 = getUtils();
@@ -150,133 +89,5 @@
utils2.encodeAttribute(context, table, attrs[1], attrs[0]);
}
- }
-
- /**
- * Encode HTML "class" attribute, if is not empty. Classes combined from
- * pre-defined skin classes, class from parent component, and custom
- * attribute.
- *
- * @param writer
- * @param parentPredefined TODO
- * @param predefined
- * predefined skin classes
- * @param parent
- * class from parent component
- * @param custom
- * custom classes.
- * @throws IOException
- */
-
- protected void encodeStyleClass(ResponseWriter writer, Object parentPredefined, Object
predefined,
- Object parent, Object custom) throws IOException {
-
- StringBuffer styleClass = new StringBuffer();
-
- // Construct predefined classes
- //TODO nick - use HtmlUtil.concatClasses(String ...);
- if (null != parentPredefined) {
- styleClass.append(parentPredefined).append(" ");
- } else if (null != predefined) {
- styleClass.append(predefined).append(" ");
- }
-
- // Append class from parent component.
- if (null != parent) {
- styleClass.append(parent).append(" ");
- }
- if (null != custom) {
- styleClass.append(custom);
- }
- if (styleClass.length() > 0) {
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, styleClass, "styleClass");
- }
- }
-
- protected void encodeStyle(ResponseWriter writer, Object parentPredefined,
- Object predefined, Object parent, Object custom) throws IOException {
-
- StringBuffer style = new StringBuffer();
- // Construct predefined styles
- //TODO nick - use HtmlUtil.concatStyles(String ...);
- if (null != parentPredefined) {
- style.append(parentPredefined).append(" ");
- } else if (null != predefined) {
- style.append(predefined).append(" ");
- }
- // Append style from parent component.
- if (null != parent) {
- style.append(parent).append(" ");
- }
- if (null != custom) {
- style.append(custom);
- }
- if (style.length() > 0) {
- writer.writeAttribute("style", style, "style");
- }
-
- }
-
-
- /**
- * Render component and all its children with current row/cell style
- * classes.
- *
- * @param context
- * @param cell
- * @param skinFirstRowClass TODO
- * @param skinRowClass
- * TODO
- * @param rowClass
- * @param skinCellClass
- * TODO
- * @param cellClass
- * @throws IOException
- */
-
-/*
- protected void encodeCellChildren(FacesContext context, UIComponent cell,
- String skinFirstRowClass, String skinRowClass, String rowClass,
- String skinCellClass, String cellClass) throws IOException {
-
- Map<String, Object> requestMap =
context.getExternalContext().getRequestMap();
- // Save top level class parameters ( if any ), and put new for this
- // component
- Object savedRowClass = requestMap.get(ROW_CLASS_KEY);
- if (null != rowClass) {
- requestMap.put(ROW_CLASS_KEY, rowClass);
-
- }
- Object savedSkinFirstRowClass = requestMap.get(SKIN_FIRST_ROW_CLASS_KEY);
- if (null != skinRowClass) {
- requestMap.put(SKIN_FIRST_ROW_CLASS_KEY, skinFirstRowClass);
-
- }
- Object savedSkinRowClass = requestMap.get(SKIN_ROW_CLASS_KEY);
- if (null != skinRowClass) {
- requestMap.put(SKIN_ROW_CLASS_KEY, skinRowClass);
-
- }
- Object savedCellClass = requestMap.get(CELL_CLASS_KEY);
- if (null != cellClass) {
- requestMap.put(CELL_CLASS_KEY, cellClass);
- }
- Object savedSkinCellClass = requestMap.get(SKIN_CELL_CLASS_KEY);
- if (null != skinCellClass) {
- requestMap.put(SKIN_CELL_CLASS_KEY, skinCellClass);
-
- }
-
- encodeCell(context, cell);
-
- // Restore original values.
- requestMap.put(ROW_CLASS_KEY, savedRowClass);
- requestMap.put(CELL_CLASS_KEY, savedCellClass);
- requestMap.put(SKIN_FIRST_ROW_CLASS_KEY, savedSkinFirstRowClass);
- requestMap.put(SKIN_ROW_CLASS_KEY, savedSkinRowClass);
- requestMap.put(SKIN_CELL_CLASS_KEY, savedSkinCellClass);
-
- }
-*/
-
+ } */
}
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 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/AbstractTableRenderer.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -1,13 +1,11 @@
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.UIColumn;
import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
import org.richfaces.component.Column;
import org.richfaces.component.Row;
@@ -21,17 +19,6 @@
})
public abstract class AbstractTableRenderer extends AbstractRowsRenderer {
- public void encodeTableBody (FacesContext context, UIDataTable table) throws IOException
{
- encodeBodyBegin(context, table);
- encodeRows(context, table);
- encodeBodyEnd(context, table);
- }
-
- public abstract void encodeBodyBegin(FacesContext context, UIDataTable table) throws
IOException;
-
- public abstract void encodeBodyEnd(FacesContext context, UIDataTable table) throws
IOException;
-
-
public boolean isColumnFacetPresent(UIDataTable table, String facetName) {
Iterator<UIComponent> columns = table.columns();
boolean result = false;
@@ -70,8 +57,7 @@
protected int getColumnsCount(UIDataTable table) {
// check for exact value in component
Integer span = (Integer) table.getAttributes().get("columns");
- int count = (null != span && span.intValue() != Integer.MIN_VALUE) ?
- span.intValue() : calculateRowColumns(table.columns());
+ int count = (null != span && span.intValue() != Integer.MIN_VALUE) ?
span.intValue() : calculateRowColumns(table.columns());
return count;
}
@@ -122,10 +108,4 @@
}
return count;
}
-
- @Override
- public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
- encodeTableBody(context, (UIDataTable) component);
- }
-
}
Deleted:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/CellEncodeEvent.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/CellEncodeEvent.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/CellEncodeEvent.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -1,36 +0,0 @@
-package org.richfaces.renderkit;
-
-import java.util.Map;
-
-import javax.faces.component.UIColumn;
-import javax.faces.context.FacesContext;
-
-//TODO nick - can this be UIComponent instead of UIColumn?
-public class CellEncodeEvent implements ElementEncodeEvent <UIColumn> {
-
- private FacesContext context;
-
- private UIColumn source;
-
- private Map<String, String> styleClasses;
-
-
- public CellEncodeEvent(FacesContext context, UIColumn source) {
- this.context = context;
- this.source = source;
- }
-
- public FacesContext getContext() {
- return this.context;
- }
-
- public UIColumn getSource() {
- return this.source;
- }
-
- public Map<String, String> getStyleClasses() {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
Deleted:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ElementEncodeEvent.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ElementEncodeEvent.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ElementEncodeEvent.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -1,16 +0,0 @@
-package org.richfaces.renderkit;
-
-import java.util.Map;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-public interface ElementEncodeEvent <T extends UIComponent> {
-
- public Map <String, String> getStyleClasses();
-
- public T getSource();
-
- public FacesContext getContext();
-
-}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ElementEncodeListener.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ElementEncodeListener.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ElementEncodeListener.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -2,27 +2,42 @@
import java.io.IOException;
+import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
-import org.richfaces.component.UISubTable;
+import org.richfaces.component.UIDataTable;
public interface ElementEncodeListener {
+
+ public void encodeRowStart(ResponseWriter writer, FacesContext context, UIComponent
component, RowHolder holder) throws IOException;
-// public void encodeFirstCell(CellEncodeEvent event)throws IOException;
+ public void encodeRowEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException;
- //TODO nick - also encodeFooterCell?
- public void encodeHeaderCell(CellEncodeEvent event) throws IOException;
+ public void encodeCellStart(ResponseWriter writer, FacesContext context, UIComponent
component, RowHolder holder) throws IOException;
- public void encodeCell(CellEncodeEvent event) throws IOException;
-
- //TODO nick - encodeFirstRow and encodeRowStart are not on the same abstraction level
- public void encodeFirstRow(RowEncodeEvent event) throws IOException;
+ public void encodeCellEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException;
- public void encodeRowStart(RowEncodeEvent event) throws IOException;
+// public void encodeHeaderCellStart(ResponseWriter writer, FacesContext context,
UIComponent component, String styleClass) throws IOException;
+//
+// public void encodeHeaderCellEnd(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException;
- public void encodeRowEnd(RowEncodeEvent event) throws IOException;
+ public void encodeFirstRowStart(ResponseWriter writer, FacesContext context,
UIComponent component, RowHolder holder) throws IOException;
+
+ public void encodeFirstRowEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException;
+
+ public void encodeTableStart(ResponseWriter writer, FacesContext context, UIDataTable
dataTable) throws IOException;
+
+ public void encodeTableEnd(ResponseWriter writer, FacesContext context, UIDataTable
dataTable) throws IOException;
+
+ public void encodeTableBodyStart(ResponseWriter writer, FacesContext context,
UIDataTable dataTable) throws IOException;
+
+ public void encodeTableBodyEnd(ResponseWriter writer, FacesContext context, UIDataTable
dataTable) throws IOException;
+
+ public void encodeCaption(ResponseWriter writer, FacesContext context, UIDataTable
dataTable) throws IOException;
+
+ public void encodeHeader(ResponseWriter writer, FacesContext context, UIDataTable
dataTable, int columns) throws IOException;
+
+ public void encodeFooter(ResponseWriter writer, FacesContext context, UIDataTable
dataTable, int columns) throws IOException;
- //TODO nick - should be removed?
- public void encodeSubTable(FacesContext context, UISubTable subTable) throws
IOException;
-
}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ProcessRowHolder.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ProcessRowHolder.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/ProcessRowHolder.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -0,0 +1,28 @@
+package org.richfaces.renderkit;
+
+import javax.faces.component.UIComponent;
+
+public class ProcessRowHolder {
+
+ private UIComponent component;
+
+ private int processRow;
+
+
+ public int getProcessRow() {
+ return processRow;
+ }
+
+ public void setProcessRow(int processRow) {
+ this.processRow = processRow;
+ }
+
+ public ProcessRowHolder(UIComponent component) {
+ this.component = component;
+ }
+
+ public int nextRow(){
+ return ++processRow;
+ }
+
+}
Deleted:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowEncodeEvent.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowEncodeEvent.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowEncodeEvent.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -1,34 +0,0 @@
-package org.richfaces.renderkit;
-
-import java.util.Map;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-public class RowEncodeEvent implements ElementEncodeEvent<UIComponent> {
-
- private FacesContext context;
-
- private UIComponent source;
-
- private Map<String, String> styleClasses;
-
- public RowEncodeEvent(FacesContext context, UIComponent source) {
- this.context = context;
- this.source = source;
- }
-
- public FacesContext getContext() {
- return this.context;
- }
-
- public UIComponent getSource() {
- return this.source;
- }
-
- public Map<String, String> getStyleClasses() {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
Deleted:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowEncoder.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowEncoder.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowEncoder.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -1,126 +0,0 @@
-package org.richfaces.renderkit;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.faces.component.UIColumn;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.renderkit.RendererUtils;
-import org.richfaces.component.Column;
-import org.richfaces.component.Row;
-import org.richfaces.component.UISubTable;
-
-
-public class RowEncoder {
-
-
- private ElementEncodeListener listener;
-
- private Map <String, String> styleClasses = new HashMap<String, String>();
-
- private boolean header = false;
-
- public void encodeCell(FacesContext context, UIColumn column, int currentColumn) throws
IOException {
- CellEncodeEvent event = new CellEncodeEvent(context, column);
- listener.encodeCell(event);
- }
-
- public void encodeHeaderCell(FacesContext context, UIColumn column, int currentColumn)
throws IOException {
- CellEncodeEvent event = new CellEncodeEvent(context, column);
- listener.encodeHeaderCell(event);
- }
-
- public void encodeRowEnd(FacesContext context, UIComponent component) throws IOException
{
- RowEncodeEvent event = new RowEncodeEvent(context, component);
- listener.encodeRowEnd(event);
- }
-
- public void encodeRowStart(FacesContext context, UIComponent component) throws
IOException {
- RowEncodeEvent event = new RowEncodeEvent(context, component);
- listener.encodeRowStart(event);
- }
-
- public void encodeFirstRow(FacesContext context, UIComponent row) throws IOException {
- RowEncodeEvent event = new RowEncodeEvent(context, row);
- listener.encodeFirstRow(event);
- }
-
- public ElementEncodeListener getListener() {
- return listener;
- }
-
- public void setListener(ElementEncodeListener listener) {
- this.listener = listener;
- }
-
- public void encodeSubTable(FacesContext context, UISubTable subTable) throws IOException
{
- subTable.resetDataModel(context);
- listener.encodeSubTable(context, subTable);
- }
-
- public void encodeRows(FacesContext context, UIComponent component) throws IOException
{
- boolean firstRow = true;
- int currentColumn = 0;
- Iterator<UIComponent> iterator = component.getChildren().iterator();
- while(iterator.hasNext()) {
-
- UIComponent child = iterator.next();
- if(!(child instanceof UISubTable)) {
-
- if(firstRow) {
- encodeRowStart(context, child);
- firstRow = false;
- }
-
- if(child instanceof Row) {
- if(!firstRow) {
- encodeRowEnd(context, null);
- }
- encodeRows(context, child);
- }
-
- if(child instanceof UIColumn) {
-
- UIColumn column = (UIColumn)child;
- //TODO: check
- if(column instanceof Column && ((Column)column).isBreakBefore()) {
- encodeRows(context, column);
- }
-
- if(header) {
- encodeHeaderCell(context, column, currentColumn);
- } else {
- encodeCell(context, column, currentColumn);
- }
-
- }
-
- } else {
- UISubTable subTable = (UISubTable)child;
- encodeSubTable(context,subTable);
- }
- }
- encodeRowEnd(context, null);
- }
-
- public RendererUtils getRenderUtils() {
- return RendererUtils.getInstance();
- }
-
- public void setStyleClass(String key, String value) {
- styleClasses.put(key, value);
- }
-
- public boolean isHeader() {
- return header;
- }
-
- public void setHeader(boolean header) {
- this.header = header;
- }
-
-}
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowHolder.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowHolder.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/RowHolder.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -0,0 +1,90 @@
+package org.richfaces.renderkit;
+
+import org.richfaces.component.Row;
+
+public class RowHolder {
+
+ private int currentRow = 0;
+
+ private String cellElement;
+
+ private String cellClass;
+
+ private String rowClass;
+
+ private String firstRowClass;
+
+ private boolean headerRow;
+
+ public boolean isHeaderRow() {
+ return headerRow;
+ }
+
+ public void setHeaderRow(boolean headerRow) {
+ this.headerRow = headerRow;
+ }
+
+ private Row row;
+
+ public RowHolder(Row row) {
+ this.row = row;
+ }
+
+ public int getCurrentRow() {
+ return currentRow;
+ }
+
+ public int nextRow() {
+ return ++currentRow;
+ }
+
+ public void setCurrentRow(int currentRow) {
+ this.currentRow = currentRow;
+ }
+
+ public void resetCurrentRow() {
+ this.currentRow = 0;
+ }
+
+ public String getCellClass() {
+ return this.cellClass;
+ }
+
+ public void setCellClass(String cellClass) {
+ this.cellClass = cellClass;
+ }
+
+ public String getRowClass() {
+ return this.rowClass;
+ }
+
+ public void setRowClass(String rowClass) {
+ this.rowClass = rowClass;
+ }
+
+ public String getFirstRowClass() {
+ return this.firstRowClass;
+ }
+
+ public void setFirstRowClass(String firstRowClass) {
+ this.firstRowClass = firstRowClass;
+ }
+
+ public String getCellElement() {
+ return cellElement;
+ }
+
+ public void setCellElement(String cellElement) {
+ this.cellElement = cellElement;
+ }
+
+ public Row getRow() {
+ return this.row;
+ }
+
+ public void setRow(Row row) {
+ this.row = row;
+ }
+
+}
+
Added:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/SimpleDataTableRenderer.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/SimpleDataTableRenderer.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/SimpleDataTableRenderer.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -0,0 +1,463 @@
+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.UIColumn;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.Row;
+import org.richfaces.component.UIDataTable;
+import org.richfaces.component.UISimpleDataTable;
+
+@ResourceDependencies({
+ @ResourceDependency(name = "simple-datatable.js"),
+ @ResourceDependency(name = "simple-table.css")
+})
+public class SimpleDataTableRenderer extends AbstractTableRenderer implements
ElementEncodeListener{
+
+
+ protected void encodeTableStructure(ResponseWriter writer, FacesContext context,
UIDataTable dataTable) throws IOException {
+
+ Object key = dataTable.getRowKey();
+ dataTable.captureOrigValue(context);
+ dataTable.setRowKey(context, null);
+
+ encodeCaption(writer, context, dataTable);
+
+ //TODO nick - do we need this element if "columnsWidth" is absent?
+ //TODO nick - use constants from HTML class for attribute/element names
+ writer.startElement("colgroup", dataTable);
+ int columns = getColumnsCount(dataTable);
+
+ writer.writeAttribute(HTML.SPAN_ELEM, String.valueOf(columns), null);
+ String columnsWidth = (String)
dataTable.getAttributes().get("columnsWidth");
+
+ if (null != columnsWidth) {
+ String[] widths = columnsWidth.split(",");
+ for (int i = 0; i < widths.length; i++) {
+ writer.startElement("col", dataTable);
+ writer.writeAttribute("width", widths[i], null);
+ writer.endElement("col");
+ }
+ }
+ writer.endElement("colgroup");
+
+ encodeHeader(writer, context, dataTable, columns);
+ encodeFooter(writer, context, dataTable, columns);
+
+ dataTable.setRowKey(context, key);
+ dataTable.restoreOrigValue(context);
+
+ }
+
+ public void encodeRows(FacesContext context, UIDataTable dataTable) throws IOException
{
+
+ RowHolder holder = new RowHolder(dataTable);
+ holder.setCellClass(dataTable.getCellSkinClass());
+ holder.setRowClass(dataTable.getRowSkinClass());
+ holder.setFirstRowClass(dataTable.getFirstRowSkinClass());
+ holder.setHeaderRow(false);
+
+ encodeRows(context, dataTable, holder);
+ }
+
+ public void encodeRow(FacesContext context, RowHolder rowHolder) throws IOException {
+
+ boolean rowStart = true;
+ int processCell = 0;
+
+ Row row = rowHolder.getRow();
+ int processRow = rowHolder.getCurrentRow();
+
+ ResponseWriter writer = context.getResponseWriter();
+
+ Iterator<UIComponent> iterator = row.columns();
+ while(iterator.hasNext()) {
+
+ UIComponent child = iterator.next();
+ if(child instanceof Row) {
+
+ Row childRow = (Row)child;
+ RowHolder childRowHolder = new RowHolder(childRow);
+ childRowHolder.setCurrentRow(processRow);
+ childRowHolder.setCellElement(rowHolder.getCellElement());
+
+ if(rowHolder.isHeaderRow()) {
+ childRowHolder.setRowClass(rowHolder.getRowClass());
+ childRowHolder.setFirstRowClass(rowHolder.getFirstRowClass());
+ childRowHolder.setCellClass(rowHolder.getCellClass());
+ } else {
+ childRowHolder.setRowClass(childRow.getRowSkinClass());
+ childRowHolder.setFirstRowClass(childRow.getFirstRowSkinClass());
+ childRowHolder.setCellClass(childRow.getCellSkinClass());
+ }
+ childRowHolder.setHeaderRow(rowHolder.isHeaderRow());
+ encodeRows(context, childRow, childRowHolder);
+
+ } else if(child instanceof UIColumn) {
+
+ if(rowStart) {
+
+ if(processRow == 0) {
+ encodeFirstRowStart(writer, context, child, rowHolder);
+ } else {
+ encodeRowStart(writer, context, child, rowHolder);
+ }
+
+ rowStart = false;
+ }
+
+ encodeCellStart(writer, context, child, rowHolder);
+ encodeCellEnd(writer, context, child);
+
+ if(!iterator.hasNext()) {
+ if(processRow == 0) {
+ encodeFirstRowEnd(writer, context, child);
+ } else {
+ encodeRowEnd(writer, context, child);
+ }
+ }
+ processCell++;
+ }
+ }
+ }
+
+ @Override
+ protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ if(!shouldProceed(component)) {
+ return;
+ }
+ UIDataTable dataTable = (UIDataTable)component;
+ encodeTableStart(writer,context, dataTable);
+ encodeTableStructure(writer, context, dataTable);
+ }
+
+ @Override
+ protected void doEncodeChildren(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+
+ if(!shouldProceed(component)) {
+ return;
+ }
+
+ UIDataTable dataTable = (UIDataTable)component;
+ encodeTableBodyStart(writer, context, dataTable);
+ encodeRows(context, dataTable);
+ encodeTableBodyEnd(writer, context, dataTable);
+
+ }
+
+ @Override
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+
+ if(!shouldProceed(component)) {
+ return;
+ }
+
+ UIDataTable dataTable = (UIDataTable)component;
+ encodeTableEnd(writer, context, dataTable);
+ }
+
+ protected boolean shouldProceed(UIComponent component) {
+ return (component instanceof UIDataTable);
+ }
+
+ @Override
+ protected Class<? extends UIComponent> getComponentClass() {
+ return UISimpleDataTable.class;
+ }
+
+ public void encodeCellEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ writer.endElement(HTML.TD_ELEM);
+ }
+
+ public void encodeCellStart(ResponseWriter writer, FacesContext context, UIComponent
component, RowHolder holder) throws IOException {
+ writer.startElement(HTML.TD_ELEM, component);
+ String cellClass = holder.getCellClass();
+ encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, cellClass);
+ renderChildren(context, component);
+ }
+
+ public void encodeFirstRowEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ writer.endElement(HTML.TR_ELEMENT);
+ }
+
+ public void encodeFirstRowStart(ResponseWriter writer, FacesContext context, UIComponent
component, RowHolder holder) throws IOException {
+ writer.startElement(HTML.TR_ELEMENT, component);
+ String styleClass = holder.getFirstRowClass() + " " + holder.getRowClass();
+ encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, styleClass);
+ }
+
+ public void encodeRowEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ writer.endElement(HTML.TR_ELEMENT);
+ }
+
+ public void encodeRowStart(ResponseWriter writer, FacesContext context, UIComponent
component, RowHolder holder) throws IOException {
+ writer.startElement(HTML.TR_ELEMENT, component);
+ String styleClass = holder.getRowClass();
+ encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, styleClass);
+ }
+
+ public void encodeTableBodyEnd(ResponseWriter writer, FacesContext context, UIDataTable
component) throws IOException {
+ writer.endElement(HTML.TABLE_ELEMENT);
+ }
+
+ public void encodeTableBodyStart(ResponseWriter writer, FacesContext context,
UIDataTable component) throws IOException {
+ writer.startElement(HTML.BODY_ELEMENT, component);
+ }
+
+ public void encodeTableEnd(ResponseWriter writer, FacesContext context, UIDataTable
component) throws IOException {
+ writer.endElement(HTML.BODY_ELEMENT);
+ }
+
+ public void encodeTableStart(ResponseWriter writer, FacesContext context, UIDataTable
component) throws IOException {
+ writer.startElement(HTML.TABLE_ELEMENT, component);
+ String styleClass = getTableSkinClass();
+ encodeStyleClass(writer, context, component, HTML.STYLE_CLASS_ATTR, styleClass);
+ }
+
+ public void encodeCaption(ResponseWriter writer, FacesContext context, UIDataTable
dataTable) throws IOException {
+
+ UIComponent caption = dataTable.getCaption();
+
+ if (caption == null) {
+ return;
+ }
+
+ if(!caption.isRendered()) {
+ return;
+ }
+
+ writer.startElement(HTML.CAPTION_ELEMENT, dataTable);
+
+ String captionClass = (String)
dataTable.getAttributes().get("captionClass");
+ String captionSkinClass = getCaptionSkinClass();
+ captionClass = captionClass != null ? captionClass + " " + captionClass :
captionSkinClass;
+
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, captionClass, "captionClass");
+
+ String captionStyle = (String)
dataTable.getAttributes().get("captionStyle");
+
+ if (captionStyle != null && captionStyle.trim().length()!=0) {
+ writer.writeAttribute(HTML.STYLE_ATTRIBUTE, captionStyle, "captionStyle");
+ }
+
+ renderChild(context, caption);
+
+ writer.endElement(HTML.CAPTION_ELEMENT);
+ }
+
+ public void encodeFooter(ResponseWriter writer, FacesContext context, UIDataTable
dataTable, int columns) throws IOException {
+
+ Iterator<UIComponent> tableColumns = dataTable.columns();
+
+ UIComponent footer = dataTable.getFooter();
+
+ boolean columnFacetPresent = isColumnFacetPresent(dataTable, "footer");
+
+ if ((footer != null && footer.isRendered()) || columnFacetPresent) {
+
+ writer.startElement(HTML.TFOOT_ELEMENT, dataTable);
+ String footerClass = (String) dataTable.getAttributes().get("footerClass");
+
+ if (columnFacetPresent) {
+ writer.startElement(HTML.TR_ELEMENT, dataTable);
+
+ encodeStyleClass(writer, context, dataTable, "footerClass",
"rich-table-subfooter");
+ //TODO nick - use "th" instead of "td"?
+ //TODO nick - rename method "encodeHeaderFacets"
+ encodeHeaderFacets(context, writer, tableColumns,
"rich-table-subfootercell",
+ footerClass, "footer", HTML.TD_ELEM, columns);
+ writer.endElement("tr");
+ }
+
+
+ if (footer != null && footer.isRendered()) {
+ //TODO nick - use "th" instead of "td"?
+ //TODO nick - rename method "encodeTableHeaderFacet"
+ encodeTableHeaderFacet(context, columns, writer, footer,
+ "rich-table-footer",
+ "rich-table-footer-continue",
+ "rich-table-footercell",
+ footerClass, HTML.TH_ELEM);
+ }
+
+ writer.endElement(HTML.TFOOT_ELEMENT);
+ }
+ }
+
+ public void encodeHeader(ResponseWriter writer, FacesContext context, UIDataTable
dataTable, int columns) throws IOException {
+
+ UIComponent header = dataTable.getHeader();
+ boolean isEncodeHeaders = isEncodeHeaders(dataTable);
+
+ if ((header != null && header.isRendered()) || isEncodeHeaders) {
+
+ writer.startElement(HTML.THEAD_ELEMENT, dataTable);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-table-thead", null);
+
+ String headerClass = (String) dataTable.getAttributes().get("headerClass");
+
+ if (header != null && header.isRendered()) {
+ encodeTableHeaderFacet(context, columns, writer, header,
+ "rich-table-header",
+ //TODO nick - rename classes!!!
+ "rich-table-header-continue",
+ "rich-table-headercell",
+ headerClass, HTML.TH_ELEM);
+ }
+
+ if (isEncodeHeaders) {
+ writer.startElement(HTML.TR_ELEMENT, dataTable);
+ encodeStyleClass(writer, context, dataTable, "headerClass",
"rich-table-subheader");
+ encodeHeaderFacets(context, writer, dataTable.columns(),
"rich-table-subheadercell", headerClass, "header", HTML.TH_ELEM,
columns);
+ writer.endElement(HTML.TR_ELEMENT);
+ }
+
+ writer.endElement("thead");
+ }
+ }
+
+ protected void encodeTableHeaderFacet(FacesContext context, int columns,
ResponseWriter writer, UIComponent footer,
+ String skinFirstRowClass, String skinRowClass, String skinCellClass, String
footerClass, String element)
+ throws IOException {
+
+ if(footer instanceof Row) {
+ Row row = (Row)footer;
+
+ RowHolder holder = new RowHolder(row);
+ holder.setCellElement(element);
+ holder.setFirstRowClass(skinFirstRowClass);
+ holder.setRowClass(skinRowClass);
+ holder.setCellClass(skinCellClass);
+ holder.resetCurrentRow();
+ holder.setHeaderRow(true);
+
+ encodeRows(context, row, holder);
+ } else {
+ writer.startElement(HTML.TR_ELEMENT, footer);
+
+ String rowClass = skinFirstRowClass;
+ String cellClass = skinCellClass;
+ if(footerClass != null && footerClass.trim().length()!=0) {
+ rowClass = rowClass + " " + footerClass;
+ cellClass = cellClass + " " + footerClass;
+ }
+
+ encodeStyleClass(writer, context, footer, null, rowClass);
+
+ writer.startElement(element, footer);
+
+ encodeStyleClass(writer, context, footer, null, cellClass);
+
+ if(columns > 0) {
+ writer.writeAttribute("colspan", String.valueOf(columns), null);
+ }
+ writer.writeAttribute("scope", "colgroup", null);
+
+ renderChild(context, footer);
+
+ writer.endElement(element);
+ writer.endElement("tr");
+ }
+ }
+
+ protected void encodeHeaderFacets(FacesContext context, ResponseWriter writer,
Iterator<UIComponent> headers,
+ String skinCellClass, String headerClass, String facetName, String element,
int colCount) throws IOException {
+
+ int tColCount = 0;
+
+ while (headers.hasNext()) {
+ UIComponent column = headers.next();
+ if (!column.isRendered()) {
+ continue;
+ }
+
+ Integer colspan = (Integer)
column.getAttributes().get("colspan");
+ if (colspan != null && colspan.intValue() > 0) {
+ tColCount += colspan.intValue();
+ } else {
+ tColCount++;
+ }
+
+ if (tColCount > colCount) {
+ break;
+ }
+
+ String classAttribute = facetName + "Class";
+ String columnHeaderClass = (String)
column.getAttributes().get(classAttribute);
+
+ String styleClass = skinCellClass;
+ if(headerClass != null && headerClass.trim().length() != 0) {
+ styleClass = styleClass + " " + headerClass;
+ }
+
+ if(columnHeaderClass != null && columnHeaderClass.trim().length()
!= 0) {
+ styleClass = styleClass + " " + columnHeaderClass;
+ }
+
+
+ writer.startElement(element, column);
+
+ encodeStyleClass(writer, context, column, null, styleClass);
+
+ writer.writeAttribute("scope", "col", null);
+ getUtils().encodeAttribute(context, column, "colspan");
+
+ UIComponent facet = column.getFacet(facetName);
+ if (facet != null && facet.isRendered()) {
+ renderChild(context, facet);
+ }
+
+ writer.endElement(element);
+ }
+ }
+
+
+ protected void encodeStyleClass(ResponseWriter writer, FacesContext context,
UIComponent component , String styleClassAttribute, String styleClass) throws IOException
{
+ boolean isEmpty = isEmpty(component, styleClassAttribute);
+ if( isEmpty && !(styleClass != null && styleClass.trim().length() !=
0)) {
+ return;
+ }
+
+ String componentStyleClass = isEmpty ? styleClass : styleClass + " " +
component.getAttributes().get(styleClassAttribute);
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, componentStyleClass, null);
+ }
+
+ protected boolean isEmpty(UIComponent component, String attribute) {
+ if(attribute == null) {
+ return true;
+ }
+ String value = (String) component.getAttributes().get(attribute);
+ return !(value != null && value.trim().length()!=0);
+ }
+
+ protected void encodeStyle(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ String style = (String)component.getAttributes().get(HTML.STYLE_ATTRIBUTE);
+ if(!isEmptyStyle(style)) {
+ writer.writeAttribute(HTML.STYLE_ATTRIBUTE, style, null);
+ }
+ }
+
+ protected boolean isEmptyStyle(String style) {
+ return !((style != null) && (style.trim().length()!=0));
+ }
+
+ protected String getTableSkinClass() {
+ return "rich-table";
+ }
+
+ protected String getTableHeadSkinClass() {
+ return "rich-table-head";
+ }
+
+ protected String getCaptionSkinClass() {
+ return "rich-table-caption";
+ }
+
+}
Deleted:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/SimpleDataTableRendererBase.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/SimpleDataTableRendererBase.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/SimpleDataTableRendererBase.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -1,347 +0,0 @@
-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.UIColumn;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
-import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.Row;
-import org.richfaces.component.UIDataTable;
-import org.richfaces.component.UISubTable;
-
-@ResourceDependencies({
- @ResourceDependency(name = "simple-datatable.js"),
- @ResourceDependency(name = "simple-table.css")
-})
-public abstract class SimpleDataTableRendererBase extends AbstractTableRenderer {
-
- public void encodeRowStart(RowEncodeEvent event) throws IOException {
- ResponseWriter writer = event.getContext().getResponseWriter();
- writer.startElement(HTML.TR_ELEMENT, event.getSource());
- }
-
- public void encodeRowEnd(RowEncodeEvent event) throws IOException {
- ResponseWriter writer = event.getContext().getResponseWriter();
- writer.endElement(HTML.TR_ELEMENT);
- }
-
- public void encodeFirstRow(RowEncodeEvent event) throws IOException {
- ResponseWriter writer = event.getContext().getResponseWriter();
- writer.startElement(HTML.TR_ELEMENT, event.getSource());
- }
-
- public void encodeCell(CellEncodeEvent event) throws IOException {
- ResponseWriter writer = event.getContext().getResponseWriter();
- FacesContext context = event.getContext();
- UIColumn column = event.getSource();
-
- writer.startElement(HTML.TD_ELEM, column);
- getUtils().encodeId(context, column);
- getCellStyleClasses(context, column);
- renderChildren(context, column);
-
- writer.endElement(HTML.TD_ELEM);
- }
-
- public void encodeHeaderCell(CellEncodeEvent event) throws IOException {
- ResponseWriter writer = event.getContext().getResponseWriter();
- FacesContext context = event.getContext();
- UIColumn column = event.getSource();
-
- writer.startElement(HTML.TH_ELEM, column);
- //TODO --- move to the separate method
- getUtils().encodeId(context, column);
- getCellStyleClasses(context, column);
- renderChildren(context, column);
- //------
- writer.endElement(HTML.TH_ELEM);
- }
-
- @Override
- public RowEncoder getRowEncoder(TableHolder holder) {
- RowEncoder encoder = new RowEncoder();
- encoder.setListener(this);
- return encoder;
- }
-
- public void encodeSubTable(FacesContext context, UISubTable subTable) throws
IOException {
- encodeRows(context, subTable);
- }
-
- //
---------------------------------------------------------------------------------------
-
- public void encodeTableStructure(FacesContext context, UIDataTable table) throws
IOException {
-
- Object key = table.getRowKey();
- table.captureOrigValue(context);
- table.setRowKey(context, null);
-
- encodeCaption(context, table);
-
- // Encode colgroup definition.
- ResponseWriter writer = context.getResponseWriter();
-
- //TODO nick - do we need this element if "columnsWidth" is absent?
- //TODO nick - use constants from HTML class for attribute/element names
- writer.startElement("colgroup", table);
-
- int columns = getColumnsCount(table);
-
- writer.writeAttribute("span", String.valueOf(columns), null);
- String columnsWidth = (String)
table.getAttributes().get("columnsWidth");
-
- if (null != columnsWidth) {
- String[] widths = columnsWidth.split(",");
- for (int i = 0; i < widths.length; i++) {
- writer.startElement("col", table);
- writer.writeAttribute("width", widths[i], null);
- writer.endElement("col");
- }
- }
- writer.endElement("colgroup");
-
- encodeHeader(context, table, columns);
- encodeFooter(context, table, columns);
-
- table.setRowKey(context, key);
- table.restoreOrigValue(context);
- }
-
- public void encodeCaption(FacesContext context, UIDataTable table) throws IOException
{
-
- UIComponent caption = table.getCaption();
- //TODO nick - check for "rendered" attribute
- if (caption == null) {
- return;
- }
-
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement("caption", table);
-
- String captionClass = (String)
table.getAttributes().get("captionClass");
- captionClass = captionClass != null ? "rich-table-caption " +
captionClass : "rich-table-caption";
- writer.writeAttribute("class", captionClass,
"captionClass");
-
- String captionStyle = (String)
table.getAttributes().get("captionStyle");
- //TODO nick - check for empty string
- if (captionStyle != null) {
- writer.writeAttribute("style", captionStyle,
"captionStyle");
- }
-
- renderChild(context, caption);
-
- writer.endElement("caption");
-
- }
-/*
- @Override
- public void encodeCell(FacesContext context, UIComponent component) throws IOException
{
- CellEncoder cellEncode = new SimpleCellEncoder(getUtils(), getCellStyleClasses(context,
component));
- cellEncode.encodeBegin(context, component);
- renderChildren(context, component);
- cellEncode.encodeEnd(context, component);
-
- }
-
- */
-
- public void encodeHeader(FacesContext context, UIDataTable table, int columns) throws
IOException {
- UIComponent header = table.getHeader();
- boolean isEncodeHeaders = isEncodeHeaders(table);
-
- //TODO nick - check for "rendered" attribute
- if (header != null || isEncodeHeaders) {
-
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement("thead", table);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rich-table-thead",
null);
- String headerClass = (String)
table.getAttributes().get("headerClass");
-
- if (header != null) {
- encodeTableHeaderFacet(context, columns, writer, header,
- "rich-table-header",
- //TODO nick - rename classes!!!
- "rich-table-header-continue",
- "rich-table-headercell",
- headerClass, "th");
- }
-
- if (isEncodeHeaders) {
- writer.startElement("tr", table);
- encodeStyleClass(writer, null, "rich-table-subheader", null,
headerClass);
- encodeHeaderFacets(context, writer, table.columns(),
"rich-table-subheadercell", headerClass, "header",
- "th", columns);
- writer.endElement("tr");
- }
-
- writer.endElement("thead");
- }
- }
-
- public void encodeFooter(FacesContext context, UIDataTable table, int columns) throws
IOException {
- ResponseWriter writer = context.getResponseWriter();
- Iterator<UIComponent> tableColumns = table.columns();
-
- UIComponent footer = table.getFooter();
- boolean columnFacetPresent = isColumnFacetPresent(table, "footer");
-
- if (footer != null || columnFacetPresent) {
- writer.startElement("tfoot", table);
- String footerClass = (String)
table.getAttributes().get("footerClass");
-
- if (columnFacetPresent) {
- writer.startElement("tr", table);
- encodeStyleClass(writer, null, "rich-table-subfooter", null,
footerClass);
- //TODO nick - use "th" instead of "td"?
- //TODO nick - rename method "encodeHeaderFacets"
- encodeHeaderFacets(context, writer, tableColumns,
"rich-table-subfootercell", footerClass, "footer",
- "td", columns);
- writer.endElement("tr");
- }
-
- if (footer != null) {
- //TODO nick - use "th" instead of "td"?
- //TODO nick - rename method "encodeTableHeaderFacet"
- encodeTableHeaderFacet(context, columns, writer, footer,
- "rich-table-footer",
- "rich-table-footer-continue",
- "rich-table-footercell",
- footerClass, "td");
- }
- writer.endElement("tfoot");
- }
- }
-
- protected void encodeTableHeaderFacet(FacesContext context, int columns,
ResponseWriter writer, UIComponent footer,
- String skinFirstRowClass, String skinRowClass, String skinCellClass, String
footerClass, String element)
- throws IOException {
-
- boolean isColgroup = footer instanceof Row;
-
- if (!isColgroup) {
- writer.startElement("tr", footer);
- encodeStyleClass(writer, null, skinFirstRowClass, footerClass, null);
- writer.startElement(element, footer);
- encodeStyleClass(writer, null, skinCellClass, footerClass, null);
-
- if (columns > 0) {
- writer.writeAttribute("colspan", String.valueOf(columns),
null);
- }
-
- writer.writeAttribute("scope", "colgroup", null);
- }
-
- if (isColgroup) {
- //TODO nick - tableHolder is null
- RowEncoder encoder = getRowEncoder(null);
- encoder.setHeader(true);
- encoder.encodeRows(context, footer);
- } else {
- renderChild(context, footer);
- }
-
- if (!isColgroup) {
- writer.endElement(element);
- writer.endElement("tr");
- }
- }
-
- protected void encodeHeaderFacets(FacesContext context, ResponseWriter writer,
Iterator<UIComponent> headers,
- String skinCellClass, String headerClass, String facetName, String element, int
colCount) throws IOException {
-
- int tColCount = 0;
-
- // HeaderEncodeStrategy richEncodeStrategy = new
- // RichHeaderEncodeStrategy();
- // HeaderEncodeStrategy simpleEncodeStrategy = new
- // SimpleHeaderEncodeStrategy();
-
- while (headers.hasNext()) {
- UIComponent column = headers.next();
- if (!column.isRendered()) {
- continue;
- }
-
- Integer colspan = (Integer) column.getAttributes().get("colspan");
- if (colspan != null && colspan.intValue() > 0) {
- tColCount += colspan.intValue();
- } else {
- tColCount++;
- }
-
- if (tColCount > colCount) {
- break;
- }
-
- String classAttribute = facetName + "Class";
- String columnHeaderClass = (String)
column.getAttributes().get(classAttribute);
-
- writer.startElement(element, column);
- encodeStyleClass(writer, null, skinCellClass, headerClass,
columnHeaderClass);
- writer.writeAttribute("scope", "col", null);
- getUtils().encodeAttribute(context, column, "colspan");
-
- UIComponent facet = column.getFacet(facetName);
- if (facet != null && facet.isRendered()) {
- renderChild(context, facet);
- }
-
- writer.endElement(element);
- }
- }
-
- @Override
- public void encodeBodyBegin(FacesContext context, UIDataTable table) throws
IOException {
- String clientId = table.getClientId(context);
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement("tbody", table);
- writer.writeAttribute("id", clientId + ":tb", null);
- }
-
- @Override
- public void encodeBodyEnd(FacesContext context, UIDataTable table) throws IOException
{
- ResponseWriter writer = context.getResponseWriter();
- writer.endElement("tbody");
- }
-
- protected String getRowSkinClasses(boolean firstColumn) {
- String rowSkinClass = getRowSkinClass();
- if (firstColumn) {
- String firstRowSkinClass = getFirstRowSkinClass();
- if (firstRowSkinClass != null && firstRowSkinClass.length() != 0) {
- rowSkinClass = (rowSkinClass != null &&
rowSkinClass.trim().length() != 0)
- ? rowSkinClass + " " + firstRowSkinClass :
firstRowSkinClass;
- }
- }
-
- return rowSkinClass;
- }
-
- /**
- * @return
- */
- protected String getRowSkinClass() {
- return "rich-table-row";
- }
-
- /**
- * @return
- */
- protected String getFirstRowSkinClass() {
- return "rich-table-firstrow";
- }
-
- /**
- * @return
- */
- protected String getCellSkinClass() {
- return "rich-table-cell";
- }
-
-}
Deleted:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/TableHolder.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/TableHolder.java 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/renderkit/TableHolder.java 2009-11-05
10:42:57 UTC (rev 15831)
@@ -1,118 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.renderkit;
-
-import java.util.Map;
-
-import org.richfaces.component.UIDataAdaptor;
-
-/**
- * Private class for keep reference to table and intermediate iteration values ( current
row styles, events etc )
- * @author shura
- *
- */
-public class TableHolder {
- private UIDataAdaptor component;
- private int rowCounter;
-
- //TODO nick - not used anyhow
- private int gridRowCounter;
-
- private String[] rowClasses;
- private String[] columnsClasses;
-
- /**
- * @param table
- */
- public TableHolder(UIDataAdaptor component) {
- this.component = component;
- this.rowCounter = 0;
- this.gridRowCounter = 0;
- Map<String, Object> attributes = component.getAttributes();
- String classes = (String) attributes.get("rowClasses");
- if(null != classes){
- rowClasses=classes.split(",");
- }
- classes = (String) attributes.get("columnClasses");
- if(null != classes){
- columnsClasses=classes.split(",");
- }
- }
-
- /**
- * @return the table
- */
- public UIDataAdaptor getTable() {
- return this.component;
- }
-
- /**
- * @return the rowCounter
- */
- public int getRowCounter() {
- return this.rowCounter;
- }
-
- /**
- * Get current rendered row number, and increment to next value.
- * @return the rowCounter
- */
- public int nextRow() {
- return ++rowCounter;
- }
-
- public String getRowClass() {
- int row = rowCounter;
- return getRowClass(row);
- }
-
- //TODO nick - this seems to be removed
- public String getRowClass(int row) {
- String rowClass = null;
- if(null != rowClasses){
- rowClass = rowClasses[row%rowClasses.length];
- }
- return rowClass;
- }
-
- public String getColumnClass(int columnNumber) {
- String columnClass = null;
- if(null != columnsClasses){
- columnClass = columnsClasses[columnNumber%columnsClasses.length];
- }
- return columnClass;
- }
-
- /**
- * @return the gridRowCounter
- */
- public int getGridRowCounter() {
- return this.gridRowCounter;
- }
-
- /**
- * @param gridRowCounter the gridRowCounter to set
- */
- public void setGridRowCounter(int gridRowCounter) {
- this.gridRowCounter = gridRowCounter;
- }
-}
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/faces-config.xml
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/faces-config.xml 2009-11-05
01:25:23 UTC (rev 15830)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/faces-config.xml 2009-11-05
10:42:57 UTC (rev 15831)
@@ -30,23 +30,12 @@
<renderer>
<component-family>org.richfaces.SimpleDataTable</component-family>
<renderer-type>org.richfaces.SimpleDataTableRenderer</renderer-type>
- <renderer-class>org.richfaces.renderkit.html.SimpleDataTableRenderer</renderer-class>
+ <renderer-class>org.richfaces.renderkit.SimpleDataTableRenderer</renderer-class>
</renderer>
<renderer>
<component-family>org.richfaces.ExtendedDataTable</component-family>
<renderer-type>org.richfaces.ExtendedDataTableRenderer</renderer-type>
<renderer-class>org.richfaces.renderkit.html.ExtendedDataTableRenderer</renderer-class>
</renderer>
- <!-- renderer>
- <component-family>org.richfaces.Colgroup</component-family>
- <renderer-type>org.richfaces.ColumnGroupRenderer</renderer-type>
- <renderer-class>org.richfaces.renderkit.html.ColgroupRenderer</renderer-class>
- </renderer>
- <renderer>
- <component-family>org.richfaces.SubTable</component-family>
- <renderer-type>org.richfaces.renderkit.SubTableRenderer</renderer-type>
- <renderer-class>org.richfaces.renderkit.SubTableRenderer</renderer-class>
- </renderer -->
-
</render-kit>
</faces-config>
\ No newline at end of file