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.

ExpandingContainerVisibleRowRaceCondition.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.vaadin.tests.components.table;
  2. import java.util.Map;
  3. import com.vaadin.server.VaadinRequest;
  4. import com.vaadin.ui.Label;
  5. import com.vaadin.ui.Table;
  6. import com.vaadin.ui.UI;
  7. import com.vaadin.ui.VerticalLayout;
  8. @SuppressWarnings("serial")
  9. public class ExpandingContainerVisibleRowRaceCondition extends UI {
  10. static final String TABLE = "table";
  11. @Override
  12. public void init(VaadinRequest request) {
  13. final VerticalLayout rootLayout = new VerticalLayout();
  14. rootLayout.setSpacing(true);
  15. rootLayout.setSizeFull();
  16. rootLayout.setMargin(true);
  17. final Label sizeLabel = new Label();
  18. final ExpandingContainer container = new ExpandingContainer(sizeLabel);
  19. container.logDetails(false);
  20. Table table = new Table(null, container) {
  21. @Override
  22. public void changeVariables(Object source,
  23. Map<String, Object> variables) {
  24. if (variables.containsKey("firstvisible")) {
  25. int index = (Integer) variables.get("firstvisible");
  26. container.checkExpand(index);
  27. }
  28. if (variables.containsKey("reqfirstrow")
  29. || variables.containsKey("reqrows")) {
  30. try {
  31. int index = ((Integer) variables
  32. .get("lastToBeRendered")).intValue();
  33. container.checkExpand(index);
  34. } catch (Exception e) {
  35. // do nothing
  36. }
  37. }
  38. super.changeVariables(source, variables);
  39. }
  40. };
  41. table.setId(TABLE);
  42. table.setCacheRate(0);
  43. table.setSizeFull();
  44. table.setVisibleColumns(ExpandingContainer.PROPERTY_IDS
  45. .toArray(new String[ExpandingContainer.PROPERTY_IDS.size()]));
  46. table.setCurrentPageFirstItemIndex(120);
  47. rootLayout.addComponent(table);
  48. rootLayout.setExpandRatio(table, 1);
  49. rootLayout.addComponent(sizeLabel);
  50. setContent(rootLayout);
  51. container.checkExpand(300);
  52. }
  53. }