Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ClientCachingExample.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.automatedtests.featurebrowser;
  5. import com.vaadin.terminal.PaintException;
  6. import com.vaadin.terminal.PaintTarget;
  7. import com.vaadin.ui.CustomComponent;
  8. import com.vaadin.ui.Label;
  9. import com.vaadin.ui.Layout;
  10. import com.vaadin.ui.TabSheet;
  11. import com.vaadin.ui.VerticalLayout;
  12. /**
  13. * This example is a (simple) demonstration of client-side caching. The content
  14. * in one tab is intentionally made very slow to produce server-side. When the
  15. * user changes to this tab for the first time, there will be a 3 second wait
  16. * before the content shows up, but the second time it shows up immediately
  17. * since the content has not changed and is cached client-side.
  18. *
  19. * @author IT Mill Ltd.
  20. */
  21. @SuppressWarnings("serial")
  22. public class ClientCachingExample extends CustomComponent {
  23. private static final String msg = "This example is a (simple) demonstration of client-side caching."
  24. + " The content in one tab is intentionally made very slow to"
  25. + " 'produce' server-side. When you changes to this tab for the"
  26. + " first time, there will be a 3 second wait before the content"
  27. + " shows up, but the second time it shows up immediately since the"
  28. + " content has not changed and is cached client-side.";
  29. public ClientCachingExample() {
  30. final VerticalLayout main = new VerticalLayout();
  31. main.setMargin(true);
  32. setCompositionRoot(main);
  33. main.addComponent(new Label(msg));
  34. final TabSheet ts = new TabSheet();
  35. main.addComponent(ts);
  36. Layout layout = new VerticalLayout();
  37. layout.setMargin(true);
  38. Label l = new Label("This is a normal label, quick to render.");
  39. l.setCaption("A normal label");
  40. layout.addComponent(l);
  41. ts.addTab(layout, "Normal", null);
  42. layout = new VerticalLayout();
  43. layout.setMargin(true);
  44. l = new Label("Slow label - until cached client side.") {
  45. @Override
  46. public void paintContent(PaintTarget target) throws PaintException {
  47. try {
  48. Thread.sleep(3000);
  49. } catch (final Exception e) {
  50. // IGNORED
  51. }
  52. super.paintContent(target);
  53. }
  54. };
  55. l.setCaption("A slow label");
  56. layout.addComponent(l);
  57. ts.addTab(layout, "Slow", null);
  58. }
  59. }