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 4.4KB

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