eu.webtoolkit.jwt
Class WTabWidget

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WWidget
          extended by eu.webtoolkit.jwt.WCompositeWidget
              extended by eu.webtoolkit.jwt.WTabWidget

public class WTabWidget
extends WCompositeWidget

A widget that organizes contents in tab panes.

This widget combines a horizontal WMenu with a WStackedWidget , and a tab-like look.

A tab widget will place the tab bar on top of the contents, and fit the contents below it.

Usage example:

 {
        @code
        WTabWidget examples = new WTabWidget(this);
 
        examples.addTab(helloWorldExample(), "Hello World");
        examples.addTab(chartExample(), "Charts");
        examples.addTab(new WText("A WText"), "WText");
 
        examples.currentChanged().addListener(this, new Signal.Listener() {
                public void trigger() {
                        //custom code
                }
        });
        examples.setInternalPathEnabled();
        examples.setInternalBasePath("/examples");
 }
 

CSS

The tab widget is styled by the current CSS theme. The look (of the header) can be overridden using the Wt-tabs CSS class and the following selectors:

 .Wt-tabs ul        : the list
 .Wt-tabs li        : a list item
 .Wt-tabs span      : outer span of a list item
 .Wt-span span span : inner span of a list item
 

An example WTabWidget (default)

An example WTabWidget (default)

An example WTabWidget (polished)

An example WTabWidget (polished)


Nested Class Summary
static class WTabWidget.LoadPolicy
          When should the contents be loaded ?
 
Constructor Summary
WTabWidget()
          Creates a new tab widget.
WTabWidget(java.util.EnumSet<AlignmentFlag> layoutAlignment)
          Creates a new tab widget (indicating layout alignment) (deprecated).
WTabWidget(java.util.EnumSet<AlignmentFlag> layoutAlignment, WContainerWidget parent)
          Deprecated. Since JWt 3.1.1, the layoutAlignment is no longer needed and its value is ignored
WTabWidget(WContainerWidget parent)
          Creates a new tab widget.
 
Method Summary
 WMenuItem addTab(WWidget child, java.lang.CharSequence label)
          Adds a new tab, with child as content, and the given label.
 WMenuItem addTab(WWidget child, java.lang.CharSequence label, WTabWidget.LoadPolicy loadPolicy)
          Adds a new tab, with child as content, and the given label.
 void closeTab(int index)
          Closes a tab at index.
 Signal1<java.lang.Integer> currentChanged()
          Signal emitted when the user activates a tab.
 WStackedWidget getContentsStack()
          Returns the contents stack.
 int getCount()
          Returns the number of tabs.
 int getCurrentIndex()
          Returns the index of the activated tab.
 WWidget getCurrentWidget()
          Returns the widget of the activated tab.
 int getIndexOf(WWidget widget)
          Returns the index of the tab of the given content widget.
 java.lang.String getInternalBasePath()
          Returns the internal base path.
 WString getTabText(int index)
          Returns the label for a tab.
 WString getTabToolTip(int index)
          Returns the tooltip for a tab.
 WWidget getWidget(int index)
          Returns the content widget at the given tab index.
 boolean isInternalPathEnabled()
          Returns whether internal paths are enabled.
 boolean isTabCloseable(int index)
          Returns whether a tab is closeable.
 boolean isTabEnabled(int index)
          Returns whether a tab is enabled.
 boolean isTabHidden(int index)
          Returns whether a tab is hidden.
 void removeTab(WWidget child)
          Removes a tab item.
 void setCurrentIndex(int index)
          Activates the tab at index.
 void setCurrentWidget(WWidget widget)
          Activates the tab showing the given widget.
 void setInternalBasePath(java.lang.String path)
          Sets the internal base path.
 void setInternalPathEnabled()
          Enables internal paths for items.
 void setInternalPathEnabled(java.lang.String basePath)
          Enables internal paths for items.
 void setTabCloseable(int index, boolean closeable)
          Make it possible to close a tab interactively or by closeTab.
 void setTabEnabled(int index, boolean enable)
          Enables or disables a tab.
 void setTabHidden(int index, boolean hidden)
          Hides or shows a tab.
 void setTabText(int index, java.lang.CharSequence label)
          Changes the label for a tab.
 void setTabToolTip(int index, java.lang.CharSequence tip)
          Sets the tooltip for a tab.
 Signal1<java.lang.Integer> tabClosed()
          Signal emitted when the user closes a tab.
 
