Class SuperTabs<T>

  • Type Parameters:
    T - Type of value.
    All Implemented Interfaces:
    com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.customfield.CustomField>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.customfield.CustomField>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.customfield.CustomField>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,​T>,​T>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,​T>,​T>, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.data.binder.HasItems<T>, Serializable, HasHelperPositionable, HasId, WithHelperMixin<SuperTabs<T>>, WithHelperPositionableMixin<SuperTabs<T>>, WithIdMixin<SuperTabs<T>>, WithItemsMixin<T,​SuperTabs<T>>, WithLabelMixin<SuperTabs<T>>, WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,​T>,​T,​SuperTabs<T>>

    @Tag("super-tabs")
    @CssImport(value="./styles/super-tabs-multiline.css",
               themeFor="vaadin-tabs")
    public class SuperTabs<T>
    extends com.vaadin.flow.component.customfield.CustomField<T>
    implements com.vaadin.flow.component.HasStyle, WithItemsMixin<T,​SuperTabs<T>>, WithIdMixin<SuperTabs<T>>, WithHelperMixin<SuperTabs<T>>, WithHelperPositionableMixin<SuperTabs<T>>, WithLabelMixin<SuperTabs<T>>, WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,​T>,​T,​SuperTabs<T>>
    Configurable tab sheet component that also is a field.
    Since:
    2020-04-10
    Author:
    miki
    See Also:
    Serialized Form
    • Field Detail

      • DEFAULT_TAB_CONTENTS_CONTAINER

        public static final Supplier<com.vaadin.flow.component.html.Div> DEFAULT_TAB_CONTENTS_CONTAINER
        Default container for tab contents.
      • MULTILINE_THEME_NAME

        public static final String MULTILINE_THEME_NAME
        Name of the theme for multiline tabs.
        See Also:
        Constant Field Values
    • Method Detail

      • addNewTab

        protected void addNewTab​(T value,
                                 boolean select)
        Adds a new tab and content for given value, using getTabHeaderGenerator() and getTabContentGenerator() to produce components.
        Parameters:
        value - A new value, not yet present in the component. Warning: no check are made to make sure this value is not used.
        select - Whether or not to select newly added tab.
      • addNewTab

        protected void addNewTab​(T value,
                                 com.vaadin.flow.component.tabs.Tab tab,
                                 com.vaadin.flow.component.Component content,
                                 boolean select)
        Adds a new tab and content for given value.
        Parameters:
        value - A new value, not yet present in the component. Warning: no check are made to make sure this value is not used.
        tab - Tab corresponding to the value.
        content - Content corresponding to the value.
        select - Whether or not to select newly added tab.
      • addTabs

        public void addTabs​(Collection<T> values)
        Adds a tab for each of the given values. Selects the tab if it was already present, otherwise just adds it. Will use getTabHeaderGenerator() and getTabContentGenerator() to produce components. If there were no tabs prior to calling this method, the first tab added this way will be selected.
        Parameters:
        values - Values to add tabs and contents for.
      • addTab

        public void addTab​(T value,
                           com.vaadin.flow.component.tabs.Tab tabHeader,
                           com.vaadin.flow.component.Component tabContents)
        Adds a tab for a given value. Selects the tab if it was already present, otherwise just adds it. This will *not* overwrite the existing tab. If you want that, remove the tab first. If this is the first tab added, it will be selected.
        Parameters:
        value - A value that corresponds to provided tab header and tab contents.
        tabHeader - Header.
        tabContents - Contents.
      • removeExistingTab

        protected void removeExistingTab​(T value,
                                         com.vaadin.flow.component.tabs.Tab header)
        Removes an existing tab, its header and contents. Makes no check on whether the tab is really there.
        Parameters:
        value - Value to remove.
        header - Header being removed.
      • removeTab

        public void removeTab​(T value)
        Removes the tab for a given value, if found. If the tab was selected, there will be no selection active.
        Parameters:
        value - Value to remove the tab for.
      • getValueAndTab

        protected Optional<Map.Entry<T,​com.vaadin.flow.component.tabs.Tab>> getValueAndTab​(T value)
        Finds the value and tab entry corresponding to the given value.
        Parameters:
        value - A value to look for.
        Returns:
        Value and its matching Tab, if any.
      • getTabHeader

        public Optional<com.vaadin.flow.component.tabs.Tab> getTabHeader​(T value)
        Returns tab header that corresponds to the given value.
        Parameters:
        value - Value to look for.
        Returns:
        A Tab that corresponds to the value, if any.
      • getTabContents

        public Optional<com.vaadin.flow.component.Component> getTabContents​(T value)
        Returns contents that corresponds to the given value. Note: Component.setVisible(boolean) calls on the result are discouraged ;)
        Parameters:
        value - Value to look for.
        Returns:
        A Component that corresponds to the value, if any.
      • generateModelValue

        protected T generateModelValue()
        Specified by:
        generateModelValue in class com.vaadin.flow.component.customfield.CustomField<T>
      • setPresentationValue

        protected void setPresentationValue​(T t)
        Specified by:
        setPresentationValue in class com.vaadin.flow.component.customfield.CustomField<T>
      • getValues

        public List<T> getValues()
        Returns the values that correspond to tabs.
        Returns:
        A collection of values. Modifying the returned collection has no effect on this component.
        See Also:
        getTabHeader(Object), getTabContents(Object)
      • size

        public int size()
        Returns the number of values that currently correspond to tabs.
        Returns:
        A number of values.
      • setTabContentGenerator

        public void setTabContentGenerator​(TabContentGenerator<T> tabContentGenerator)
        Sets the generator responsible for providing content for selected tabs. It is called first time a tab is displayed. When the generator is changed, the new one has no effect on previously generated content.
        Parameters:
        tabContentGenerator - TabContentGenerator. If null, it will be replaced with a default function.
      • setTabHeaderGenerator

        public void setTabHeaderGenerator​(TabHeaderGenerator<T> tabHeaderGenerator)
        Sets the generator responsible for providing tabs (headers) for values. It is called first time a tab is created. When the generator is changed, the new one has no effect on previously generated tabs.
        Parameters:
        tabHeaderGenerator - TabHeaderGenerator. If null, it will be replaced with a default function.
      • isCustomValueAllowed

        public boolean isCustomValueAllowed()
        Whether or not custom values may be set through AbstractField.setValue(Object).
        Returns:
        true when selecting a value that does not have a corresponding tab results in adding a new tab, false otherwise (and by default).
      • setCustomValueAllowed

        public void setCustomValueAllowed​(boolean customValueAllowed)
        Allows or disallows creating new tabs when calling AbstractField.setValue(Object).
        Parameters:
        customValueAllowed - when true, selecting a value that does not have a corresponding tab will result in adding and selecting a new tab; false will ignore setting the value.
      • setTabHandler

        public void setTabHandler​(TabHandler tabHandler)
        Sets the new TabHandler to use. Causes all current tab contents to be removed with the current TabHandler, then added and (de)selected with the new one. Does not trigger value change events nor generating tab headers/contents, as only the handling of tabs is changed.
        Parameters:
        tabHandler - A TabHandler. If null is passed, TabHandlers.REMOVING_HANDLER will be used.
      • isMultiline

        public boolean isMultiline()
        Checks whether tabs wrap to a new line.
        Returns:
        When true and tabs would overflow current viewport, the extra ones will drop to the next line; false otherwise and by default.
      • setMultiline

        public void setMultiline​(boolean multiline)
        Sets whether or not tabs should overflow to next line.
        Parameters:
        multiline - When true and tabs overflow current viewport, the extra ones will drop to the next line; false when all should be displayed in one line (with navigation buttons if needed).
      • setItems

        public void setItems​(Collection<T> collection)
        Specified by:
        setItems in interface com.vaadin.flow.data.binder.HasItems<T>
      • setId

        public void setId​(String id)
        Description copied from interface: HasId
        Sets this object's id.
        Specified by:
        setId in interface HasId
        Overrides:
        setId in class com.vaadin.flow.component.Component
        Parameters:
        id - A new id. Can be null to remove existing id.