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

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