Change-Id: I9caa766be3152b35f7fe354b989e8cd6d615a043tags/7.5.0.beta1
@@ -6174,6 +6174,108 @@ public class Table extends AbstractSelect implements Action.Container, | |||
} | |||
} | |||
@Override | |||
public void writeDesign(Element design, DesignContext context) { | |||
Table def = context.getDefaultInstance(this); | |||
DesignAttributeHandler.writeAttribute("sortable", design.attributes(), | |||
isSortEnabled(), def.isSortEnabled(), boolean.class); | |||
Element table = null; | |||
boolean hasColumns = getVisibleColumns().length != 0; | |||
if (hasColumns) { | |||
table = design.appendElement("table"); | |||
writeColumns(table, def); | |||
writeHeader(table, def); | |||
} | |||
super.writeDesign(design, context); | |||
if (hasColumns) { | |||
writeFooter(table); | |||
} | |||
} | |||
private void writeColumns(Element table, Table def) { | |||
Object[] columns = getVisibleColumns(); | |||
if (columns.length == 0) { | |||
return; | |||
} | |||
Element colgroup = table.appendElement("colgroup"); | |||
for (Object id : columns) { | |||
Element col = colgroup.appendElement("col"); | |||
col.attr("property-id", id.toString()); | |||
if (getColumnAlignment(id) == Align.CENTER) { | |||
col.attr("center", ""); | |||
} else if (getColumnAlignment(id) == Align.RIGHT) { | |||
col.attr("right", ""); | |||
} | |||
DesignAttributeHandler.writeAttribute("width", col.attributes(), | |||
getColumnWidth(id), def.getColumnWidth(null), int.class); | |||
DesignAttributeHandler.writeAttribute("expand", col.attributes(), | |||
getColumnExpandRatio(id), def.getColumnExpandRatio(null), | |||
float.class); | |||
DesignAttributeHandler.writeAttribute("collapsible", | |||
col.attributes(), isColumnCollapsible(id), | |||
def.isColumnCollapsible(null), boolean.class); | |||
DesignAttributeHandler.writeAttribute("collapsed", | |||
col.attributes(), isColumnCollapsed(id), | |||
def.isColumnCollapsed(null), boolean.class); | |||
} | |||
} | |||
private void writeHeader(Element table, Table def) { | |||
Object[] columns = getVisibleColumns(); | |||
if (columns.length == 0 | |||
|| (columnIcons.isEmpty() && columnHeaders.isEmpty())) { | |||
return; | |||
} | |||
Element header = table.appendElement("thead").appendElement("tr"); | |||
for (Object id : columns) { | |||
Element th = header.appendElement("th"); | |||
th.html(getColumnHeader(id)); | |||
DesignAttributeHandler.writeAttribute("icon", th.attributes(), | |||
getColumnIcon(id), def.getColumnIcon(null), Resource.class); | |||
} | |||
} | |||
private void writeFooter(Element table) { | |||
Object[] columns = getVisibleColumns(); | |||
if (columns.length == 0 || columnFooters.isEmpty()) { | |||
return; | |||
} | |||
Element footer = table.appendElement("tfoot").appendElement("tr"); | |||
for (Object id : columns) { | |||
footer.appendElement("td").text(getColumnFooter(id)); | |||
} | |||
} | |||
@Override | |||
protected void writeItems(Element design, DesignContext context) { | |||
Element tbody = design.child(0).appendElement("tbody"); | |||
super.writeItems(tbody, context); | |||
} | |||
@Override | |||
protected Element writeItem(Element tbody, Object itemId, | |||
DesignContext context) { | |||
Element tr = tbody.appendElement("tr"); | |||
Item item = getItem(itemId); | |||
for (Object id : getVisibleColumns()) { | |||
Element td = tr.appendElement("td"); | |||
td.html(item.getItemProperty(id).getValue().toString()); | |||
} | |||
return tr; | |||
} | |||
@Override | |||
protected Collection<String> getCustomAttributes() { | |||
Collection<String> result = super.getCustomAttributes(); | |||
@@ -6181,6 +6283,7 @@ public class Table extends AbstractSelect implements Action.Container, | |||
result.add("sort-enabled"); | |||
result.add("sort-disabled"); | |||
result.add("footer-visible"); | |||
result.add("item-caption-mode"); | |||
result.add("current-page-first-item-id"); | |||
result.add("current-page-first-item-index"); | |||
return result; |
@@ -94,7 +94,7 @@ public abstract class DeclarativeTestBaseBase<T extends Component> { | |||
Assert.assertEquals(message + ": array length", a1.length, | |||
a2.length); | |||
for (int i = 0; i < a1.length; i++) { | |||
assertEquals(message, a1[i], a2[i]); | |||
assertEquals(message + ": element " + i, a1[i], a2[i]); | |||
} | |||
return; | |||
} |
@@ -15,8 +15,6 @@ | |||
*/ | |||
package com.vaadin.tests.server.component.table; | |||
import java.io.UnsupportedEncodingException; | |||
import org.junit.Test; | |||
import com.vaadin.server.ExternalResource; | |||
@@ -38,28 +36,31 @@ public class TableDeclarativeTest extends TableDeclarativeTestBase { | |||
@Test | |||
public void testBasicAttributes() { | |||
String design = "<v-table page-length=30 cache-rate=3 selectable editable sortable=false " | |||
+ "drag-mode=row multi-select-mode=simple column-header-mode=id " | |||
+ "column-reordering-allowed column-collapsing-allowed sort-ascending=false " | |||
+ "row-header-mode=id sort-container-property-id=foo />"; | |||
String design = "<v-table page-length=30 cache-rate=3 selectable=true editable=true " | |||
+ "sortable=false sort-ascending=false sort-container-property-id=foo " | |||
+ "drag-mode=row multi-select-mode=simple column-header-mode=id row-header-mode=id " | |||
+ "column-reordering-allowed=true column-collapsing-allowed=true />"; | |||
Table table = new Table(); | |||
table.setPageLength(30); | |||
table.setCacheRate(3); | |||
table.setSelectable(true); | |||
table.setEditable(true); | |||
table.setSortEnabled(false); | |||
table.setSortAscending(false); | |||
table.setSortContainerPropertyId("foo"); | |||
table.setDragMode(TableDragMode.ROW); | |||
table.setMultiSelectMode(MultiSelectMode.SIMPLE); | |||
table.setColumnHeaderMode(ColumnHeaderMode.ID); | |||
table.setRowHeaderMode(RowHeaderMode.ID); | |||
table.setColumnReorderingAllowed(true); | |||
table.setColumnCollapsingAllowed(true); | |||
table.setSortAscending(false); | |||
table.setSortContainerPropertyId("foo"); | |||
testRead(design, table); | |||
// testWrite(design, table); | |||
testWrite(design, table); | |||
} | |||
@Test | |||
@@ -67,7 +68,7 @@ public class TableDeclarativeTest extends TableDeclarativeTestBase { | |||
String design = "<v-table column-collapsing-allowed=true>" // | |||
+ " <table>" // | |||
+ " <colgroup>" | |||
+ " <col property-id='foo'>" | |||
+ " <col property-id='foo' width=300>" | |||
+ " <col property-id='bar' center expand=1 collapsible=false>" | |||
+ " <col property-id='baz' right expand=2 collapsed=true>" | |||
+ " </colgroup>" // | |||
@@ -79,7 +80,7 @@ public class TableDeclarativeTest extends TableDeclarativeTestBase { | |||
table.addContainerProperty("foo", String.class, null); | |||
table.setColumnAlignment("foo", Align.LEFT); | |||
table.setColumnExpandRatio("foo", 0); | |||
table.setColumnWidth("foo", 300); | |||
table.addContainerProperty("bar", String.class, null); | |||
table.setColumnAlignment("bar", Align.CENTER); | |||
@@ -92,7 +93,7 @@ public class TableDeclarativeTest extends TableDeclarativeTestBase { | |||
table.setColumnCollapsed("baz", true); | |||
testRead(design, table); | |||
// testWrite(design, table); | |||
testWrite(design, table); | |||
} | |||
@Test | |||
@@ -123,15 +124,15 @@ public class TableDeclarativeTest extends TableDeclarativeTestBase { | |||
table.setColumnFooter("bar", "bar"); | |||
testRead(design, table); | |||
// testWrite(design, table); | |||
testWrite(design, table); | |||
} | |||
@Test | |||
public void testInlineData() throws UnsupportedEncodingException { | |||
String design = "<v-table footer-visible=true> "// | |||
public void testInlineData() { | |||
String design = "<v-table> "// | |||
+ " <table>" // | |||
+ " <colgroup>" | |||
+ " <col property-id='foo' width=150 />" | |||
+ " <col property-id='foo' />" | |||
+ " <col property-id='bar' />" | |||
+ " <col property-id='baz' />" // | |||
+ " </colgroup>" | |||
@@ -147,6 +148,7 @@ public class TableDeclarativeTest extends TableDeclarativeTestBase { | |||
+ " </tfoot>" // | |||
+ " </table>" // | |||
+ "</v-table>"; | |||
Table table = new Table(); | |||
table.addContainerProperty("foo", String.class, null); | |||
table.addContainerProperty("bar", String.class, null); | |||
@@ -158,8 +160,8 @@ public class TableDeclarativeTest extends TableDeclarativeTestBase { | |||
table.addItem(new Object[] { "r1c1", "r1c2", "r1c3" }, null); | |||
table.addItem(new Object[] { "r2c1", "r2c2", "r2c3" }, null); | |||
table.setFooterVisible(true); | |||
testRead(design, table); | |||
// testWrite(design, table); | |||
testRead(design, table); | |||
testWrite(design, table, true); | |||
} | |||
} |
@@ -25,7 +25,7 @@ public class TableDeclarativeTestBase extends DeclarativeTestBase<Table> { | |||
@Override | |||
public Table testRead(String design, Table expected) { | |||
Table read = super.testRead(design, expected); | |||
compareFooter(read, expected); | |||
compareColumns(read, expected); | |||
compareBody(read, expected); | |||
return read; | |||
} | |||
@@ -43,9 +43,20 @@ public class TableDeclarativeTestBase extends DeclarativeTestBase<Table> { | |||
} | |||
} | |||
private void compareFooter(Table read, Table expected) { | |||
private void compareColumns(Table read, Table expected) { | |||
for (Object pid : expected.getVisibleColumns()) { | |||
assertEquals(expected.getColumnFooter(pid), | |||
String col = "column '" + pid + "'"; | |||
assertEquals(col + " width", expected.getColumnWidth(pid), | |||
read.getColumnWidth(pid)); | |||
assertEquals(col + " expand ratio", | |||
expected.getColumnExpandRatio(pid), | |||
read.getColumnExpandRatio(pid)); | |||
assertEquals(col + " collapsible", | |||
expected.isColumnCollapsible(pid), | |||
read.isColumnCollapsible(pid)); | |||
assertEquals(col + " collapsed", expected.isColumnCollapsed(pid), | |||
read.isColumnCollapsed(pid)); | |||
assertEquals(col + " footer", expected.getColumnFooter(pid), | |||
read.getColumnFooter(pid)); | |||
} | |||
} |