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.

ClientCachingExample.java 2.5KB

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