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.

SetPageFirstItemLoadsNeededRowsOnly.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.components.table;
  17. import java.io.Serializable;
  18. import java.util.List;
  19. import com.vaadin.data.util.BeanContainer;
  20. import com.vaadin.server.VaadinRequest;
  21. import com.vaadin.tests.components.AbstractTestUI;
  22. import com.vaadin.ui.Label;
  23. import com.vaadin.ui.Table;
  24. import com.vaadin.ui.VerticalLayout;
  25. /**
  26. *
  27. * @author Vaadin Ltd
  28. */
  29. @SuppressWarnings("serial")
  30. public class SetPageFirstItemLoadsNeededRowsOnly extends AbstractTestUI {
  31. /*
  32. * (non-Javadoc)
  33. *
  34. * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
  35. * VaadinRequest)
  36. */
  37. @Override
  38. protected void setup(VaadinRequest request) {
  39. final VerticalLayout layout = new VerticalLayout();
  40. addComponent(layout);
  41. final Label label = new Label("");
  42. addComponent(label);
  43. BeanContainer<String, Bean> beans = new BeanContainer<String, Bean>(
  44. Bean.class) {
  45. @Override
  46. public List<String> getItemIds(int startIndex, int numberOfIds) {
  47. label.setValue("rows requested: " + numberOfIds);
  48. return super.getItemIds(startIndex, numberOfIds);
  49. }
  50. };
  51. beans.setBeanIdProperty("i");
  52. for (int i = 0; i < 2000; i++) {
  53. beans.addBean(new Bean(i));
  54. }
  55. final Table table = new Table("Beans", beans);
  56. table.setVisibleColumns(new Object[] { "i" });
  57. layout.addComponent(table);
  58. table.setCurrentPageFirstItemIndex(table.size() - 1);
  59. }
  60. /*
  61. * (non-Javadoc)
  62. *
  63. * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
  64. */
  65. @Override
  66. protected String getTestDescription() {
  67. return "Only cached rows and rows in viewport should be rendered after "
  68. + "calling table.setCurrentPageFirstItemIndex(n) - as opposed to all rows "
  69. + "between the previous position and new position";
  70. }
  71. /*
  72. * (non-Javadoc)
  73. *
  74. * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
  75. */
  76. @Override
  77. protected Integer getTicketNumber() {
  78. return 14135;
  79. }
  80. public class Bean implements Serializable {
  81. private Integer i;
  82. public Bean(Integer i) {
  83. this.i = i;
  84. }
  85. public Integer getI() {
  86. return i;
  87. }
  88. public void setI(Integer i) {
  89. this.i = i;
  90. }
  91. }
  92. }