You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TableDeclarativeTest.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package com.vaadin.v7.tests.server.component.table;
  2. import org.junit.Test;
  3. import com.vaadin.server.ExternalResource;
  4. import com.vaadin.shared.ui.MultiSelectMode;
  5. import com.vaadin.v7.ui.Table;
  6. import com.vaadin.v7.ui.Table.Align;
  7. import com.vaadin.v7.ui.Table.ColumnHeaderMode;
  8. import com.vaadin.v7.ui.Table.RowHeaderMode;
  9. import com.vaadin.v7.ui.Table.TableDragMode;
  10. /**
  11. * Test declarative support for {@link Table}.
  12. *
  13. * @since
  14. * @author Vaadin Ltd
  15. */
  16. public class TableDeclarativeTest extends TableDeclarativeTestBase {
  17. @Test
  18. public void testBasicAttributes() {
  19. String design = "<" + getTag()
  20. + " page-length=30 cache-rate=3 selectable editable "
  21. + "sortable=false sort-ascending=false sort-container-property-id=foo "
  22. + "drag-mode=row multi-select-mode=simple column-header-mode=id row-header-mode=id "
  23. + "column-reordering-allowed column-collapsing-allowed />";
  24. Table table = getTable();
  25. table.setPageLength(30);
  26. table.setCacheRate(3);
  27. table.setSelectable(true);
  28. table.setEditable(true);
  29. table.setSortEnabled(false);
  30. table.setSortAscending(false);
  31. table.setSortContainerPropertyId("foo");
  32. table.setDragMode(TableDragMode.ROW);
  33. table.setMultiSelectMode(MultiSelectMode.SIMPLE);
  34. table.setColumnHeaderMode(ColumnHeaderMode.ID);
  35. table.setRowHeaderMode(RowHeaderMode.ID);
  36. table.setColumnReorderingAllowed(true);
  37. table.setColumnCollapsingAllowed(true);
  38. testRead(design, table);
  39. testWrite(design, table);
  40. }
  41. @Test
  42. public void testColumns() {
  43. String design = "<" + getTag() + " column-collapsing-allowed>" //
  44. + " <table>" //
  45. + " <colgroup>" + " <col property-id='foo' width=300>"
  46. + " <col property-id='bar' center expand=1 collapsible=false>"
  47. + " <col property-id='baz' right expand=2 collapsed>"
  48. + " </colgroup>" //
  49. + " </table>";
  50. Table table = getTable();
  51. table.setColumnCollapsingAllowed(true);
  52. table.addContainerProperty("foo", String.class, null);
  53. table.setColumnAlignment("foo", Align.LEFT);
  54. table.setColumnWidth("foo", 300);
  55. table.addContainerProperty("bar", String.class, null);
  56. table.setColumnAlignment("bar", Align.CENTER);
  57. table.setColumnExpandRatio("bar", 1);
  58. table.setColumnCollapsible("bar", false);
  59. table.addContainerProperty("baz", String.class, null);
  60. table.setColumnAlignment("baz", Align.RIGHT);
  61. table.setColumnExpandRatio("baz", 2);
  62. table.setColumnCollapsed("baz", true);
  63. testRead(design, table);
  64. testWrite(design, table);
  65. }
  66. @Test
  67. public void testHeadersFooters() {
  68. String design = "<" + getTag() + ">" //
  69. + " <table>" //
  70. + " <colgroup><col property-id=foo><col property-id=bar></colgroup>" //
  71. + " <thead>" //
  72. + " <tr><th icon='http://example.com/icon.png'>FOO<th>BAR" //
  73. + " </thead>" //
  74. + " <tfoot>" //
  75. + " <tr><td>foo<td>bar" //
  76. + " </tfoot>" //
  77. + " </table>";
  78. Table table = getTable();
  79. table.setFooterVisible(true);
  80. table.addContainerProperty("foo", String.class, null);
  81. table.setColumnHeader("foo", "FOO");
  82. table.setColumnIcon("foo",
  83. new ExternalResource("http://example.com/icon.png"));
  84. table.setColumnFooter("foo", "foo");
  85. table.addContainerProperty("bar", String.class, null);
  86. table.setColumnHeader("bar", "BAR");
  87. table.setColumnFooter("bar", "bar");
  88. testRead(design, table);
  89. testWrite(design, table);
  90. }
  91. @Test
  92. public void testInlineData() {
  93. String design = "<" + getTag() + ">" //
  94. + " <table>" //
  95. + " <colgroup>" + " <col property-id='foo' />"
  96. + " <col property-id='bar' />"
  97. + " <col property-id='baz' />" //
  98. + " </colgroup>" + " <thead>"
  99. + " <tr><th>Description<th>Milestone<th>Status</tr>"
  100. + " </thead>" + " <tbody>"
  101. + " <tr item-id=1><td>r1c1</td><td>r1c2</td><td>r1c3</td>" //
  102. + " <tr item-id=2><td>r2c1</td><td>r2c2</td><td>r2c3</td>" //
  103. + " </tbody>" //
  104. + " <tfoot>" //
  105. + " <tr><td>F1<td>F2<td>F3</tr>" //
  106. + " </tfoot>" //
  107. + " </table>";
  108. Table table = getTable();
  109. table.addContainerProperty("foo", String.class, null);
  110. table.addContainerProperty("bar", String.class, null);
  111. table.addContainerProperty("baz", String.class, null);
  112. table.setColumnHeaders("Description", "Milestone", "Status");
  113. table.setColumnFooter("foo", "F1");
  114. table.setColumnFooter("bar", "F2");
  115. table.setColumnFooter("baz", "F3");
  116. table.addItem(new Object[] { "r1c1", "r1c2", "r1c3" }, "1");
  117. table.addItem(new Object[] { "r2c1", "r2c2", "r2c3" }, "2");
  118. table.setFooterVisible(true);
  119. testRead(design, table);
  120. testWrite(design, table, true);
  121. }
  122. @Test
  123. public void testHtmlEntities() {
  124. String design = "<vaadin7-table>" + "<table>" + " <colgroup>"
  125. + " <col property-id=\"test\"" + " </colgroup>"
  126. + " <thead>" + " <tr><th>&amp; Test</th></tr>"
  127. + " </thead>" + " <tbody>"
  128. + " <tr item-id=\"test\"><td>&amp; Test</tr>" + " </tbody>"
  129. + " <tfoot>" + " <tr><td>&amp; Test</td></tr>"
  130. + " </tfoot>" + "</table>" + "</vaadin7-table>";
  131. Table read = read(design);
  132. assertEquals("& Test",
  133. read.getContainerProperty("test", "test").getValue());
  134. assertEquals("& Test", read.getColumnHeader("test"));
  135. assertEquals("& Test", read.getColumnFooter("test"));
  136. }
  137. }