Class SuperTabs<T>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<com.vaadin.flow.component.customfield.CustomField<T>,T>
com.vaadin.flow.component.customfield.CustomField<T>
org.vaadin.miki.superfields.tabs.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<T>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.customfield.CustomField<T>>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.customfield.CustomField<T>>, 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.component.shared.HasValidationProperties, 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:
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField

    com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V extends Object>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier

    com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier

    com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue

    com.vaadin.flow.component.HasValue.ValueChangeEvent<V extends Object>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Supplier<com.vaadin.flow.component.html.Div>
    Default container for tab contents.
    static final String
    Name of the theme for multiline tabs.

    Fields inherited from interface org.vaadin.miki.markers.HasHelperPositionable

    HELPER_ABOVE_THEME_VARIANT
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates the component with no tabs and default TabHandler, TabHeaderGenerator and TabContentGenerator.
    SuperTabs(Supplier<C> mainContentSupplier, T... values)
    Creates the component with no tabs and default TabHandler, TabHeaderGenerator and TabContentGenerator, overriding default main layout component for the tab contents.
    SuperTabs(TabContentGenerator<T> tabContentGenerator, T... values)
    Creates the component with given TabContentGenerator and tabs, but with default TabHeaderGenerator and TabHandler.
    SuperTabs(TabHeaderGenerator<T> tabHeaderGenerator, TabContentGenerator<T> tabContentGenerator, T... values)
    Creates the component with given TabHeaderGenerator, TabContentGenerator and tabs, but default TabHandler.
    SuperTabs(T defaultValue, Supplier<C> mainContentSupplier, TabHandler tabHandler, TabHeaderGenerator<T> tabHeaderGenerator, TabContentGenerator<T> tabContentGenerator, T... values)
    Creates the component with given TabHandler, TabHeaderGenerator, TabContentGenerator and tabs, overriding the default value from null to the one provided and overriding default layout component for tab contents.
    SuperTabs(T defaultValue, TabHandler tabHandler, TabHeaderGenerator<T> tabHeaderGenerator, TabContentGenerator<T> tabContentGenerator, T... values)
    Creates the component with given TabHandler, TabHeaderGenerator, TabContentGenerator and tabs, overriding the default value from null to the one provided.
    SuperTabs(T defaultValue, TabHeaderGenerator<T> tabHeaderGenerator, TabContentGenerator<T> tabContentGenerator, T... values)
    Creates the component with default TabHandler, given TabHeaderGenerator, TabContentGenerator and tabs, overriding the default value from null to the one provided.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addNewTab(T value, boolean select)
    Adds a new tab and content for given value, using getTabHeaderGenerator() and getTabContentGenerator() to produce components.
    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.
    final void
    addTab(T... values)
    This method adds one or more tabs.
    void
    addTab(T value, com.vaadin.flow.component.tabs.Tab tabHeader, com.vaadin.flow.component.Component tabContents)
    Adds a tab for a given value.
    void
    addTabs(Collection<T> values)
    Adds a tab for each of the given values.
    protected T
     
    Returns the generator responsible for providing content for selected tabs.
    Optional<com.vaadin.flow.component.Component>
    Returns contents that corresponds to the given value.
    Returns the current TabHandler.
    Optional<com.vaadin.flow.component.tabs.Tab>
    getTabHeader(T value)
    Returns tab header that corresponds to the given value.
    Returns the generator responsible for providing tabs (headers) for values.
    protected Optional<Map.Entry<T,com.vaadin.flow.component.tabs.Tab>>
    Finds the value and tab entry corresponding to the given value.
    Returns the values that correspond to tabs.
    boolean
    Whether or not custom values may be set through AbstractField.setValue(Object).
    boolean
    Checks whether tabs wrap to a new line.
    protected void
    removeExistingTab(T value, com.vaadin.flow.component.tabs.Tab header)
    Removes an existing tab, its header and contents.
    void
    removeTab(T value)
    Removes the tab for a given value, if found.
    void
    setCustomValueAllowed(boolean customValueAllowed)
    Allows or disallows creating new tabs when calling AbstractField.setValue(Object).
    void
    Sets this object's id.
    void
    setItems(Collection<T> collection)
     
    void
    setMultiline(boolean multiline)
    Sets whether or not tabs should overflow to next line.
    protected void
     
    void
    Sets the generator responsible for providing content for selected tabs.
    void
    Sets the new TabHandler to use.
    void
    Sets the generator responsible for providing tabs (headers) for values.
    int
    Returns the number of values that currently correspond to tabs.
    withCustomValueAllowed(boolean customValueAllowed)
    Chains setCustomValueAllowed(boolean) and returns itself.
    withMultiline(boolean multiline)
    Chains setMultiline(boolean) and returns itself.
    Chains setTabHandler(TabHandler) and returns itself.

    Methods inherited from class com.vaadin.flow.component.customfield.CustomField

    add, addThemeVariants, getLabel, onAttach, remove, removeThemeVariants, setLabel, updateValue

    Methods inherited from class com.vaadin.flow.component.AbstractField

    addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEquals

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.BlurNotifier

    addBlurListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.Focusable

    addFocusShortcut, blur, focus, getTabIndex, setTabIndex

    Methods inherited from interface com.vaadin.flow.component.FocusNotifier

    addFocusListener

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.component.HasHelper

    getHelperComponent, getHelperText, setHelperComponent, setHelperText

    Methods inherited from interface org.vaadin.miki.markers.HasHelperPositionable

    isHelperAbove, setHelperAbove, setHelperAbove, setHelperBelow

    Methods inherited from interface org.vaadin.miki.markers.HasId

    getId

    Methods inherited from interface com.vaadin.flow.data.binder.HasItems

    setItems, setItems

    Methods inherited from interface com.vaadin.flow.component.HasLabel

    getLabel, setLabel

    Methods inherited from interface com.vaadin.flow.component.HasSize

    getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.HasTheme

    addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

    Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip

    getTooltip, setTooltipText

    Methods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties

    getErrorMessage, isInvalid, setErrorMessage, setInvalid

    Methods inherited from interface com.vaadin.flow.component.HasValue

    addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValue

    Methods inherited from interface com.vaadin.flow.component.HasValueAndElement

    isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible

    Methods inherited from interface org.vaadin.miki.markers.WithHelperMixin

    withHelperComponent, withHelperText

    Methods inherited from interface org.vaadin.miki.markers.WithHelperPositionableMixin

    withHelperAbove, withHelperAbove, withHelperBelow

    Methods inherited from interface org.vaadin.miki.markers.WithIdMixin

    withId

    Methods inherited from interface org.vaadin.miki.markers.WithItemsMixin

    withItems, withItems, withItems

    Methods inherited from interface org.vaadin.miki.markers.WithLabelMixin

    withLabel

    Methods inherited from interface org.vaadin.miki.markers.WithValueMixin

    withValue
  • Field Details

    • 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:
  • Constructor Details

  • Method Details

    • 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.
    • addTab

      @SafeVarargs public final void addTab(T... values)
      This method adds one or more tabs. It converts the values into a Collection and calls addTabs(Collection).
      Parameters:
      values - Values to add tabs and contents for.
      See Also:
    • 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:
    • 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.
    • getTabContentGenerator

      public TabContentGenerator<T> getTabContentGenerator()
      Returns the generator responsible for providing content for selected tabs.
      Returns:
      TabContentGenerator.
    • withTabContentGenerator

      public SuperTabs<T> withTabContentGenerator(TabContentGenerator<T> tabContentGenerator)
      Parameters:
      tabContentGenerator - A TabContentGenerator.
      Returns:
      This.
      See Also:
    • 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.
    • getTabHeaderGenerator

      public TabHeaderGenerator<T> getTabHeaderGenerator()
      Returns the generator responsible for providing tabs (headers) for values.
      Returns:
      TabContentGenerator.
    • withTabHeaderGenerator

      public SuperTabs<T> withTabHeaderGenerator(TabHeaderGenerator<T> tabHeaderGenerator)
      Parameters:
      tabHeaderGenerator - A TabHeaderGenerator.
      Returns:
      This.
      See Also:
    • 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.
    • withCustomValueAllowed

      public SuperTabs<T> withCustomValueAllowed(boolean customValueAllowed)
      Chains setCustomValueAllowed(boolean) and returns itself.
      Parameters:
      customValueAllowed - Whether or not to allow setting custom value.
      Returns:
      This.
      See Also:
    • 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.
    • getTabHandler

      public TabHandler getTabHandler()
      Returns the current TabHandler.
      Returns:
      A TabHandler. Never null.
    • withTabHandler

      public SuperTabs<T> withTabHandler(TabHandler tabHandler)
      Chains setTabHandler(TabHandler) and returns itself.
      Parameters:
      tabHandler - A TabHandler. If null is passed, TabHandlers.REMOVING_HANDLER will be used.
      Returns:
      This.
      See Also:
    • 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).
    • withMultiline

      public SuperTabs<T> withMultiline(boolean multiline)
      Chains setMultiline(boolean) and returns itself.
      Parameters:
      multiline - Whether or not wrap tabs into new line on overflow.
      Returns:
      This.
      See Also:
    • 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.