public class TabBar extends Composite implements SourcesTabEvents, HasBeforeSelectionHandlers<java.lang.Integer>, HasSelectionHandlers<java.lang.Integer>, ClickListener, KeyboardListener
TabPanel
.
public class TabBarExample implements EntryPoint { public void onModuleLoad() { // Create a tab bar with three items. TabBar bar = new TabBar(); bar.addTab("foo"); bar.addTab("bar"); bar.addTab("baz"); // Hook up a tab listener to do something when the user selects a tab. bar.addSelectionHandler(new SelectionHandler<Integer>() { public void onSelection(SelectionEvent<Integer> event) { // Let the user know what they just did. Window.alert("You clicked tab " + event.getSelectedItem()); } }); // Just for fun, let's disallow selection of 'bar'. bar.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() { public void onBeforeSelection(BeforeSelectionEvent<Integer> event) { if (event.getItem().intValue() == 1) { event.cancel(); } } }); // Add it to the root panel. RootPanel.get().add(bar); } }
Modifier and Type | Class and Description |
---|---|
static interface |
TabBar.Tab
Set of characteristic interfaces supported by
TabBar tabs. |
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
eventsToSink
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
KEY_ALT, KEY_BACKSPACE, KEY_CTRL, KEY_DELETE, KEY_DOWN, KEY_END, KEY_ENTER, KEY_ESCAPE, KEY_HOME, KEY_LEFT, KEY_PAGEDOWN, KEY_PAGEUP, KEY_RIGHT, KEY_SHIFT, KEY_TAB, KEY_UP, MODIFIER_ALT, MODIFIER_CTRL, MODIFIER_META, MODIFIER_SHIFT
Constructor and Description |
---|
TabBar()
Creates an empty tab bar.
|
Modifier and Type | Method and Description |
---|---|
HandlerRegistration |
addBeforeSelectionHandler(BeforeSelectionHandler<java.lang.Integer> handler)
Adds a
BeforeSelectionEvent handler. |
HandlerRegistration |
addSelectionHandler(SelectionHandler<java.lang.Integer> handler)
Adds a
SelectionEvent handler. |
void |
addTab(SafeHtml html)
Adds a new tab with the specified text.
|
void |
addTab(java.lang.String text)
Adds a new tab with the specified text.
|
void |
addTab(java.lang.String text,
boolean asHTML)
Adds a new tab with the specified text.
|
void |
addTab(Widget widget)
Adds a new tab with the specified widget.
|
void |
addTabListener(TabListener listener)
Deprecated.
|
protected SimplePanel |
createTabTextWrapper()
Create a
SimplePanel that will wrap the contents in a tab. |
int |
getSelectedTab()
Gets the tab that is currently selected.
|
TabBar.Tab |
getTab(int index)
Gets the given tab.
|
int |
getTabCount()
Gets the number of tabs present.
|
java.lang.String |
getTabHTML(int index)
Gets the specified tab's HTML.
|
void |
insertTab(SafeHtml html,
int beforeIndex)
Inserts a new tab at the specified index.
|
void |
insertTab(java.lang.String text,
boolean asHTML,
int beforeIndex)
Inserts a new tab at the specified index.
|
void |
insertTab(java.lang.String text,
int beforeIndex)
Inserts a new tab at the specified index.
|
void |
insertTab(Widget widget,
int beforeIndex)
Inserts a new tab at the specified index.
|
protected void |
insertTabWidget(Widget widget,
int beforeIndex)
Inserts a new tab at the specified index.
|
boolean |
isTabEnabled(int index)
Check if a tab is enabled or disabled.
|
void |
onClick(Widget sender)
Deprecated.
add a
BeforeSelectionHandler instead. Alternatively, if
you need to access to the individual tabs, add a click handler to each
TabBar.Tab element instead. |
protected void |
onEnsureDebugId(java.lang.String baseID)
Affected Elements:
-tab# = The element containing the contents of the tab.
-tab-wrapper# = The cell containing the tab at the index.
|
void |
onKeyDown(Widget sender,
char keyCode,
int modifiers)
Deprecated.
add a key down handler to the individual
TabBar.Tab objects
instead. |
void |
onKeyPress(Widget sender,
char keyCode,
int modifiers)
Deprecated.
this method has been doing nothing for the entire last release,
if what you wanted to do was to listen to key press events on tabs, add the
key press handler to the individual tab wrappers instead.
|
void |
onKeyUp(Widget sender,
char keyCode,
int modifiers)
Deprecated.
this method has been doing nothing for the entire last release,
if what you wanted to do was to listen to key up events on tabs, add the
key up handler to the individual tab wrappers instead.
|
void |
removeTab(int index)
Removes the tab at the specified index.
|
void |
removeTabListener(TabListener listener)
Deprecated.
Instead use the
HandlerRegistration.removeHandler()
call on the object returned by an add*Handler method |
boolean |
selectTab(int index)
Programmatically selects the specified tab and fires events.
|
boolean |
selectTab(int index,
boolean fireEvents)
Programmatically selects the specified tab.
|
void |
setTabEnabled(int index,
boolean enabled)
Enable or disable a tab.
|
void |
setTabHTML(int index,
SafeHtml html)
Sets a tab's contents via safe html.
|
void |
setTabHTML(int index,
java.lang.String html)
Sets a tab's contents via HTML.
|
void |
setTabText(int index,
java.lang.String text)
Sets a tab's text contents.
|
claimElement, getWidget, initializeClaimedElement, initWidget, isAttached, onAttach, onBrowserEvent, onDetach, render, render, resolvePotentialElement, setWidget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isOrWasAttached, onLoad, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEvents
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
fireEvent
public HandlerRegistration addBeforeSelectionHandler(BeforeSelectionHandler<java.lang.Integer> handler)
HasBeforeSelectionHandlers
BeforeSelectionEvent
handler.addBeforeSelectionHandler
in interface HasBeforeSelectionHandlers<java.lang.Integer>
handler
- the handlerpublic HandlerRegistration addSelectionHandler(SelectionHandler<java.lang.Integer> handler)
HasSelectionHandlers
SelectionEvent
handler.addSelectionHandler
in interface HasSelectionHandlers<java.lang.Integer>
handler
- the handlerpublic void addTab(SafeHtml html)
html
- the new tab's htmlpublic void addTab(java.lang.String text)
text
- the new tab's textpublic void addTab(java.lang.String text, boolean asHTML)
text
- the new tab's textasHTML
- true
to treat the specified text as htmlpublic void addTab(Widget widget)
widget
- the new tab's widget@Deprecated public void addTabListener(TabListener listener)
addBeforeSelectionHandler(BeforeSelectionHandler)
and addSelectionHandler(SelectionHandler)
insteadSourcesTabEvents
addTabListener
in interface SourcesTabEvents
listener
- the listener interface to addpublic int getSelectedTab()
public final TabBar.Tab getTab(int index)
index
- the tab's indexpublic int getTabCount()
public java.lang.String getTabHTML(int index)
index
- the index of the tab whose HTML is to be retrievedpublic void insertTab(SafeHtml html, int beforeIndex)
html
- the new tab's htmlbeforeIndex
- the index before which this tab will be insertedpublic void insertTab(java.lang.String text, boolean asHTML, int beforeIndex)
text
- the new tab's textasHTML
- true
to treat the specified text as HTMLbeforeIndex
- the index before which this tab will be insertedpublic void insertTab(java.lang.String text, int beforeIndex)
text
- the new tab's textbeforeIndex
- the index before which this tab will be insertedpublic void insertTab(Widget widget, int beforeIndex)
widget
- widget to be used in the new tabbeforeIndex
- the index before which this tab will be insertedpublic boolean isTabEnabled(int index)
index
- the index of the tab@Deprecated public void onClick(Widget sender)
BeforeSelectionHandler
instead. Alternatively, if
you need to access to the individual tabs, add a click handler to each
TabBar.Tab
element instead.ClickListener
onClick
in interface ClickListener
sender
- the widget sending the event.@Deprecated public void onKeyDown(Widget sender, char keyCode, int modifiers)
TabBar.Tab
objects
instead.KeyboardListener
onKeyDown
in interface KeyboardListener
sender
- the widget that was focused when the event occurred.keyCode
- the physical key that was depressed. Constants for this
value are defined in this interface with the KEY prefix.modifiers
- the modifier keys pressed at when the event occurred. This
value is a combination of the bits defined by
KeyboardListener.MODIFIER_SHIFT
,
KeyboardListener.MODIFIER_CTRL
, and
KeyboardListener.MODIFIER_ALT
@Deprecated public void onKeyPress(Widget sender, char keyCode, int modifiers)
KeyboardListener
It should be noted that many browsers do not generate keypress events for
non-printing keyCode values, such as KeyboardListener.KEY_ENTER
or
arrow keys. These keyCodes can be reliably captured either with
KeyboardListener.onKeyDown(Widget, char, int)
or
KeyboardListener.onKeyUp(Widget, char, int)
.
onKeyPress
in interface KeyboardListener
sender
- the widget that was focused when the event occurred.keyCode
- the Unicode character that was generated by the keyboard
action.modifiers
- the modifier keys pressed at when the event occurred. This
value is a combination of the bits defined by
KeyboardListener.MODIFIER_SHIFT
,
KeyboardListener.MODIFIER_CTRL
, and
KeyboardListener.MODIFIER_ALT
@Deprecated public void onKeyUp(Widget sender, char keyCode, int modifiers)
KeyboardListener
onKeyUp
in interface KeyboardListener
sender
- the widget that was focused when the event occurred.keyCode
- the physical key that was released. Constants for this value
are defined in this interface with the KEY prefix.modifiers
- the modifier keys pressed at when the event occurred. This
value is a combination of the bits defined by
KeyboardListener.MODIFIER_SHIFT
,
KeyboardListener.MODIFIER_CTRL
, and
KeyboardListener.MODIFIER_ALT
public void removeTab(int index)
index
- the index of the tab to be removed@Deprecated public void removeTabListener(TabListener listener)
HandlerRegistration.removeHandler()
call on the object returned by an add*Handler methodSourcesTabEvents
removeTabListener
in interface SourcesTabEvents
listener
- the listener interface to removepublic boolean selectTab(int index)
index
- the index of the tab to be selectedtrue
if successful, false
if the change
is denied by the BeforeSelectionHandler
.public boolean selectTab(int index, boolean fireEvents)
index
- the index of the tab to be selectedfireEvents
- true to fire events, false not totrue
if successful, false
if the change
is denied by the BeforeSelectionHandler
.public void setTabEnabled(int index, boolean enabled)
index
- the index of the tab to enable or disableenabled
- true to enable, false to disablepublic void setTabHTML(int index, java.lang.String html)
setTabText(int, String)
or setTabHTML(int, SafeHtml)
whenever possible.index
- the index of the tab whose HTML is to be sethtml
- the tab new HTMLpublic void setTabHTML(int index, SafeHtml html)
index
- the index of the tab whose HTML is to be sethtml
- the tab new HTMLpublic void setTabText(int index, java.lang.String text)
index
- the index of the tab whose text is to be settext
- the object's new textprotected SimplePanel createTabTextWrapper()
SimplePanel
that will wrap the contents in a tab.
Subclasses can use this method to wrap tabs in decorator panels.SimplePanel
to wrap the tab contents, or null to leave
tabs unwrappedprotected void insertTabWidget(Widget widget, int beforeIndex)
widget
- widget to be used in the new tabbeforeIndex
- the index before which this tab will be insertedprotected void onEnsureDebugId(java.lang.String baseID)
onEnsureDebugId
in class UIObject
baseID
- the base ID used by the main elementUIObject.onEnsureDebugId(String)