You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2009/10/14 12:15:03 UTC
svn commit: r825078 - in
/incubator/click/trunk/click/examples/src/org/apache/click/examples:
control/exporter/ExportTable.java page/general/ExcelTableExportPage.java
Author: sabob
Date: Wed Oct 14 10:15:03 2009
New Revision: 825078
URL: http://svn.apache.org/viewvc?rev=825078&view=rev
Log:
columns can now be excluded from view or export
Modified:
incubator/click/trunk/click/examples/src/org/apache/click/examples/control/exporter/ExportTable.java
incubator/click/trunk/click/examples/src/org/apache/click/examples/page/general/ExcelTableExportPage.java
Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/control/exporter/ExportTable.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/control/exporter/ExportTable.java?rev=825078&r1=825077&r2=825078&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/control/exporter/ExportTable.java (original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/control/exporter/ExportTable.java Wed Oct 14 10:15:03 2009
@@ -49,10 +49,12 @@
protected List excludedColumns;
- protected List exportColumnList;
+ protected List excludedExportColumns;
protected TableExportBanner exporter;
+ private List exportColumnList;
+
public ExportTable() {
}
@@ -127,28 +129,33 @@
this.exportBannerPosition = exportBannerPosition;
}
- /**
- * @return the excludedColumns
- */
- public List getExcludedColumns() {
+ public List<String> getExcludedColumns() {
if (excludedColumns == null) {
excludedColumns = new ArrayList();
}
return excludedColumns;
}
- /**
- * @param excludedColumns the excludedColumns to set
- */
- public void setExcludedColumns(List excludedColumns) {
+ public void setExcludedColumns(List<String> excludedColumns) {
this.excludedColumns = excludedColumns;
}
- public List getExportColumnList() {
+ public List<String> getExcludedExportColumns() {
+ if (excludedExportColumns == null) {
+ excludedExportColumns = new ArrayList();
+ }
+ return excludedExportColumns;
+ }
+
+ public void setExcludedExportColumns(List<String> excludedExportColumns) {
+ this.excludedExportColumns = excludedExportColumns;
+ }
+
+ public List getExportColumnList() {
if (exportColumnList == null) {
exportColumnList = new ArrayList();
List<Column> columns = getColumnList();
- List<String> excludes = getExcludedColumns();
+ List<String> excludes = getExcludedExportColumns();
for (Column column : columns) {
String name = column.getName();
@@ -160,6 +167,14 @@
return exportColumnList;
}
+ public int getExportAttachment() {
+ return exportAttachment;
+ }
+
+ public void setExportAttachment(int exportAttachment) {
+ this.exportAttachment = exportAttachment;
+ }
+
@Override
public void onInit() {
super.onInit();
@@ -207,7 +222,7 @@
buffer.append("<tbody>\n");
buffer.append("<tr class=\"export-inline\">\n");
buffer.append("<td class=\"export-inline\" colspan=\"");
- buffer.append(getColumnList().size());
+ buffer.append(getColumnList().size() - getExcludedExportColumns().size());
buffer.append("\">");
getExporter().render(buffer);
@@ -225,7 +240,7 @@
buffer.append("<tbody>\n");
buffer.append("<tr class=\"export-inline\">\n");
buffer.append("<td class=\"export-inline\" colspan=\"");
- buffer.append(getColumnList().size());
+ buffer.append(getColumnList().size() - getExcludedExportColumns().size());
buffer.append("\">");
getExporter().render(buffer);
@@ -236,11 +251,50 @@
}
}
- public int getExportAttachment() {
- return exportAttachment;
+ @Override
+ protected void renderHeaderRow(HtmlStringBuffer buffer) {
+ buffer.append("<thead>\n<tr>\n");
+
+ final List tableColumns = getColumnList();
+ final List excludedColumns = getExcludedColumns();
+
+ for (int j = 0; j < tableColumns.size(); j++) {
+ Column column = (Column) tableColumns.get(j);
+ if (!excludedColumns.contains(column.getName())) {
+ column.renderTableHeader(buffer, getContext());
+ if (j < tableColumns.size() - 1) {
+ buffer.append("\n");
+ }
+ }
+ }
+
+ buffer.append("</tr></thead>\n");
}
- public void setExportAttachment(int exportAttachment) {
- this.exportAttachment = exportAttachment;
+ @Override
+ protected void renderBodyRowColumns(HtmlStringBuffer buffer, int rowIndex) {
+ Object row = getRowList().get(rowIndex);
+
+ final List tableColumns = getColumnList();
+ final List excludedColumns = getExcludedColumns();
+
+ for (int j = 0; j < tableColumns.size(); j++) {
+ Column column = (Column) tableColumns.get(j);
+ if (!excludedColumns.contains(column.getName())) {
+ column.renderTableData(row, buffer, getContext(), rowIndex);
+ if (j < tableColumns.size() - 1) {
+ buffer.append("\n");
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void renderBodyNoRows(HtmlStringBuffer buffer) {
+ buffer.append("<tr class=\"odd\"><td colspan=\"");
+ buffer.append(getColumns().size() - getExcludedColumns().size());
+ buffer.append("\" class=\"error\">");
+ buffer.append(getMessage("table-no-rows-found"));
+ buffer.append("</td></tr>\n");
}
}
Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/general/ExcelTableExportPage.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/general/ExcelTableExportPage.java?rev=825078&r1=825077&r2=825078&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/general/ExcelTableExportPage.java (original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/general/ExcelTableExportPage.java Wed Oct 14 10:15:03 2009
@@ -44,6 +44,8 @@
@Component
public class ExcelTableExportPage extends BorderPage {
+ private static final String ACTION_COLUMN = "action";
+
private ExportTable table1 = new ExportTable("table1");
private ExportTable table2 = new ExportTable("table2");
private ExportTable table3 = new ExportTable("table3");
@@ -95,8 +97,9 @@
ExcelTableExporter excel = new ExcelTableExporter("Excel", "/assets/images/page_excel.png");
table.getExporter().add(excel);
- // Exclude the action column from being exported
- table.getExcludedColumns().add("action");
+ // Excluding the action column ensures the actions are not exported to
+ // Excel
+ table.getExcludedExportColumns().add(ACTION_COLUMN);
}
private void addColumns(ExportTable table) {
@@ -108,32 +111,36 @@
table.setPaginator(new TableInlinePaginator(table));
table.setPaginatorAttachment(ExportTable.PAGINATOR_INLINE);
- Column column = new Column("name");
+ Column column = new Column(Customer.NAME_PROPERTY);
column.setWidth("140px;");
table.addColumn(column);
- column = new Column("email");
+ column = new Column(Customer.EMAIL_PROPERTY);
column.setAutolink(true);
column.setWidth("230px;");
table.addColumn(column);
- column = new Column("age");
+ column = new Column(Customer.AGE_PROPERTY);
column.setTextAlign("center");
column.setWidth("40px;");
table.addColumn(column);
- column = new Column("holdings");
+ column = new Column(Customer.HOLDINGS_PROPERTY);
column.setFormat("{0,number,currency}");
column.setTextAlign("right");
column.setWidth("100px;");
table.addColumn(column);
- column = new Column("dateJoined");
+ column = new Column(Customer.DATE_JOINED_PROPERTY);
column.setFormat("{0,date,medium}");
column.setWidth("100px;");
table.addColumn(column);
- column = new Column("action");
+ // Excluding the dateJoined column ensures the date is not shown in the
+ // HTML table, but will be exported to the Excel spreadsheet
+ table.getExcludedColumns().add(Customer.DATE_JOINED_PROPERTY);
+
+ column = new Column(ACTION_COLUMN);
AbstractLink[] links = new AbstractLink[] { editLink };
editLink.setParameter("referrer", "/general/excel-table-export.htm");
column.setDecorator(new LinkDecorator(table, links, "id"));