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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright 2000-2014 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.Test;
  18. import com.vaadin.server.ExternalResource;
  19. import com.vaadin.shared.ui.MultiSelectMode;
  20. import com.vaadin.ui.Table;
  21. import com.vaadin.ui.Table.Align;
  22. import com.vaadin.ui.Table.ColumnHeaderMode;
  23. import com.vaadin.ui.Table.RowHeaderMode;
  24. import com.vaadin.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 = "<"
  35. + 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 = "<"
  60. + getTag()
  61. + " column-collapsing-allowed=''>" //
  62. + " <table>" //
  63. + " <colgroup>"
  64. + " <col property-id='foo' width=300>"
  65. + " <col property-id='bar' center expand=1 collapsible=false>"
  66. + " <col property-id='baz' right expand=2 collapsed=''>"
  67. + " </colgroup>" //
  68. + " </table>";
  69. Table table = getTable();
  70. table.setColumnCollapsingAllowed(true);
  71. table.addContainerProperty("foo", String.class, null);
  72. table.setColumnAlignment("foo", Align.LEFT);
  73. table.setColumnWidth("foo", 300);
  74. table.addContainerProperty("bar", String.class, null);
  75. table.setColumnAlignment("bar", Align.CENTER);
  76. table.setColumnExpandRatio("bar", 1);
  77. table.setColumnCollapsible("bar", false);
  78. table.addContainerProperty("baz", String.class, null);
  79. table.setColumnAlignment("baz", Align.RIGHT);
  80. table.setColumnExpandRatio("baz", 2);
  81. table.setColumnCollapsed("baz", true);
  82. testRead(design, table);
  83. testWrite(design, table);
  84. }
  85. @Test
  86. public void testHeadersFooters() {
  87. String design = "<" + getTag()
  88. + ">" //
  89. + " <table>" //
  90. + " <colgroup><col property-id=foo><col property-id=bar></colgroup>" //
  91. + " <thead>" //
  92. + " <tr><th icon='http://example.com/icon.png'>FOO<th>BAR" //
  93. + " </thead>" //
  94. + " <tfoot>" //
  95. + " <tr><td>foo<td>bar" //
  96. + " </tfoot>" //
  97. + " </table>";
  98. Table table = getTable();
  99. table.setFooterVisible(true);
  100. table.addContainerProperty("foo", String.class, null);
  101. table.setColumnHeader("foo", "FOO");
  102. table.setColumnIcon("foo", new ExternalResource(
  103. "http://example.com/icon.png"));
  104. table.setColumnFooter("foo", "foo");
  105. table.addContainerProperty("bar", String.class, null);
  106. table.setColumnHeader("bar", "BAR");
  107. table.setColumnFooter("bar", "bar");
  108. testRead(design, table);
  109. testWrite(design, table);
  110. }
  111. @Test
  112. public void testInlineData() {
  113. String design = "<"
  114. + getTag()
  115. + ">" //
  116. + " <table>" //
  117. + " <colgroup>"
  118. + " <col property-id='foo' />"
  119. + " <col property-id='bar' />"
  120. + " <col property-id='baz' />" //
  121. + " </colgroup>" + " <thead>"
  122. + " <tr><th>Description<th>Milestone<th>Status</tr>"
  123. + " </thead>" + " <tbody>"
  124. + " <tr item-id=1><td>r1c1</td><td>r1c2</td><td>r1c3</td>" //
  125. + " <tr item-id=2><td>r2c1</td><td>r2c2</td><td>r2c3</td>" //
  126. + " </tbody>" //
  127. + " <tfoot>" //
  128. + " <tr><td>F1<td>F2<td>F3</tr>" //
  129. + " </tfoot>" //
  130. + " </table>";
  131. Table table = getTable();
  132. table.addContainerProperty("foo", String.class, null);
  133. table.addContainerProperty("bar", String.class, null);
  134. table.addContainerProperty("baz", String.class, null);
  135. table.setColumnHeaders("Description", "Milestone", "Status");
  136. table.setColumnFooter("foo", "F1");
  137. table.setColumnFooter("bar", "F2");
  138. table.setColumnFooter("baz", "F3");
  139. table.addItem(new Object[] { "r1c1", "r1c2", "r1c3" }, "1");
  140. table.addItem(new Object[] { "r2c1", "r2c2", "r2c3" }, "2");
  141. table.setFooterVisible(true);
  142. testRead(design, table);
  143. testWrite(design, table, true);
  144. }
  145. }