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.

TestCurrentPageFirstItem.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.tests.components.TestBase;
  3. import com.vaadin.ui.Button;
  4. import com.vaadin.ui.Button.ClickEvent;
  5. import com.vaadin.ui.Button.ClickListener;
  6. import com.vaadin.ui.HorizontalLayout;
  7. import com.vaadin.v7.data.Container;
  8. import com.vaadin.v7.data.Item;
  9. import com.vaadin.v7.data.util.IndexedContainer;
  10. import com.vaadin.v7.ui.Table;
  11. public class TestCurrentPageFirstItem extends TestBase
  12. implements ClickListener {
  13. private Button buttonIndex;
  14. private Button buttonItem;
  15. private Table[] tables = new Table[4];
  16. private int counter = 0;
  17. IndexedContainer container = new IndexedContainer();
  18. @Override
  19. public void setup() {
  20. container.addContainerProperty("row", String.class, "");
  21. HorizontalLayout baseLayout = new HorizontalLayout();
  22. baseLayout.setHeight("115px");
  23. getMainWindow().setContent(baseLayout);
  24. for (int i = 0; i < tables.length; ++i) {
  25. Table t = new Table();
  26. t.setContainerDataSource(container);
  27. t.setWidth("100px");
  28. baseLayout.addComponent(t);
  29. tables[i] = t;
  30. }
  31. tables[0].setSizeFull();
  32. tables[0].setCaption("Full");
  33. tables[1].setHeight("100px");
  34. tables[1].setCaption("100px");
  35. tables[2].setHeight("95%");
  36. tables[2].setCaption("95%");
  37. tables[3].setPageLength(3);
  38. tables[3].setCaption("3 rows");
  39. buttonIndex = new Button("Add row and select last index", this);
  40. buttonItem = new Button("Add row and select last item", this);
  41. baseLayout.addComponent(buttonIndex);
  42. baseLayout.addComponent(buttonItem);
  43. }
  44. @Override
  45. public void buttonClick(ClickEvent event) {
  46. Item item = container.addItem(++counter);
  47. item.getItemProperty("row").setValue(counter + "");
  48. for (int i = 0; i < tables.length; ++i) {
  49. Table t = tables[i];
  50. t.select(counter);
  51. if (event.getButton() == buttonIndex) {
  52. t.setCurrentPageFirstItemIndex(
  53. ((Container.Indexed) t.getContainerDataSource())
  54. .indexOfId(counter));
  55. } else {
  56. t.setCurrentPageFirstItemId(counter);
  57. }
  58. }
  59. }
  60. @Override
  61. protected String getDescription() {
  62. return "Table height changes when using setCurrentPageFirstItemId";
  63. }
  64. @Override
  65. protected Integer getTicketNumber() {
  66. return 2864;
  67. }
  68. }