com.vaadin.ui.


Class TabSheet

java.lang.Object
  com.vaadin.ui.AbstractComponent
      com.vaadin.ui.AbstractComponentContainer
          com.vaadin.ui.TabSheet

All Implemented Interfaces:

FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, MethodEventSource, Paintable, Sizeable, VariableOwner, Component, Component.Focusable, ComponentContainer, Serializable, EventListener

Direct Known Subclasses:

Accordion

public class TabSheet
extends AbstractComponentContainer
implements Component.Focusable, FieldEvents.FocusNotifier, FieldEvents.BlurNotifier

TabSheet component. 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 TabSheet.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 (TabSheet.CloseHandler), which by default removes the tab from the TabSheet. The TabSheet can be styled with the .v-tabsheet, .v-tabsheet-tabs and .v-tabsheet-content styles. Themes may also have pre-defined variations of the tab sheet presentation, such as Reindeer.TABSHEET_BORDERLESS, Runo.TABSHEET_SMALL and several other styles in Reindeer. The current implementation does not load the tabs to the UI before the first time they are shown, but this may change in future releases.

Since:

3.0

Version:

6.8.18

Author:

Vaadin Ltd.

See Also:

Serialized Form

Nested Class Summary
static interface TabSheet.CloseHandler
          CloseHandler is used to process tab closing events.
 class TabSheet.SelectedTabChangeEvent
          Selected tab change event.
static interface TabSheet.SelectedTabChangeListener
          Selected tab change event listener.
static interface TabSheet.Tab
          Tab meta-data for a component in a TabSheet.
 class TabSheet.TabSheetTabImpl
          TabSheet's implementation of TabSheet.Tab - tab metadata.
 
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractComponent
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.ErrorListener, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.terminal.Paintable
Paintable.RepaintRequestEvent, Paintable.RepaintRequestListener
 
Nested classes/interfaces inherited from interface com.vaadin.ui.ComponentContainer
ComponentContainer.ComponentAttachEvent, ComponentContainer.ComponentAttachListener, ComponentContainer.ComponentDetachEvent, ComponentContainer.ComponentDetachListener
 
Field Summary
 
Fields inherited from interface com.vaadin.terminal.Sizeable
SIZE_UNDEFINED, UNIT_SYMBOLS, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
TabSheet()
          Constructs a new Tabsheet.
 
Method Summary
 void addComponent(Component c)
          Adds a new tab into TabSheet.
 void addListener(FieldEvents.BlurListener listener)
          Adds a BlurListener to the Component which gets fired when a Field loses keyboard focus.
 void addListener(FieldEvents.FocusListener listener)
          Adds a FocusListener to the Component which gets fired when a Field receives keyboard focus.
 void addListener(TabSheet.SelectedTabChangeListener listener)
          Adds a tab selection listener
 TabSheet.Tab addTab(Component c)
          Adds a new tab into TabSheet.
 TabSheet.Tab addTab(Component c, int position)
          Adds a new tab into TabSheet.
 TabSheet.Tab addTab(Component c, String caption)
          Adds a new tab into TabSheet.
 TabSheet.Tab addTab(Component c, String caption, Resource icon)
          Adds a new tab into TabSheet.
 TabSheet.Tab addTab(Component c, String caption, Resource icon, int position)
          Adds a new tab into TabSheet.
 boolean areTabsHidden()
          Are the tab selection parts ("tabs") hidden.
 void changeVariables(Object source, Map<String,Object> variables)
          Called when one or more variables handled by the implementing class are changed.
