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

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