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.

MissingHierarchyDetection.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2000-2016 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.application;
  17. import com.vaadin.server.VaadinRequest;
  18. import com.vaadin.tests.components.AbstractReindeerTestUIWithLog;
  19. import com.vaadin.ui.Button;
  20. import com.vaadin.ui.Button.ClickEvent;
  21. import com.vaadin.ui.Component;
  22. import com.vaadin.ui.CssLayout;
  23. import com.vaadin.ui.Label;
  24. import com.vaadin.ui.SelectiveRenderer;
  25. public class MissingHierarchyDetection extends AbstractReindeerTestUIWithLog {
  26. private boolean isChildRendered = true;
  27. private BrokenCssLayout brokenLayout = new BrokenCssLayout();
  28. private CssLayout normalLayout = new CssLayout(
  29. new Label("Normal layout child"));
  30. public class BrokenCssLayout extends CssLayout
  31. implements SelectiveRenderer {
  32. public BrokenCssLayout() {
  33. setCaption("Broken layout");
  34. Label label = new Label("Child component");
  35. label.setId("label");
  36. addComponent(label);
  37. }
  38. @Override
  39. public boolean isRendered(Component childComponent) {
  40. return isChildRendered;
  41. }
  42. }
  43. @Override
  44. protected void setup(VaadinRequest request) {
  45. addComponent(brokenLayout);
  46. addComponent(normalLayout);
  47. addComponent(new Button("Toggle properly", new Button.ClickListener() {
  48. @Override
  49. public void buttonClick(ClickEvent event) {
  50. toggle(true);
  51. }
  52. }));
  53. addComponent(
  54. new Button("Toggle improperly", new Button.ClickListener() {
  55. @Override
  56. public void buttonClick(ClickEvent event) {
  57. toggle(false);
  58. }
  59. }));
  60. }
  61. private void toggle(boolean properly) {
  62. isChildRendered = !isChildRendered;
  63. if (properly) {
  64. brokenLayout.markAsDirtyRecursive();
  65. }
  66. normalLayout.getComponent(0).setVisible(isChildRendered);
  67. // Must also have a state change of the layout to trigger special case
  68. // related to optimizations
  69. normalLayout.setCaption("With child: " + isChildRendered);
  70. }
  71. }