protected  void fireSelectedTabChange()
          Sends an event that the currently selected tab has changed.
 void focus()
          Sets the focus for this component if the component is Focusable.
 int getComponentCount()
          Gets the number of contained components (tabs).
 Iterator<Component> getComponentIterator()
          Gets the component container iterator for going through all the components (tab contents).
 Component getSelectedTab()
          Gets the selected tab content component.
 TabSheet.Tab getTab(Component c)
          Returns the TabSheet.Tab (metadata) for a component.
 TabSheet.Tab getTab(int position)
          Returns the TabSheet.Tab (metadata) for a component.
 String getTabCaption(Component c)
          Deprecated. Use getTab(Component) and TabSheet.Tab.getCaption() instead.
 Resource getTabIcon(Component c)
          Deprecated. Use getTab(Component) and TabSheet.Tab.getIcon() instead.
 int getTabIndex()
          Gets the tabulator index of the Focusable component.
 int getTabPosition(TabSheet.Tab tab)
          Gets the position of the tab
 void hideTabs(boolean tabsHidden)
          Hides or shows the tab selection parts ("tabs").
 void moveComponentsFrom(ComponentContainer source)
          Moves all components from another container to this container.
 void paintContent(PaintTarget target)
          Paints the content of this component.
 void removeComponent(Component c)
          Removes a component and its corresponding tab.
 void removeListener(FieldEvents.BlurListener listener)
          Removes a BlurListener from the Component.
 void removeListener(FieldEvents.FocusListener listener)
          Removes a FocusListener from the Component.
 void removeListener(Paintable.RepaintRequestListener listener)
          Removes repaint request listener.
 void removeListener(TabSheet.SelectedTabChangeListener listener)
          Removes a tab selection listener
 void removeTab(TabSheet.Tab tab)
          Removes a TabSheet.Tab and the component associated with it, as previously added with addTab(Component), addTab(Component, String, Resource) or addComponent(Component).
 void replaceComponent(Component oldComponent, Component newComponent)
          Replaces a component (tab content) with another.
 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.
 void setSelectedTab(Component c)
          Sets the selected tab.
 void setSelectedTab(int position)
          Sets the selected tab, identified by its position.
 void setSelectedTab(TabSheet.Tab tab)
          Sets the selected tab.
 void setTabCaption(Component c, String caption)
          Deprecated. Use getTab(Component) and TabSheet.Tab.setCaption(String) instead.
 void setTabIcon(Component c, Resource icon)
          Deprecated. Use getTab(Component) and TabSheet.Tab.setIcon(Resource) instead.
 void setTabIndex(int tabIndex)
          Sets the tabulator index of the Focusable component.
 void setTabPosition(TabSheet.Tab tab, int position)
          Sets the position of the tab.
 
Methods inherited from class com.vaadin.ui.AbstractComponentContainer
addListener, addListener, attach, detach, fireComponentAttachEvent, fireComponentDetachEvent, removeAllComponents, removeListener, removeListener, requestRepaintAll, setEnabled, setHeight, setWidth
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addListener, addListener, addListener, addListener, addStyleName, childRequestedRepaint, fireComponentErrorEvent, fireComponentEvent, fireEvent, getApplication, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getErrorMessage, getHeight, getHeightUnits, getIcon, getListeners, getLocale, getParent, getStyle, getStyleName, getWidth, getWidthUnits, getWindow, handleError, hasListeners, isEnabled, isImmediate, isReadOnly, isVisible, paint, removeListener, removeListener, removeListener, removeListener, removeListener, removeStyleName, requestRepaint, requestRepaintRequests, setCaption, setComponentError, setData, setDebugId, setDescription, setErrorHandler, setHeight, setHeight, setHeightUnits, setIcon, setImmediate, setLocale, setParent, setReadOnly, setSizeFull, setSizeUndefined, setStyle, setStyleName, setVisible, setWidth, setWidth, setWidthUnits
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, attach, childRequestedRepaint, detach, getApplication, getCaption, getIcon, getLocale, getParent, getStyleName, getWindow, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setParent, setReadOnly, setStyleName, setVisible
 
Methods inherited from interface com.vaadin.terminal.Paintable
addListener, getDebugId, paint, requestRepaint, requestRepaintRequests, setDebugId
 
Methods inherited from interface com.vaadin.terminal.VariableOwner
isImmediate
 
Methods inherited from interface com.vaadin.terminal.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeight, setHeightUnits, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidth, setWidthUnits
 

Constructor Detail

TabSheet

public TabSheet()

Constructs a new Tabsheet. Tabsheet is immediate by default, and the default close handler removes the tab being closed.

Method Detail

getComponentIterator

public Iterator<Component> getComponentIterator()

Gets the component container iterator for going through all the components (tab contents).

Specified by:
getComponentIterator in interface ComponentContainer

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 getComponentIterator().

Returns:
the number of contained components

removeComponent

public void removeComponent(Component c)

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:
c - the component to be removed.
See Also:
ComponentContainer.removeComponent(Component)

removeTab

public void removeTab(TabSheet.Tab tab)

