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.

ClientWidget.java 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. /**
  5. *
  6. */
  7. package com.vaadin.ui;
  8. import java.lang.annotation.ElementType;
  9. import java.lang.annotation.Retention;
  10. import java.lang.annotation.RetentionPolicy;
  11. import java.lang.annotation.Target;
  12. import com.vaadin.terminal.gwt.client.VPaintableWidget;
  13. import com.vaadin.terminal.gwt.widgetsetutils.CustomWidgetMapGenerator;
  14. import com.vaadin.terminal.gwt.widgetsetutils.EagerWidgetMapGenerator;
  15. import com.vaadin.terminal.gwt.widgetsetutils.LazyWidgetMapGenerator;
  16. import com.vaadin.terminal.gwt.widgetsetutils.WidgetMapGenerator;
  17. /**
  18. * Annotation defining the default client side counterpart in GWT terminal for
  19. * {@link Component}.
  20. * <p>
  21. * With this annotation server side Vaadin component is marked to have a client
  22. * side counterpart. The value of the annotation is the class of client side
  23. * implementation.
  24. * <p>
  25. * Note, even though client side implementation is needed during development,
  26. * one may safely remove them from the classpath of the production server.
  27. *
  28. * @since 6.2
  29. */
  30. @Retention(RetentionPolicy.RUNTIME)
  31. @Target(ElementType.TYPE)
  32. public @interface ClientWidget {
  33. /**
  34. * @return the client side counterpart for the annotated component
  35. */
  36. Class<? extends VPaintableWidget> value();
  37. /**
  38. * Depending on the used WidgetMap generator, these optional hints may be
  39. * used to define how the client side components are loaded by the browser.
  40. * The default is to eagerly load all widgets
  41. * {@link EagerWidgetMapGenerator}, but if the {@link WidgetMapGenerator} is
  42. * used by the widgetset, these load style hints are respected.
  43. * <p>
  44. * Lazy loading of a widget implementation means the client side component
  45. * is not included in the initial JavaScript application loaded when the
  46. * application starts. Instead the implementation is loaded to the client
  47. * when it is first needed. Lazy loaded widget can be achieved by giving
  48. * {@link LoadStyle#LAZY} value in ClientWidget annotation.
  49. * <p>
  50. * Lazy loaded widgets don't stress the size and startup time of the client
  51. * side as much as eagerly loaded widgets. On the other hand there is a
  52. * slight latency when lazy loaded widgets are first used as the client side
  53. * needs to visit the server to fetch the client side implementation.
  54. * <p>
  55. * The {@link LoadStyle#DEFERRED} will also not stress the initially loaded
  56. * JavaScript file. If this load style is defined, the widget implementation
  57. * is preemptively loaded to the browser after the application is started
  58. * and the communication to server idles. This load style kind of combines
  59. * the best of both worlds.
  60. * <p>
  61. * Fine tunings to widget loading can also be made by overriding
  62. * {@link WidgetMapGenerator} in the GWT module. Tunings might be helpful if
  63. * the end users have slow connections and especially if they have high
  64. * latency in their network. The {@link CustomWidgetMapGenerator} is an
  65. * abstract generator implementation for easy customization. Vaadin package
  66. * also includes {@link LazyWidgetMapGenerator} that makes as many widgets
  67. * lazily loaded as possible.
  68. *
  69. * @since 6.4
  70. *
  71. * @return the hint for the widget set generator how the client side
  72. * implementation should be loaded to the browser
  73. */
  74. LoadStyle loadStyle() default LoadStyle.DEFERRED;
  75. public enum LoadStyle {
  76. /**
  77. * The widget is included in the initial JS sent to the client.
  78. */
  79. EAGER,
  80. /**
  81. * Not included in the initial set of widgets, but added to queue from
  82. * which it will be loaded when network is not busy or the
  83. * implementation is required.
  84. */
  85. DEFERRED,
  86. /**
  87. * Loaded to the client only if needed.
  88. */
  89. LAZY
  90. }
  91. }