Package com.vaadin.ui

Class CustomComponent

  • All Implemented Interfaces:
    ContextClickEvent.ContextClickNotifier, MethodEventSource, ClientConnector, Sizeable, Connector, Component, HasComponents, Serializable, Iterable<Component>
    Direct Known Subclasses:
    ColorPickerHistory, ColorPickerSelect, DragAndDropWrapper

    public class CustomComponent
    extends AbstractComponent
    implements HasComponents
    Custom component provides a simple implementation of the Component interface to allow creating new UI components by composition of existing server-side components.

    The component is used by inheriting the CustomComponent class and setting the composition root component. The composition root must be set with setCompositionRoot(Component) before the CustomComponent is used, such as by adding it to a layout, so it is preferable to set it in the constructor.

    The composition root itself can contain more components. The advantage of wrapping it in a CustomComponent is that its details, such as interfaces, are hidden from the users of the component, thereby contributing to information hiding.

    The CustomComponent does not display the caption of the composition root, so if you want to have it shown in the layout where the custom component is contained, you need to set it as caption of the CustomComponent.

    The component expands horizontally and has undefined height by default.

    Since:
    3.0
    Author:
    Vaadin Ltd.
    See Also:
    Serialized Form
    • Constructor Detail

      • CustomComponent

        public CustomComponent()
        Constructs a new custom component.

        Note that you must set the composition root before the component can be used, preferably in the constructor.

      • CustomComponent

        public CustomComponent​(Component compositionRoot)
        Constructs a new custom component.
        Parameters:
        compositionRoot - the root of the composition component tree. It must not be null.
    • Method Detail

      • getCompositionRoot

        protected Component getCompositionRoot()
        Returns the composition root.
        Returns:
        the Component Composition root.
      • setCompositionRoot

        protected void setCompositionRoot​(Component compositionRoot)
        Sets the composition root for the component.

        You must set the composition root to a non-null value before the component can be used. You can change it later.

        Parameters:
        compositionRoot - the root of the composition component tree.
      • iterator

        public Iterator<Component> iterator()
        Description copied from interface: HasComponents
        Gets an iterator to the collection of contained components. Using this iterator it is possible to step through all components contained in this container.
        Specified by:
        iterator in interface HasComponents
        Specified by:
        iterator in interface Iterable<Component>
        Returns:
        the component iterator.
      • getComponentCount

        public int getComponentCount()
        Gets the number of contained components. Consistent with the iterator returned by #getComponentIterator().
        Returns:
        the number of contained components (zero or one)