Methods inherited from class eu.webtoolkit.jwt.WCompositeWidget
addStyleClass, boxBorder, boxPadding, callJavaScriptMember, doJavaScript, enableAjax, find, getAttributeValue, getClearSides, getDecorationStyle, getFloatSide, getHeight, getId, getImplementation, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, isDisabled, isEnabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isVisible, load, propagateSetEnabled, refresh, remove, removeStyleClass, resize, setAttributeValue, setClearSides, setDecorationStyle, setDisabled, setFloatSide, setHidden, setHiddenKeepsGeometry, setId, setImplementation, setInline, setJavaScriptMember, setLineHeight, setMargin, setMaximumSize, setMinimumSize, setOffsets, setPopup, setPositionScheme, setSelectable, setStyleClass, setTabIndex, setToolTip, setVerticalAlignment
 
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addStyleClass, animateHide, animateShow, containsExposed, disable, dropEvent, enable, getDrop, getJsRef, getParent, hide, htmlText, isLayoutSizeAware, isRendered, layoutSizeChanged, positionAt, positionAt, removeStyleClass, resize, setClearSides, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
 
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getObjectName, setObjectName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WTabWidget

public WTabWidget(WContainerWidget parent)
Creates a new tab widget.


WTabWidget

public WTabWidget()
Creates a new tab widget.

Calls this((WContainerWidget)null)


WTabWidget

public WTabWidget(java.util.EnumSet<AlignmentFlag> layoutAlignment,
                  WContainerWidget parent)
Deprecated. Since JWt 3.1.1, the layoutAlignment is no longer needed and its value is ignored

Creates a new tab widget (indicating layout alignment) (deprecated).


WTabWidget

public WTabWidget(java.util.EnumSet<AlignmentFlag> layoutAlignment)
Creates a new tab widget (indicating layout alignment) (deprecated).

Calls this(layoutAlignment, (WContainerWidget)null)

Method Detail

addTab

public WMenuItem addTab(WWidget child,
                        java.lang.CharSequence label,
                        WTabWidget.LoadPolicy loadPolicy)
Adds a new tab, with child as content, and the given label.

Returns the menu item that implements the tab item.


addTab

public final WMenuItem addTab(WWidget child,
                              java.lang.CharSequence label)
Adds a new tab, with child as content, and the given label.

Returns addTab(child, label, WTabWidget.LoadPolicy.LazyLoading)


removeTab

public void removeTab(WWidget child)
Removes a tab item.

The widget itself is not deleted.

See Also:
WMenu.removeItem(WMenuItem item)

getCount

public int getCount()
Returns the number of tabs.


getWidget

public WWidget getWidget(int index)
Returns the content widget at the given tab index.


getIndexOf

public int getIndexOf(WWidget widget)
Returns the index of the tab of the given content widget.

If the widget is not in this tab widget, then -1 is returned.


setCurrentIndex

public void setCurrentIndex(int index)
Activates the tab at index.


getCurrentIndex

public int getCurrentIndex()
Returns the index of the activated tab.


setCurrentWidget

public void setCurrentWidget(WWidget widget)
Activates the tab showing the given widget.


getCurrentWidget

public WWidget getCurrentWidget()
Returns the widget of the activated tab.


setTabEnabled

public void setTabEnabled(int index,
                          boolean enable)
Enables or disables a tab.

