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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.server.component.table;
  17. import org.junit.Assert;
  18. import org.junit.Test;
  19. import com.vaadin.server.ExternalResource;
  20. import com.vaadin.shared.ui.MultiSelectMode;
  21. import com.vaadin.ui.Table;
  22. import com.vaadin.ui.Table.Align;
  23. import com.vaadin.ui.Table.ColumnHeaderMode;
  24. import com.vaadin.ui.Table.RowHeaderMode;
  25. import com.vaadin.ui.Table.TableDragMode;
  26. /**
  27. * Test declarative support for {@link Table}.
  28. *
  29. * @since
  30. * @author Vaadin Ltd
  31. */
  32. public class TableDeclarativeTest extends TableDeclarativeTestBase {
  33. @Test
  34. public void testBasicAttributes() {
  35. String design = "<" + getTag()
  36. + " page-length=30 cache-rate=3 selectable editable "
  37. + "sortable=false sort-ascending=false sort-container-property-id=foo "
  38. + "drag-mode=row multi-select-mode=simple column-header-mode=id row-header-mode=id "
  39. + "column-reordering-allowed column-collapsing-allowed />";
  40. Table table = getTable();
  41. table.setPageLength(30);
  42. table.setCacheRate(3);
  43. table.setSelectable(true);
  44. table.setEditable(true);
  45. table.setSortEnabled(false);
  46. table.setSortAscending(false);
  47. table.setSortContainerPropertyId("foo");
  48. table.setDragMode(TableDragMode.ROW);
  49. table.setMultiSelectMode(MultiSelectMode.SIMPLE);
  50. table.setColumnHeaderMode(ColumnHeaderMode.ID);
  51. table.setRowHeaderMode(RowHeaderMode.ID);
  52. table.setColumnReorderingAllowed(true);
  53. table.setColumnCollapsingAllowed(true);
  54. testRead(design, table);
  55. testWrite(design, table);
  56. }
  57. @Test
  58. public void testColumns() {
  59. String design = "<" + getTag() + " column-collapsing-allowed>" //
  60. + " <table>" //
  61. + " <colgroup>" + " <col property-id='foo' width=300>"
  62. + " <col property-id='bar' center expand=1 collapsible=false>"
  63. + " <col property-id='baz' right expand=2 collapsed>"
  64. + " </colgroup>" //
  65. + " </table>";
  66. Table table = getTable();
  67. table.setColumnCollapsingAllowed(true);
  68. table.addContainerProperty("foo", String.class, null);
  69. table.setColumnAlignment("foo", Align.LEFT);
  70. table.setColumnWidth("foo", 300);
  71. table.addContainerProperty("bar", String.class, null);
  72. table.setColumnAlignment("bar", Align.CENTER);
  73. table.setColumnExpandRatio("bar", 1);
  74. table.setColumnCollapsible("bar", false);
  75. table.addContainerProperty("baz", String.class, null);
  76. table.setColumnAlignment("baz", Align.RIGHT);
  77. table.setColumnExpandRatio("baz", 2);
  78. table.setColumnCollapsed("baz", true);
  79. testRead(design, table);
  80. testWrite(design, table);
  81. }
  82. @Test
  83. public void testHeadersFooters() {
  84. String design = "<" + getTag() + ">" //
  85. + " <table>" //
  86. + " <colgroup><col property-id=foo><col property-id=bar></colgroup>" //
  87. + " <thead>" //
  88. + " <tr><th icon='http://example.com/icon.png'>FOO<th>BAR" //
  89. + " </thead>" //
  90. + " <tfoot>" //
  91. + " <tr><td>foo<td>bar" //
  92. + " </tfoot>" //
  93. + " </table>";
  94. Table table = getTable();
  95. table.setFooterVisible(true);
  96. table.addContainerProperty("foo", String.class, null);
  97. table.setColumnHeader("foo", "FOO");
  98. table.setColumnIcon("foo",
  99. new ExternalResource("http://example.com/icon.png"));
  100. table.setColumnFooter("foo", "foo");
  101. table.addContainerProperty("bar", String.class, null);
  102. table.setColumnHeader("bar", "BAR");
  103. table.setColumnFooter("bar", "bar");
  104. testRead(design, table);
  105. testWrite(design, table);
  106. }
  107. @Test
  108. public void testInlineData() {
  109. String design = "<" + getTag() + ">" //
  110. + " <table>" //
  111. + " <colgroup>" + " <col property-id='foo' />"
  112. + " <col property-id='bar' />"
  113. + " <col property-id='baz' />" //
  114. + " </colgroup>" + " <thead>"
  115. + " <tr><th>Description<th>Milestone<th>Status</tr>"
  116. + " </thead>" + " <tbody>"
  117. + " <tr item-id=1><td>r1c1</td><td>r1c2</td><td>r1c3</td>" //
  118. + " <tr item-id=2><td>r2c1</td><td>r2c2</td><td>r2c3</td>" //
  119. + " </tbody>" //
  120. + " <tfoot>" //
  121. + " <tr><td>F1<td>F2<td>F3</tr>" //
  122. + " </tfoot>" //
  123. + " </table>";
  124. Table table = getTable();
  125. table.addContainerProperty("foo", String.class, null);
  126. table.addContainerProperty("bar", String.class, null);
  127. table.addContainerProperty("baz", String.class, null);
  128. table.setColumnHeaders("Description", "Milestone", "Status");
  129. table.setColumnFooter("foo", "F1");
  130. table.setColumnFooter("bar", "F2");
  131. table.setColumnFooter("baz", "F3");
  132. table.addItem(new Object[] { "r1c1", "r1c2", "r1c3" }, "1");
  133. table.addItem(new Object[] { "r2c1", "r2c2", "r2c3" }, "2");
  134. table.setFooterVisible(true);
  135. testRead(design, table);
  136. testWrite(design, table, true);
  137. }
  138. @Test
  139. public void testHtmlEntities() {
  140. String design = "<v-table>" + "<table>" + " <colgroup>"
  141. + " <col property-id=\"test\"" + " </colgroup>"
  142. + " <thead>" + " <tr><th>&amp; Test</th></tr>"
  143. + " </thead>" + " <tbody>"
  144. + " <tr item-id=\"test\"><td>&amp; Test</tr>" + " </tbody>"
  145. + " <tfoot>" + " <tr><td>&amp; Test</td></tr>"
  146. + " </tfoot>" + "</table>" + "</v-table>";
  147. Table read = read(design);
  148. Assert.assertEquals("& Test",
  149. read.getContainerProperty("test", "test").getValue());
  150. Assert.assertEquals("& Test", read.getColumnHeader("test"));
  151. Assert.assertEquals("& Test", read.getColumnFooter("test"));
  152. }
  153. }