Removes a TabSheet.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:
addTab(Component), addTab(Component, String, Resource), addComponent(Component), removeComponent(Component)

addComponent

public void addComponent(Component c)

Adds a new tab into TabSheet. 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(Component)

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 c,
                           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:
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
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 c,
                           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:
c - 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

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 TabSheet, 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.

paintContent

public void paintContent(PaintTarget target)
                  throws PaintException

Paints the content of this component.

Overrides:
paintContent in class AbstractComponent

Parameters:
target - the paint target
Throws:
PaintException - if the paint operation failed.

areTabsHidden

public boolean areTabsHidden()

Are the tab selection parts ("tabs") hidden.

Returns:
true if the tabs are hidden in the UI

hideTabs

public void hideTabs(boolean tabsHidden)

Hides or shows the tab selection parts ("tabs").

Parameters:
tabsHidden - true if the tabs should be hidden

getTabCaption

@Deprecated
public String getTabCaption(Component c)

Deprecated. Use getTab(Component) and TabSheet.Tab.getCaption() instead.

Gets tab caption. The tab is identified by the tab content component.

Parameters:
c - the component in the tab

setTabCaption

@Deprecated
public void setTabCaption(Component c,
                                     String caption)

Deprecated. Use getTab(Component) and TabSheet.Tab.setCaption(String) instead.

Sets tab caption. The tab is identified by the tab content component.

Parameters:
c - the component in the tab
caption - the caption to set.

getTabIcon

@Deprecated
public Resource getTabIcon(Component c)

Deprecated. Use getTab(Component) and TabSheet.Tab.getIcon() instead.

Gets the icon for a tab. The tab is identified by the tab content component.

Parameters:
c - the component in the tab

setTabIcon

@Deprecated
public void setTabIcon(Component c,
                                  Resource icon)

Deprecated. Use getTab(Component) and TabSheet.Tab.setIcon(Resource) instead.

Sets icon for the given component. The tab is identified by the tab content component.

Parameters:
c - the component in the tab
icon - the icon to set

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

changeVariables

public void changeVariables(Object source,
                            Map<String,Object> variables)

Description copied from interface: VariableOwner

Called when one or more variables handled by the implementing class are changed.

Specified by:
changeVariables in interface VariableOwner
Overrides:
changeVariables in class AbstractComponent

Parameters:
source - the Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.
variables - the Mapping from variable names to new variable values.

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.

addListener

public void addListener(TabSheet.SelectedTabChangeListener listener)

Adds a tab selection listener

Parameters:
listener - the Listener to be added.

removeListener

public void removeListener(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.

removeListener

public void removeListener(Paintable.RepaintRequestListener listener)

Description copied from interface: Paintable

Removes repaint request listener.

Specified by:
removeListener in interface Paintable
Overrides:
removeListener in class AbstractComponent

Parameters:
listener - the listener to be removed.

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:

focus

public void focus()

Description copied from class: AbstractComponent

Sets the focus for this component if the component is Focusable.

Specified by:
focus in interface Component.Focusable
Overrides:
focus in class AbstractComponent

See Also:
FieldEvents, FieldEvents.FocusEvent, FieldEvents.FocusListener, FieldEvents.BlurEvent, FieldEvents.BlurListener

getTabIndex

public int getTabIndex()

Description copied from interface: Component.Focusable

Gets the tabulator index of the Focusable component.

Specified by:
getTabIndex in interface Component.Focusable

Returns:
tab index set for the Focusable component
See Also:
Component.Focusable.setTabIndex(int)

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()

addListener

public void addListener(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:
addListener in interface FieldEvents.BlurNotifier

See Also:
FieldEvents.BlurListener

removeListener

public void removeListener(FieldEvents.BlurListener listener)

Description copied from interface: FieldEvents.BlurNotifier

Removes a BlurListener from the Component.

Specified by:
removeListener in interface FieldEvents.BlurNotifier

See Also:
FieldEvents.BlurListener

addListener

public void addListener(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:
addListener in interface FieldEvents.FocusNotifier

See Also:
FieldEvents.FocusListener

removeListener

public void removeListener(FieldEvents.FocusListener listener)

Description copied from interface: FieldEvents.FocusNotifier

Removes a FocusListener from the Component.

Specified by:
removeListener in interface FieldEvents.FocusNotifier

See Also:
FieldEvents.FocusListener