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.

TableSortingIndicator.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright 2000-2013 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.components.table;
  17. import java.util.Random;
  18. import com.vaadin.data.Container;
  19. import com.vaadin.data.util.BeanItemContainer;
  20. import com.vaadin.server.VaadinRequest;
  21. import com.vaadin.tests.components.AbstractTestUI;
  22. import com.vaadin.ui.Button;
  23. import com.vaadin.ui.Button.ClickEvent;
  24. import com.vaadin.ui.Button.ClickListener;
  25. import com.vaadin.ui.Table;
  26. /**
  27. * Test if the table sorting indicators update correctly when the table is
  28. * sorted serverside
  29. *
  30. * @author Vaadin Ltd
  31. */
  32. public class TableSortingIndicator extends AbstractTestUI {
  33. /*
  34. * (non-Javadoc)
  35. *
  36. * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
  37. * VaadinRequest)
  38. */
  39. @Override
  40. protected void setup(VaadinRequest request) {
  41. final Table table = new Table("Test table", buildContainer());
  42. table.setSizeFull();
  43. addComponent(table);
  44. Button sortButton = new Button("Sort", new ClickListener() {
  45. @Override
  46. public void buttonClick(ClickEvent event) {
  47. table.sort(new Object[] { "val1" }, new boolean[] { false });
  48. }
  49. });
  50. addComponent(sortButton);
  51. }
  52. private Container buildContainer() {
  53. BeanItemContainer<TestBean> container = new BeanItemContainer<TestBean>(
  54. TestBean.class);
  55. for (int i = 0; i < 100; ++i) {
  56. TestBean item = new TestBean();
  57. item.setVal1(i);
  58. item.setVal2(randomWord());
  59. item.setVal3(randomWord());
  60. container.addBean(item);
  61. }
  62. return container;
  63. }
  64. /*
  65. * (non-Javadoc)
  66. *
  67. * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
  68. */
  69. @Override
  70. protected String getTestDescription() {
  71. return "The table should have visible sorting indicators.";
  72. }
  73. /*
  74. * (non-Javadoc)
  75. *
  76. * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
  77. */
  78. @Override
  79. protected Integer getTicketNumber() {
  80. return 8978;
  81. }
  82. public class TestBean {
  83. private Integer val1;
  84. private String val2;
  85. private String val3;
  86. public Integer getVal1() {
  87. return val1;
  88. }
  89. public void setVal1(Integer val1) {
  90. this.val1 = val1;
  91. }
  92. public String getVal2() {
  93. return val2;
  94. }
  95. public void setVal2(String val2) {
  96. this.val2 = val2;
  97. }
  98. public String getVal3() {
  99. return val3;
  100. }
  101. public void setVal3(String val3) {
  102. this.val3 = val3;
  103. }
  104. }
  105. private String randomWord() {
  106. Random rng = new Random();
  107. char[] word = new char[3 + rng.nextInt(10)];
  108. for (int i = 0; i < word.length; ++i) {
  109. word[i] = (char) ('a' + rng.nextInt(26));
  110. }
  111. return new String(word);
  112. }
  113. }