Package com.vaadin.ui

Class TabSheet

    • Constructor Detail

      • TabSheet

        public TabSheet()
        Constructs a new TabSheet. A TabSheet is immediate by default, and the default close handler removes the tab being closed.
      • TabSheet

        public TabSheet​(Component... components)
        Constructs a new TabSheet containing the given components.
        Parameters:
        components - The components to add to the tab sheet. Each component will be added to a separate tab.
    • Method Detail

      • iterator

        public Iterator<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<Component>
        Returns:
        the unmodifiable Iterator of the tab content components
      • 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.
        Since:
        7.4
      • addTab

        public TabSheet.Tab addTab​(Component c,
                                   String caption)
        Adds a new tab into TabSheet. 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 TabSheet.Tab
      • addTab

        public TabSheet.Tab addTab​(Component c,
                                   String caption,
                                   Resource icon)
        Adds a new tab into TabSheet. 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 TabSheet.Tab
      • addTab

        public TabSheet.Tab addTab​(Component tabComponent,
                                   String caption,
                                   Resource icon,
                                   int position)
        Adds a new tab into TabSheet. 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 TabSheet.Tab
      • addTab

        public TabSheet.Tab addTab​(Component c)
        Adds a new tab into TabSheet. 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 TabSheet.Tab
      • addTab

        public TabSheet.Tab addTab​(Component component,
                                   int position)
        Adds a new tab into TabSheet. 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 TabSheet.Tab
      • areTabsHidden

        @Deprecated
        public boolean areTabsHidden()
        Deprecated.
        as of 7.5, use isTabsVisible() instead
        Are the tab selection parts ("tabs") hidden.
        Returns:
        true if the tabs are hidden in the UI
      • hideTabs

        @Deprecated
        public void hideTabs​(boolean tabsHidden)
        Deprecated.
        as of 7.5, use setTabsVisible(boolean) instead
        Hides or shows the tab selection parts ("tabs").
        Parameters:
        tabsHidden - true if the tabs should be hidden
      • 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
        Since:
        7.5
      • 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
        Since:
        7.5
      • getTab

        public TabSheet.Tab getTab​(Component c)
        Returns the TabSheet.Tab (metadata) for a component. The TabSheet.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 TabSheet.Tab getTab​(int position)
        Returns the TabSheet.Tab (metadata) for a component. The TabSheet.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​(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 -
      • setSelectedTab

        public void setSelectedTab​(TabSheet.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 Component getSelectedTab()
        Gets the selected tab content component.
        Returns:
        the selected tab contents
      • replaceComponent

        public void replaceComponent​(Component oldComponent,
                                     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 TabSheet. 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 void addSelectedTabChangeListener​(TabSheet.SelectedTabChangeListener listener)
        Adds a tab selection listener
        Parameters:
        listener - the Listener to be added.
      • removeSelectedTabChangeListener

        public void removeSelectedTabChangeListener​(TabSheet.SelectedTabChangeListener listener)
        Removes a tab selection listener
        Parameters:
        listener - the Listener to be removed.
      • fireSelectedTabChange

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

        public void setCloseHandler​(TabSheet.CloseHandler handler)
        Provide a custom TabSheet.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​(TabSheet.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​(TabSheet.Tab tab)
        Gets the position of the tab
        Parameters:
        tab - The tab
        Returns:
      • setTabIndex

        public void setTabIndex​(int tabIndex)
        Description copied from interface: Component.Focusable
        Sets the tabulator index of the Focusable component. The tab index property is used to specify the order in which the fields are focused when the user presses the Tab key. Components with a defined tab index are focused sequentially first, and then the components with no tab index.
         Form loginBox = new Form();
         loginBox.setCaption("Login");
         layout.addComponent(loginBox);
        
         // Create the first field which will be focused
         TextField username = new TextField("User name");
         loginBox.addField("username", username);
        
         // Set focus to the user name
         username.focus();
        
         TextField password = new TextField("Password");
         loginBox.addField("password", password);
        
         Button login = new Button("Login");
         loginBox.getFooter().addComponent(login);
        
         // An additional component which natural focus order would
         // be after the button.
         CheckBox remember = new CheckBox("Remember me");
         loginBox.getFooter().addComponent(remember);
        
         username.setTabIndex(1);
         password.setTabIndex(2);
         remember.setTabIndex(3); // Different than natural place
         login.setTabIndex(4);
         

        After all focusable user interface components are done, the browser can begin again from the component with the smallest tab index, or it can take the focus out of the page, for example, to the location bar.

        If the tab index is not set (is set to zero), the default tab order is used. The order is somewhat browser-dependent, but generally follows the HTML structure of the page.

        A negative value means that the component is completely removed from the tabulation order and can not be reached by pressing the Tab key at all.

        Specified by:
        setTabIndex in interface Component.Focusable
        Parameters:
        tabIndex - the tab order of this component. Indexes usually start from 1. Zero means that default tab order should be used. A negative value means that the field should not be included in the tabbing sequence.
        See Also:
        Component.Focusable.getTabIndex()
      • isRendered

        public boolean isRendered​(Component childComponent)
        Description copied from interface: SelectiveRenderer
        Checks if the child component should be rendered (sent to the client side). This method allows hiding a child component from updates and communication to and from the client. It is mostly useful for parents which show only a limited number of their children at any given time and want to allow updates only for the visible children (e.g. TabSheet has one tab open at a time).

        This method can only prevent updates from reaching the client, not force child components to reach the client. If the child is set to visible, returning false will prevent the child from being sent to the client. If a child is set to invisible, this method has no effect.

        Specified by:
        isRendered in interface SelectiveRenderer
        Parameters:
        childComponent - The child component to check
        Returns:
        true if the child component may be sent to the client, false otherwise
      • getState

        protected TabsheetState getState()
        Description copied from class: AbstractComponent
        Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().
        Overrides:
        getState in class AbstractComponent
        Returns:
        updated component shared state
      • readDesign

        public void readDesign​(org.jsoup.nodes.Element design,
                               DesignContext designContext)
        Description copied from interface: Component
        Reads the component state from the given design.

        The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.

        It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.

        This method must not modify the design.

        Specified by:
        readDesign in interface Component
        Overrides:
        readDesign in class AbstractComponent
        Parameters:
        design - The element to obtain the state from
        designContext - The DesignContext instance used for parsing the design
      • writeDesign

        public void writeDesign​(org.jsoup.nodes.Element design,
                                DesignContext designContext)
        Description copied from interface: Component
        Writes the component state to the given design.

        The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.

        This method must not modify the component state.

        Specified by:
        writeDesign in interface Component
        Overrides:
        writeDesign in class AbstractComponent
        Parameters:
        design - The element to write the component state to. Any previous attributes or child nodes are not cleared.
        designContext - The DesignContext instance used for writing the design
      • 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
        Since:
        7.4
      • 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
        Since:
        7.4