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.

RefreshRenderedCellsOnlyIfAttached.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 com.vaadin.server.VaadinRequest;
  18. import com.vaadin.tests.components.AbstractTestUI;
  19. import com.vaadin.ui.Button;
  20. import com.vaadin.ui.Button.ClickEvent;
  21. import com.vaadin.ui.Label;
  22. import com.vaadin.ui.Table;
  23. import com.vaadin.ui.VerticalLayout;
  24. /**
  25. * There shouldn't be any attempts to refresh table's cells if the table isn't
  26. * attached.
  27. *
  28. * @since
  29. * @author Vaadin Ltd
  30. */
  31. public class RefreshRenderedCellsOnlyIfAttached extends AbstractTestUI {
  32. VerticalLayout layout;
  33. boolean check;
  34. /*
  35. * (non-Javadoc)
  36. *
  37. * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
  38. * VaadinRequest)
  39. */
  40. @Override
  41. protected void setup(VaadinRequest request) {
  42. getLayout().setMargin(true);
  43. check = false;
  44. layout = new VerticalLayout();
  45. final Label l1 = new Label("default");
  46. l1.setId("label");
  47. final Label l2 = new Label("should be: default");
  48. final Table t = new Table() {
  49. /*
  50. * (non-Javadoc)
  51. *
  52. * @see com.vaadin.ui.Table#refreshRenderedCells()
  53. */
  54. @Override
  55. protected void refreshRenderedCells() {
  56. boolean original = isRowCacheInvalidated();
  57. super.refreshRenderedCells();
  58. if (check) {
  59. l1.setValue("original: " + original + ", now: "
  60. + isRowCacheInvalidated());
  61. l2.setValue("should be: false & false");
  62. }
  63. }
  64. };
  65. t.addContainerProperty("text", String.class, "");
  66. t.addItem(new Object[] { "Foo" }, "foo");
  67. t.setId("table");
  68. layout.addComponent(t);
  69. addComponent(l1);
  70. addComponent(l2);
  71. addComponent(layout);
  72. Button b = new Button("Detach table", new Button.ClickListener() {
  73. @Override
  74. public void buttonClick(ClickEvent event) {
  75. check = true;
  76. removeTableParent();
  77. // call refreshRenderedCells
  78. t.setColumnCollapsingAllowed(true);
  79. }
  80. });
  81. b.setId("button");
  82. addComponent(b);
  83. }
  84. /**
  85. * Remove Table's parent component.
  86. *
  87. * @since
  88. */
  89. protected void removeTableParent() {
  90. removeComponent(layout);
  91. }
  92. /*
  93. * (non-Javadoc)
  94. *
  95. * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
  96. */
  97. @Override
  98. protected String getTestDescription() {
  99. return "There shouldn't be any attempts to refresh table's cells if the table isn't attached.";
  100. }
  101. /*
  102. * (non-Javadoc)
  103. *
  104. * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
  105. */
  106. @Override
  107. protected Integer getTicketNumber() {
  108. return 9138;
  109. }
  110. }