Author: hlship
Date: Tue Aug 19 11:07:40 2008
New Revision: 687116
URL: http://svn.apache.org/viewvc?rev=687116&view=rev
Log:
TAPESTRY-1310: Provide access to the current row index and current column index
in Grid
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridColumns.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridColumns.tml
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/LeanGridDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/LeanGridDemo.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java?rev=687116&r1=687115&r2=687116&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
Tue Aug 19 11:07:40 2008
@@ -210,7 +210,7 @@
* @param override if true, the context is used even if empty (normally,
the target page is allowed to passivate,
* providing a context, when the provided context is empty)
* @param context the activation context for the page. If omitted, the
activation context is obtained from the
- * target paget
+ * target page
*/
Link createPageLink(String pageName, boolean override, Object... context);
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.java?rev=687116&r1=687115&r2=687116&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.java
Tue Aug 19 11:07:40 2008
@@ -90,6 +90,18 @@
private Object row;
/**
+ * Optional output parameter used to identify the index (from zero) of the
row being rendered.
+ */
+ @Parameter
+ private int rowIndex;
+
+ /**
+ * Optional output parmater used to identify the index of the column being
rendered.
+ */
+ @Parameter
+ private int columnIndex;
+
+ /**
* The model used to identify the properties to be presented and the order
of presentation. The model may be
* omitted, in which case a default model is generated from the first
object in the data source (this implies that
* the objects provided by the source are uniform). The model may be
explicitly specified to override the default
@@ -168,7 +180,6 @@
* between CSS values (for the "zebra effect"). If null or not bound, then
no particular CSS class value is used.
*/
@Parameter(cache = false)
- @Property(write = false)
private String rowClass;
/**
@@ -215,6 +226,7 @@
@SuppressWarnings("unused")
@Component(
parameters = {
+ "index=inherit:columnIndex",
"lean=inherit:lean",
"overrides=overrides",
"zone=zone"})
@@ -223,7 +235,9 @@
@SuppressWarnings("unused")
@Component(
parameters = {
- "rowClass=rowClass",
+ "rowIndex=inherit:rowIndex",
+ "columnIndex=inherit:columnIndex",
+ "rowClass=inherit:rowClass",
"rowsPerPage=rowsPerPage",
"currentPage=currentPage",
"row=row",
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridColumns.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridColumns.java?rev=687116&r1=687115&r2=687116&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridColumns.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridColumns.java
Tue Aug 19 11:07:40 2008
@@ -59,7 +59,6 @@
@Parameter("this")
private PropertyOverrides overrides;
-
/**
* If not null, then each link is output as a link to update the specified
zone.
*/
@@ -68,7 +67,8 @@
@SuppressWarnings("unused")
@Component(
- parameters = {"event=sort", "disabled=sortDisabled",
"context=columnContext", "class=sortLinkClass", "zone=inherit:zone"})
+ parameters = {"event=sort", "disabled=sortDisabled",
"context=columnContext", "class=sortLinkClass",
+ "zone=inherit:zone"})
private EventLink sort, sort2;
@Inject
@@ -89,9 +89,16 @@
@Inject
private Block standardHeader;
+ /**
+ * Optional output parameter that stores the current column index.
+ */
+ @Parameter
@Property
- private int columnIndex;
+ private int index;
+ /**
+ * Caches the index of the last column.
+ */
private int lastColumnIndex;
@Property(write = false)
@@ -144,9 +151,9 @@
if (sort != null) classes.add(sort);
- if (columnIndex == 0) classes.add(GridConstants.FIRST_CLASS);
+ if (index == 0) classes.add(GridConstants.FIRST_CLASS);
- if (columnIndex == lastColumnIndex)
classes.add(GridConstants.LAST_CLASS);
+ if (index == lastColumnIndex) classes.add(GridConstants.LAST_CLASS);
return TapestryInternalUtils.toClassAttributeValue(classes);
}
@@ -172,7 +179,7 @@
{
onSort(columnId);
- resources.triggerEvent(InternalConstants.GRID_INPLACE_UPDATE, new
Object[]{zone}, null);
+ resources.triggerEvent(InternalConstants.GRID_INPLACE_UPDATE, new
Object[] {zone}, null);
// Event is handled, don't trigger further event handler methods.
@@ -198,7 +205,7 @@
{
if (zone == null) return columnModel.getId();
- return new Object[]{columnModel.getId(), zone};
+ return new Object[] {columnModel.getId(), zone};
}
public String getIconLabel()
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java?rev=687116&r1=687115&r2=687116&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java
Tue Aug 19 11:07:40 2008
@@ -132,6 +132,22 @@
@Parameter(name = "volatile")
private boolean volatileState;
+ /**
+ * Optional output parameter (only set during rendering) that identifies
the current row index. This is the index on
+ * the page (i.e., always numbered from zero) as opposed to the row index
inside the [EMAIL PROTECTED]
+ * org.apache.tapestry5.grid.GridDataSource}.
+ */
+ @Parameter
+ private int rowIndex;
+
+ /**
+ * Optional output parameter that stores the current column index.
+ */
+ @Parameter
+ @Property
+ private int columnIndex;
+
+
@Environmental(false)
private FormSupport formSupport;
@@ -139,7 +155,10 @@
private int endRow;
- private int rowIndex;
+ /**
+ * Index into the [EMAIL PROTECTED]
org.apache.tapestry5.grid.GridDataSource}.
+ */
+ private int dataRowIndex;
private String propertyName;
@@ -156,9 +175,9 @@
if (rc != null) classes.add(rc);
- if (rowIndex == startRow) classes.add(GridConstants.FIRST_CLASS);
+ if (dataRowIndex == startRow) classes.add(GridConstants.FIRST_CLASS);
- if (rowIndex == endRow) classes.add(GridConstants.LAST_CLASS);
+ if (dataRowIndex == endRow) classes.add(GridConstants.LAST_CLASS);
return TapestryInternalUtils.toClassAttributeValue(classes);
}
@@ -206,7 +225,7 @@
startRow = (currentPage - 1) * rowsPerPage;
endRow = Math.min(availableRows - 1, startRow + rowsPerPage - 1);
- rowIndex = startRow;
+ dataRowIndex = startRow;
recordingStateInsideForm = !volatileState && formSupport != null;
}
@@ -217,18 +236,20 @@
void setupForRow(int rowIndex)
{
row = gridModel.getDataSource().getRowValue(rowIndex);
-
}
boolean beginRender()
{
// When needed, store a callback used when the form is submitted.
- if (recordingStateInsideForm) formSupport.store(this, new
SetupForRow(rowIndex));
+ if (recordingStateInsideForm) formSupport.store(this, new
SetupForRow(dataRowIndex));
// And do it now for the render.
- setupForRow(rowIndex);
+ setupForRow(dataRowIndex);
+
+ // Update the index parameter (which starts from zero).
+ rowIndex = dataRowIndex - startRow;
// If the row is null, it's because the rowIndex is too large (see the
notes
// on GridDataSource). When row is null, return false to not render
anything for this iteration
@@ -239,12 +260,12 @@
boolean afterRender()
{
- rowIndex++;
+ dataRowIndex++;
// Abort the loop when we hit a null row, or when we've exhausted the
range we need to
// display.
- return row == null || rowIndex > endRow;
+ return row == null || dataRowIndex > endRow;
}
public List<String> getPropertyNames()
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridColumns.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridColumns.tml?rev=687116&r1=687115&r2=687116&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridColumns.tml
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridColumns.tml
Tue Aug 19 11:07:40 2008
@@ -1,7 +1,7 @@
<thead xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
xml:space="default">
<tr>
<th t:type="Loop" source="columnNames" value="columnName"
volatile="true" class="prop:headerClass"
- index="columnIndex">
+ index="index">
<t:delegate to="blockForColumn"/>
<t:block id="standardHeader">
<a t:id="sort">${columnModel.label}</a>
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml?rev=687116&r1=687115&r2=687116&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml
Tue Aug 19 11:07:40 2008
@@ -1,5 +1,5 @@
<tr class="${rowClass}" xml:space="default"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
- <t:loop source="propertyNames" value="propertyName"
volatile="inherit:volatile">
+ <t:loop source="propertyNames" value="propertyName" index="columnIndex"
volatile="inherit:volatile">
<td class="${cellClass}">
<t:gridcell model="columnModel" object="row"
overrides="overrides"/>
</td>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/LeanGridDemo.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/LeanGridDemo.tml?rev=687116&r1=687115&r2=687116&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/LeanGridDemo.tml
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/LeanGridDemo.tml Tue
Aug 19 11:07:40 2008
@@ -2,10 +2,17 @@
<h1>Lean Grid Demo</h1>
- <table t:id="grid" source="tracks" row="track" lean="true">
+ <table t:id="grid" source="tracks" row="track" rowIndex="rowIndex"
columnIndex="columnIndex" add="indexes"
+ lean="true">
<t:parameter name="ratingcell">
<t:outputRating rating="track.rating"/>
</t:parameter>
+ <t:parameter name="indexesheader">
+ Indexes (${columnIndex})
+ </t:parameter>
+ <t:parameter name="indexescell">
+ ${rowIndex},${columnIndex}
+ </t:parameter>
</table>
</html>
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java?rev=687116&r1=687115&r2=687116&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
Tue Aug 19 11:07:40 2008
@@ -1415,6 +1415,21 @@
// assertText("//th[1]/@class", "");
}
+ /**
+ * TAPESTRY-1310
+ */
+ @Test
+ public void grid_row_and_column_indexes()
+ {
+ start("Lean Grid Demo", "2");
+
+ // Use page 2 to ensure that the row index is the row in the Grid, not
the row index of the data
+
+ assertText("//th[7]", "Indexes (6)");
+ assertText("//tr[1]/td[7]", "0,6");
+ assertText("//tr[2]/td[7]", "1,6");
+ }
+
@Test
public void unless_component()
{
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/LeanGridDemo.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/LeanGridDemo.java?rev=687116&r1=687115&r2=687116&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/LeanGridDemo.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/LeanGridDemo.java
Tue Aug 19 11:07:40 2008
@@ -15,6 +15,13 @@
package org.apache.tapestry5.integration.app1.pages;
+import org.apache.tapestry5.annotations.Property;
+
public class LeanGridDemo extends GridDemo
{
+ @Property
+ private int rowIndex;
+
+ @Property
+ private int columnIndex;
}