Enables or disables the tab at index. A disabled tab cannot be activated.


isTabEnabled

public boolean isTabEnabled(int index)
Returns whether a tab is enabled.


setTabHidden

public void setTabHidden(int index,
                         boolean hidden)
Hides or shows a tab.

Hides or shows the tab at index.


isTabHidden

public boolean isTabHidden(int index)
Returns whether a tab is hidden.


setTabCloseable

public void setTabCloseable(int index,
                            boolean closeable)
Make it possible to close a tab interactively or by closeTab.

A tab that has been closed is marked as hidden, but not removed from the menu.

See Also:
removeTab(WWidget child)

isTabCloseable

public boolean isTabCloseable(int index)
Returns whether a tab is closeable.

See Also:
setTabCloseable(int index, boolean closeable)

setTabText

public void setTabText(int index,
                       java.lang.CharSequence label)
Changes the label for a tab.


getTabText

public WString getTabText(int index)
Returns the label for a tab.

See Also:
setTabText(int index, CharSequence label)

setTabToolTip

public void setTabToolTip(int index,
                          java.lang.CharSequence tip)
Sets the tooltip for a tab.

The tooltip is shown when the user hovers over the label.


getTabToolTip

public WString getTabToolTip(int index)
Returns the tooltip for a tab.

See Also:
setTabToolTip(int index, CharSequence tip)

setInternalPathEnabled

public void setInternalPathEnabled(java.lang.String basePath)
Enables internal paths for items.

The menu participates in the internal path by changing the internal path when an item has been selected, and listening for path changes to react to path selections. As a consequence this allows the user to bookmark the current menu selection and revisit it later, use back/forward buttons to navigate through history of visited menu items, and allows indexing of pages.

For each menu item, WMenuItem#getPathComponent() is appended to the basePath, which defaults to the internal path ( WApplication#getBookmarkUrl()). A '/' is appended to the base path, to turn it into a folder, if needed.

By default, menu interaction does not change the application internal path.

See Also:
WMenuItem.setPathComponent(String path)

setInternalPathEnabled

public final void setInternalPathEnabled()
Enables internal paths for items.

Calls setInternalPathEnabled("")


isInternalPathEnabled

public boolean isInternalPathEnabled()
Returns whether internal paths are enabled.

See Also:
WMenu.setInternalPathEnabled(String basePath)

setInternalBasePath

public void setInternalBasePath(java.lang.String path)
Sets the internal base path.

A '/' is appended to turn it into a folder, if needed.

See Also:
WMenu.setInternalPathEnabled(String basePath), WMenu.getInternalBasePath()

getInternalBasePath

public java.lang.String getInternalBasePath()
Returns the internal base path.

The default value is the application's internalPath ( WApplication#getBookmarkUrl()) that was recorded when WMenu#setInternalPathEnabled() was called, and together with each WMenuItem#getPathComponent() determines the paths for each item.

For example, if WMenu#getInternalBasePath() is "/examples/" and pathComponent() for a particular item is "charts/" , then the internal path for that item will be "/examples/charts/".

See Also:
WMenu.setInternalPathEnabled(String basePath)

currentChanged

public Signal1<java.lang.Integer> currentChanged()
Signal emitted when the user activates a tab.

The index of the newly activated tab is passed as an argument.


closeTab

public void closeTab(int index)
Closes a tab at index.

A tab that has been closed is marked as hidden, but not removed from the menu.

See Also:
removeTab(WWidget child), setTabHidden(int index, boolean hidden)

tabClosed

public Signal1<java.lang.Integer> tabClosed()
Signal emitted when the user closes a tab.

The index of the closed tab is passed as an argument.

See Also:
closeTab(int index), setTabCloseable(int index, boolean closeable)

getContentsStack

public WStackedWidget getContentsStack()
Returns the contents stack.

The tab widget is implemented as a WMenu + WStackedWidget which displays the contents. This method returns a reference to this contents stack.