Class FTabSheet

All Implemented Interfaces:
FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, ClientConnector, FAbstractClientConnector, FSizeable, Sizeable, ComponentContainer, FAbstractComponent, HasComponents, HasComponents.ComponentAttachDetachNotifier, com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.tabs.TabSheet>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.tabs.TabSheet>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.tabs.TabSheet>, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasComponentsOfType<com.vaadin.flow.component.Component>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.shared.HasTooltip, Serializable, Iterable<com.vaadin.flow.component.Component>

@Tag("div") @CssImport("./tab-sheet.css") public class FTabSheet extends AbstractComponentContainer implements com.vaadin.flow.component.Focusable<com.vaadin.flow.component.tabs.TabSheet>, FieldEvents.FocusNotifier, FieldEvents.BlurNotifier
FTabSheet component is a feature-pack component with Vaadin 7 Framework TabSheet component API. Tabs are typically identified by the component contained on the tab (see ComponentContainer), and tab metadata (including caption, icon, visibility, enabledness, closability etc.) is kept in separate FTabSheet.Tab instances. Tabs added with addComponent(Component) get the caption and the icon of the component at the time when the component is created, and these are not automatically updated after tab creation. A tab sheet can have multiple tab selection listeners and one tab close handler (FTabSheet.CloseHandler), which by default removes the tab from the TabSheet.
Author:
Vaadin Ltd.
See Also:
  • Constructor Details

    • FTabSheet

      public FTabSheet()
      Constructs a new FTabSheet. The default close handler removes the tab being closed.
    • FTabSheet

      public FTabSheet(com.vaadin.flow.component.Component... components)
      Constructs a new FTabSheet containing the given components.
      Parameters:
      components - The components to add to the tab sheet. Each component will be added to a separate tab.
  • Method Details

    • setLabelComponent

      public void setLabelComponent(com.vaadin.flow.component.Component labelComponent)
      Description copied from interface: FAbstractComponent
      Sets the component's label component. Flow components that support caption component usually overrides this.
      Specified by:
      setLabelComponent in interface FAbstractComponent
      Parameters:
      labelComponent - the new label component for the component.
    • setWidth

      public void setWidth(float width, com.vaadin.flow.component.Unit unit)
      Description copied from interface: Sizeable
      Sets the width of the object. Negative number implies unspecified size (terminal is free to set the size).
      Specified by:
      setWidth in interface FSizeable
      Specified by:
      setWidth in interface Sizeable
      Overrides:
      setWidth in class AbstractComponentContainer
      Parameters:
      width - the width of the object.
      unit - the unit used for the width.
    • setHeight

      public void setHeight(float height, com.vaadin.flow.component.Unit unit)
      Description copied from interface: Sizeable
      Sets the height of the object. Negative number implies unspecified size (terminal is free to set the size).
      Specified by:
      setHeight in interface FSizeable
      Specified by:
      setHeight in interface Sizeable
      Overrides:
      setHeight in class AbstractComponentContainer
      Parameters:
      height - the height of the object.
      unit - the unit used for the width.
    • iterator

      public Iterator<com.vaadin.flow.component.Component> iterator()
      Gets the component container iterator for going through all the components (tab contents).
      Specified by:
      iterator in interface HasComponents
      Specified by:
      iterator in interface Iterable<com.vaadin.flow.component.Component>
      Overrides:
      iterator in class AbstractComponentContainer
      Returns:
      the unmodifiable Iterator of the tab content components
    • getComponentCount

      public int getComponentCount()
      Gets the number of contained components (tabs). Consistent with the iterator returned by iterator().
      Specified by:
      getComponentCount in interface ComponentContainer
      Specified by:
      getComponentCount in interface com.vaadin.flow.component.HasComponentsOfType<com.vaadin.flow.component.Component>
      Returns:
      the number of contained components
    • removeComponent

      public void removeComponent(com.vaadin.flow.component.Component component)
      Removes a component and its corresponding tab. If the tab was selected, the first eligible (visible and enabled) remaining tab is selected.
      Specified by:
      removeComponent in interface ComponentContainer
      Overrides:
      removeComponent in class AbstractComponentContainer
      Parameters:
      component - the component to be removed.
    • selectedTabIndexAfterTabRemove

      protected int selectedTabIndexAfterTabRemove(int removedTabIndex)
      Called when a selected tab is removed to specify the new tab to select. Can be overridden to provide another algorithm that calculates the new selection. Current implementation will choose the first enabled tab to the right of the removed tab if it's not the last one, otherwise will choose the closer enabled tab to the left.
      Parameters:
      removedTabIndex - the index of the selected tab which was just remove.
      Returns:
      the index of the tab to be selected or -1 if there are no more enabled tabs to select.
    • removeTab

      public void removeTab(FTabSheet.Tab tab)
      Removes a FTabSheet.Tab and the component associated with it, as previously added with addTab(Component), addTab(Component, String, Resource) or addComponent(Component).

      If the tab was selected, the first eligible (visible and enabled) remaining tab is selected.

      Parameters:
      tab - the Tab to remove
      See Also:
    • addComponent

      public void addComponent(com.vaadin.flow.component.Component c)
      Adds a new tab into FTabSheet. Component caption and icon are copied to the tab metadata at creation time.
      Specified by:
      addComponent in interface ComponentContainer
      Overrides:
      addComponent in class AbstractComponentContainer
      Parameters:
      c - the component to be added.
      See Also:
    • addTab

      public FTabSheet.Tab addTab(com.vaadin.flow.component.Component c, String caption)
      Adds a new tab into FTabSheet. The first tab added to a tab sheet is automatically selected and a tab selection event is fired. If the component is already present in the tab sheet, changes its caption and returns the corresponding (old) tab, preserving other tab metadata.
      Parameters:
      c - the component to be added onto tab - should not be null.
      caption - the caption to be set for the component and used rendered in tab bar
      Returns:
      the created FTabSheet.Tab
    • addTab

      public FTabSheet.Tab addTab(com.vaadin.flow.component.Component c, String caption, Resource icon)
      Adds a new tab into FTabSheet. The first tab added to a tab sheet is automatically selected and a tab selection event is fired. If the component is already present in the tab sheet, changes its caption and icon and returns the corresponding (old) tab, preserving other tab metadata.
      Parameters:
      c - the component to be added onto tab - should not be null.
      caption - the caption to be set for the component and used rendered in tab bar
      icon - the icon to be set for the component and used rendered in tab bar
      Returns:
      the created FTabSheet.Tab
    • addTab

      public FTabSheet.Tab addTab(com.vaadin.flow.component.Component c, String caption, com.vaadin.flow.component.icon.IconFactory iconFactory)
      Adds a new tab into FTabSheet. The first tab added to a tab sheet is automatically selected and a tab selection event is fired. If the component is already present in the tab sheet, changes its caption and icon and returns the corresponding (old) tab, preserving other tab metadata.
      Parameters:
      c - the component to be added onto tab - should not be null.
      caption - the caption to be set for the component and used rendered in tab bar
      iconFactory - the icon factory to use for creating the icon that should be set for the component and used rendered in tab bar
      Returns:
      the created FTabSheet.Tab
    • addTab

      public FTabSheet.Tab addTab(com.vaadin.flow.component.Component tabComponent, String caption, Resource icon, int position)
      Adds a new tab into FTabSheet. The first tab added to a tab sheet is automatically selected and a tab selection event is fired. If the component is already present in the tab sheet, changes its caption and icon and returns the corresponding (old) tab, preserving other tab metadata like the position.
      Parameters:
      tabComponent - the component to be added onto tab - should not be null.
      caption - the caption to be set for the component and used rendered in tab bar
      icon - the icon to be set for the component and used rendered in tab bar
      position - the position at where the the tab should be added.
      Returns:
      the created FTabSheet.Tab
    • addTab

      public FTabSheet.Tab addTab(com.vaadin.flow.component.Component tabComponent, String caption, com.vaadin.flow.component.icon.IconFactory iconFactory, int position)
      Adds a new tab into FTabSheet. The first tab added to a tab sheet is automatically selected and a tab selection event is fired. If the component is already present in the tab sheet, changes its caption and icon and returns the corresponding (old) tab, preserving other tab metadata like the position.
      Parameters:
      tabComponent - the component to be added onto tab - should not be null.
      caption - the caption to be set for the component and used rendered in tab bar
      iconFactory - the icon factory to use for creating the icon that should be set for the component and used rendered in tab bar
      position - the position at where the the tab should be added.
      Returns:
      the created FTabSheet.Tab
    • addTab

      public FTabSheet.Tab addTab(com.vaadin.flow.component.Component c)
      Adds a new tab into FTabSheet. Component caption and icon are copied to the tab metadata at creation time. If the tab sheet already contains the component, its tab is returned.
      Parameters:
      c - the component to be added onto tab - should not be null.
      Returns:
      the created FTabSheet.Tab
    • addTab

      public FTabSheet.Tab addTab(com.vaadin.flow.component.Component component, int position)
      Adds a new tab into FTabSheet. Component caption and icon are copied to the tab metadata at creation time. If the tab sheet already contains the component, its tab is returned.
      Parameters:
      component - the component to be added onto tab - should not be null.
      position - The position where the tab should be added
      Returns:
      the created FTabSheet.Tab
    • moveComponentsFrom

      public void moveComponentsFrom(ComponentContainer source)
      Moves all components from another container to this container. The components are removed from the other container. If the source container is a FTabSheet, component captions and icons are copied from it.
      Specified by:
      moveComponentsFrom in interface ComponentContainer
      Overrides:
      moveComponentsFrom in class AbstractComponentContainer
      Parameters:
      source - the container components are removed from.
    • setTabsVisible

      public void setTabsVisible(boolean tabsVisible)
      Sets whether the tab selection part should be shown in the UI
      Parameters:
      tabsVisible - true if the tabs should be shown in the UI, false otherwise
    • isTabsVisible

      public boolean isTabsVisible()
      Checks if the tab selection part should be shown in the UI
      Returns:
      true if the tabs are shown in the UI, false otherwise
    • getTab

      public FTabSheet.Tab getTab(com.vaadin.flow.component.Component c)
      Returns the FTabSheet.Tab (metadata) for a component. The FTabSheet.Tab object can be used for setting caption,icon, etc for the tab.
      Parameters:
      c - the component
      Returns:
      The tab instance associated with the given component, or null if the tabsheet does not contain the component.
    • getTab

      public FTabSheet.Tab getTab(int position)
      Returns the FTabSheet.Tab (metadata) for a component. The FTabSheet.Tab object can be used for setting caption,icon, etc for the tab.
      Parameters:
      position - the position of the tab
      Returns:
      The tab in the given position, or null if the position is out of bounds.
    • setSelectedTab

      public void setSelectedTab(com.vaadin.flow.component.Component c)
      Sets the selected tab. The tab is identified by the tab content component. Does nothing if the tabsheet doesn't contain the component.
      Parameters:
      c - the component of the tab to select
    • setSelectedTab

      public void setSelectedTab(com.vaadin.flow.component.Component component, boolean userOriginated)
      Sets the selected tab. The tab is identified by the tab content component. Does nothing if the tabsheet doesn't contain the component.
      Parameters:
      component - the component of the tab to select
      userOriginated - true if the event originates from the client side, false otherwise
      Since:
      8.1
    • setSelectedTab

      public void setSelectedTab(FTabSheet.Tab tab)
      Sets the selected tab. The tab is identified by the corresponding Tab instance. Does nothing if the tabsheet doesn't contain the given tab.
      Parameters:
      tab -
    • setSelectedTab

      public void setSelectedTab(int position)
      Sets the selected tab, identified by its position. Does nothing if the position is out of bounds.
      Parameters:
      position -
    • getSelectedTab

      public com.vaadin.flow.component.Component getSelectedTab()
      Gets the selected tab content component.
      Returns:
      the selected tab contents
    • replaceComponent

      public void replaceComponent(com.vaadin.flow.component.Component oldComponent, com.vaadin.flow.component.Component newComponent)
      Replaces a component (tab content) with another. This can be used to change tab contents or to rearrange tabs. The tab position and some metadata are preserved when moving components within the same FTabSheet. If the oldComponent is not present in the tab sheet, the new one is added at the end. If the oldComponent is already in the tab sheet but the newComponent isn't, the old tab is replaced with a new one, and the caption and icon of the old one are copied to the new tab. If both old and new components are present, their positions are swapped. Replaces the component in the container with another one without changing position.

      This method replaces component with another one is such way that the new component overtakes the position of the old component. If the old component is not in the container, the new component is added to the container. If the both component are already in the container, their positions are swapped. Component attach and detach events should be taken care as with add and remove.

      Specified by:
      replaceComponent in interface ComponentContainer
      Parameters:
      oldComponent - the old component that will be replaced.
      newComponent - the new component to be replaced.
    • addSelectedTabChangeListener

      public com.vaadin.flow.shared.Registration addSelectedTabChangeListener(FTabSheet.SelectedTabChangeListener listener)
      Adds a tab selection listener.

      This is the Vaadin 7 variant of the method.

      Parameters:
      listener - the Listener to be added.
    • addSelectedTabChangeListener

      public com.vaadin.flow.shared.Registration addSelectedTabChangeListener(FTabSheet.FSelectedTabChangeListener listener)
      Adds a tab selection listener.

      This is the Vaadin 8 variant of the method.

      Parameters:
      listener - the Listener to be added.
    • removeSelectedTabChangeListener

      public void removeSelectedTabChangeListener(FTabSheet.SelectedTabChangeListener listener)
      Removes a tab selection listener.

      This is the Vaadin 7 variant of the method.

      Parameters:
      listener - the Listener to be removed.
    • removeSelectedTabChangeListener

      public void removeSelectedTabChangeListener(FTabSheet.FSelectedTabChangeListener listener)
      Removes a tab selection listener.

      This is the Vaadin 8 variant of the method.

      Parameters:
      listener - the Listener to be removed.
    • fireSelectedTabChange

      protected void fireSelectedTabChange()
      Sends an event that the currently selected tab has changed.

      This is the Vaadin 7 variant of the method.

    • fireSelectedTabChange

      protected void fireSelectedTabChange(boolean userOriginated)
      Sends an event that the currently selected tab has changed.

      This is the Vaadin 8 variant of the method.

      Parameters:
      userOriginated - true if the event originates from the client side, false otherwise
    • setCloseHandler

      public void setCloseHandler(FTabSheet.CloseHandler handler)
      Provide a custom FTabSheet.CloseHandler for this TabSheet if you wish to perform some additional tasks when a user clicks on a tabs close button, e.g. show a confirmation dialogue before removing the tab. To remove the tab, if you provide your own close handler, you must call removeComponent(Component) yourself. The default CloseHandler for TabSheet will only remove the tab.
      Parameters:
      handler -
    • setTabPosition

      public void setTabPosition(FTabSheet.Tab tab, int position)
      Sets the position of the tab.
      Parameters:
      tab - The tab
      position - The new position of the tab
    • getTabPosition

      public int getTabPosition(FTabSheet.Tab tab)
      Gets the position of the tab
      Parameters:
      tab - The tab
      Returns:
    • focus

      public void focus()
      Description copied from class: AbstractComponent
      Sets the focus for this component if the component is Focusable. NOTE: the focus is not set until the component is attached.
      Specified by:
      focus in interface com.vaadin.flow.component.Focusable<com.vaadin.flow.component.tabs.TabSheet>
      Overrides:
      focus in class AbstractComponent
    • getTabIndex

      public int getTabIndex()
      Specified by:
      getTabIndex in interface com.vaadin.flow.component.Focusable<com.vaadin.flow.component.tabs.TabSheet>
    • setTabIndex

      public void setTabIndex(int tabIndex)
      Specified by:
      setTabIndex in interface com.vaadin.flow.component.Focusable<com.vaadin.flow.component.tabs.TabSheet>
    • addBlurListener

      public void addBlurListener(FieldEvents.BlurListener listener)
      Description copied from interface: FieldEvents.BlurNotifier
      Adds a BlurListener to the Component which gets fired when a Field loses keyboard focus.
      Specified by:
      addBlurListener in interface FieldEvents.BlurNotifier
      Parameters:
      listener - BlurListener
      See Also:
    • removeBlurListener

      public void removeBlurListener(FieldEvents.BlurListener listener)
      Description copied from interface: FieldEvents.BlurNotifier
      Removes a BlurListener from the Component.
      Specified by:
      removeBlurListener in interface FieldEvents.BlurNotifier
      Parameters:
      listener - BlurListener
      See Also:
    • addFocusListener

      public void addFocusListener(FieldEvents.FocusListener listener)
      Description copied from interface: FieldEvents.FocusNotifier
      Adds a FocusListener to the Component which gets fired when a Field receives keyboard focus.
      Specified by:
      addFocusListener in interface FieldEvents.FocusNotifier
      Parameters:
      listener - FocusListener
      See Also:
    • removeFocusListener

      public void removeFocusListener(FieldEvents.FocusListener listener)
      Description copied from interface: FieldEvents.FocusNotifier
      Removes a FocusListener from the Component.
      Specified by:
      removeFocusListener in interface FieldEvents.FocusNotifier
      Parameters:
      listener - FocusListener
      See Also:
    • isRendered

      public boolean isRendered(com.vaadin.flow.component.Component childComponent)
    • setTabCaptionsAsHtml

      public void setTabCaptionsAsHtml(boolean tabCaptionsAsHtml)
      Sets whether HTML is allowed in the tab captions.

      If set to true, the captions are rendered in the browser as HTML and the developer is responsible for ensuring no harmful HTML is used. If set to false, the content is rendered in the browser as plain text.

      The default is false, i.e. render tab captions as plain text

      Parameters:
      tabCaptionsAsHtml - true if the tab captions are rendered as HTML, false if rendered as plain text
    • isTabCaptionsAsHtml

      public boolean isTabCaptionsAsHtml()
      Checks whether HTML is allowed in the tab captions.

      The default is false, i.e. render tab captions as plain text

      Returns:
      true if the tab captions are rendered as HTML, false if rendered as plain text