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.

components-interfaces.asciidoc 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ---
  2. title: Interfaces and Abstractions
  3. order: 2
  4. layout: page
  5. ---
  6. [[components.interfaces]]
  7. = Interfaces and Abstractions
  8. *_This section has not yet been updated for Vaadin Framework 8_*
  9. ((("interfaces")))
  10. Vaadin user interface components are built on a skeleton of interfaces and
  11. abstract classes that define and implement the features common to all components
  12. and the basic logic how the component states are serialized between the server
  13. and the client.
  14. This section gives details on the basic component interfaces and abstractions.
  15. The layout and other component container abstractions are described in
  16. <<dummy/../../../framework/layout/layout-overview.asciidoc#layout.overview,"Managing Layout">>.
  17. The interfaces that define the Vaadin data model are described in <<dummy/../../../framework/datamodel/datamodel-overview.asciidoc#datamodel.overview,"Binding Components to Data">>.
  18. [[figure.components.interfaces]]
  19. .Component interfaces and abstractions
  20. image::img/component-abstractions-hi.png[width=100%, scaledwidth=100%]
  21. All components are connectors that connect to the client-side widgets.
  22. ((("[classname]#Serializable#")))
  23. In addition to the interfaces defined within the Vaadin framework, all
  24. components implement the [classname]#java.io.Serializable# interface to allow
  25. serialization. Serialization is needed in many clustering and cloud computing
  26. solutions.
  27. [[components.interfaces.component]]
  28. == [classname]#Component# Interface
  29. ((("[interfacename]#Component# interface")))
  30. The [interfacename]#Component# interface is paired with the
  31. [classname]#AbstractComponent# class, which implements all the methods defined
  32. in the interface.
  33. === Component Tree Management
  34. Components are laid out in the user interface hierarchically. The layout is
  35. managed by layout components, or more generally components that implement the
  36. [classname]#ComponentContainer# interface. Such a container is the parent of the
  37. contained components.
  38. The [methodname]#getParent()# method allows retrieving the parent component of a
  39. component. While there is a [methodname]#setParent()#, you rarely need it as you
  40. usually add components with the [methodname]#addComponent()# method of the
  41. [classname]#ComponentContainer# interface, which automatically sets the parent.
  42. A component does not know its parent when the component is still being created,
  43. so you can not refer to the parent in the constructor with
  44. [methodname]#getParent()#.
  45. Attaching a component to an UI triggers a call to its [methodname]#attach()#
  46. method. Correspondingly, removing a component from a container triggers calling
  47. the [methodname]#detach()# method. If the parent of an added component is
  48. already connected to the UI, the [methodname]#attach()# is called immediately
  49. from [methodname]#setParent()#.
  50. [source, java]
  51. ----
  52. public class AttachExample extends CustomComponent {
  53. public AttachExample() {
  54. }
  55. @Override
  56. public void attach() {
  57. super.attach(); // Must call.
  58. // Now we know who ultimately owns us.
  59. ClassResource r = new ClassResource("smiley.jpg");
  60. Image image = new Image("Image:", r);
  61. setCompositionRoot(image);
  62. }
  63. }
  64. ----
  65. The attachment logic is implemented in [classname]#AbstractComponent#, as
  66. described in <<components.interfaces.abstractcomponent>>.
  67. ((("[classname]#Component# interface")))
  68. [[components.interfaces.abstractcomponent]]
  69. == [classname]#AbstractComponent#
  70. ((("[classname]#AbstractComponent#", id="term.components.interfaces.abstractcomponent", range="startofrange")))
  71. [classname]#AbstractComponent# is the base class for all user interface
  72. components. It is the (only) implementation of the [classname]#Component#
  73. interface, implementing all the methods defined in the interface. When
  74. creating a new component, you should extend [classname]#AbstractComponent# or
  75. one of its subclasses.
  76. (((range="endofrange", startref="term.components.interfaces.abstractcomponent")))