|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecteu.webtoolkit.jwt.WObject
eu.webtoolkit.jwt.WMenuItem
public class WMenuItem
A single item in a menu.
The item determines the look and behaviour of a single item in a
WMenu.
By default, for enabled menu items a WMenuItem uses a WAnchor
widget. For disabled menu items it uses a WText widget. If item is
closeable, WMenuItem puts these widgets and extra WText
widget (for a close icon) in a WContainerWidget. When the menu
participates in application internal paths (see
WMenu#setInternalPathEnabled()), the anchor references the bookmark URL
corresponding to the getPathComponent()
for the item (see WApplication#getBookmarkUrl()).
To provide another look for the menu items (such as perhaps adding an icon), you can specialize this class, and reimplement the virtual methods:
createItemWidget(): to provide
another widget to represent the item.updateItemWidget()
: to update the widget to reflect item changes, triggered by for example
setText() and
setPathComponent().activateSignal(): to bind
the event for activating the item to something else than the clicked event.closeSignal(): to bind the
event for closing the item to something else than the clicked event.renderSelected(): if you need to do additional styling to reflect a
selection, other than changing style classes.
To provide another look for the close icon you can override
Wt-closeicon CSS class (see WMenu for more details).
WMenu,
WMenu.addItem(WMenuItem item)| Nested Class Summary | |
|---|---|
static class |
WMenuItem.LoadPolicy
Enumeration that determines when contents should be loaded. |
| Constructor Summary | |
|---|---|
WMenuItem(java.lang.CharSequence text,
WWidget contents)
Creates a new item. |
|
WMenuItem(java.lang.CharSequence text,
WWidget contents,
WMenuItem.LoadPolicy policy)
Creates a new item. |
|
| Method Summary | |
|---|---|
protected AbstractSignal |
activateSignal()
Returns the signal used to activate the item. |
void |
close()
Closes this item. |
protected AbstractSignal |
closeSignal()
Returns the signal used to close the item. |
protected WWidget |
createItemWidget()
Creates the widget that represents the item. |
void |
disable()
Disables the item. |
void |
enable()
Enables the item. |
protected void |
enableAjax()
Progresses to an Ajax-enabled widget. |
WWidget |
getContents()
Returns the contents widget for this item. |
WWidget |
getItemWidget()
Returns the widget that represents the item. |
WMenu |
getMenu()
Returns the menu. |
java.lang.String |
getPathComponent()
Returns the path component for this item. |
WString |
getText()
Returns the text for this item. |
WString |
getToolTip()
Returns the tooltip. |
void |
hide()
Hides the item widget. |
boolean |
isCloseable()
Returns whether the item is closeable. |
boolean |
isDisabled()
Returns whether an item is enabled. |
boolean |
isHidden()
Returns whether the item widget is hidden. |
protected void |
renderSelected(boolean selected)
Renders the item as selected or unselected. |
void |
select()
Selects this item. |
void |
setCloseable(boolean closeable)
Make it possible to close this item interactively or by close(). |
void |
setDisabled(boolean disabled)
Enables or disables an item. |
void |
setHidden(boolean hidden)
Sets whether the item widget is hidden. |
void |
setPathComponent(java.lang.String path)
Sets the path component for this item. |
void |
setText(java.lang.CharSequence text)
Sets the text for this item. |
void |
setToolTip(java.lang.CharSequence tip)
Sets a tooltip. |
void |
show()
Shows the item widget. |
protected void |
updateItemWidget(WWidget itemWidget)
Updates the widget that represents the item. |
| Methods inherited from class eu.webtoolkit.jwt.WObject |
|---|
addChild, getId, getObjectName, remove, setObjectName, tr |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WMenuItem(java.lang.CharSequence text,
WWidget contents,
WMenuItem.LoadPolicy policy)
The text specifies the item text. The contents is the widget that must be
shown in the WMenu contents stack when the item is selected.
The load policy specifies whether the contents widgets is transmitted only when it the item is activated for the first time (LazyLoading) or transmitted prior to first rendering.
The getPathComponent() is derived
from text, and can be customized using
setPathComponent().
contents may be 0, in which case no contents is associated
with the item in the contents stack.
public WMenuItem(java.lang.CharSequence text,
WWidget contents)
Calls
this(text, contents, WMenuItem.LoadPolicy.LazyLoading)
| Method Detail |
|---|
public void setText(java.lang.CharSequence text)
Unless a custom path component was defined, the
getPathComponent() is also updated
based on the new text.
The item widget is updated using
updateItemWidget().
setPathComponent(String path)public WString getText()
setText(CharSequence text)public void setPathComponent(java.lang.String path)
The path component is used by the menu item in the application internal
path (see WApplication#getBookmarkUrl()), when internal paths are enabled (see
WMenu#setInternalPathEnabled()) for the menu.
You may specify an empty path to let a menu item be the
"default" menu option.
For example, if WMenu#getInternalBasePath() is "/examples/" and
getPathComponent() for is
"charts/", then the internal path for the item
will be "/examples/charts/".
By default, the path is automatically derived from
getText(). If a literal text is used, the path is based on the text itself, otherwise on
the key. It is converted to lower case, and
replacing white space and special characters with '_'.
setText(CharSequence text),
WMenu.setInternalPathEnabled(String basePath)public java.lang.String getPathComponent()
You may want to reimplement this to customize the path component set by the item in the application internal path.
setPathComponent(String path)public void setCloseable(boolean closeable)
close().
close(),
isCloseable()public boolean isCloseable()
setCloseable(boolean closeable)public void close()
Hides the item widget and emits WMenu#itemClosed() signal. Only closeable items can be closed.
setCloseable(boolean closeable),
hide()public void setHidden(boolean hidden)
Hides or show the item widget.
hide(),
show(),
isHidden()public boolean isHidden()
setHidden(boolean hidden)public void hide()
This calls setHidden(true).
show()public void show()
If the item was previously closed it will be shown.
This calls setHidden(false).
hide(),
select()public void setDisabled(boolean disabled)
A disabled item cannot be activated.
enable(),
disable()public boolean isDisabled()
setDisabled(boolean disabled)public void enable()
This calls setDisabled(false).
disable()public void disable()
This calls setDisabled(true).
enable()public void setToolTip(java.lang.CharSequence tip)
The tooltip is displayed when the cursor hovers over the label of the
item, i.e. WAnchor or WText, depending on whether the
item is enabled or not (see createItemWidget()).
getToolTip()public WString getToolTip()
public WMenu getMenu()
public WWidget getContents()
The contents widget is the widget in the WStackedWidget
associated with this item.
public WWidget getItemWidget()
This returns the item widget, creating it using
createItemWidget() if necessary.
public void select()
If the item was previously closed it will be shown.
close()protected WWidget createItemWidget()
The default implementation will return:
WAnchor if item is not closeable and enabled;WText if item is not closeable and disabled;WContainerWidget with WAnchor or WText (the
label of enabled or disabled item accordingly) and WText (the
close icon) inside if item is closeable.
A call to createItemWidget() is
immediately followed by
updateItemWidget().
If you reimplement this method, you should probably also reimplement
updateItemWidget().
protected void updateItemWidget(WWidget itemWidget)
The default implementation will cast the itemWidget to a
WAnchor, and set the anchor's text and destination according
to getText() and
getPathComponent().
createItemWidget()protected void renderSelected(boolean selected)
The default implementation sets the styleclass for
getItemWidget() to 'item' for
an unselected not closeable, 'itemselected' for selected not
closeable, 'citem' for an unselected closeable and
'citemselected' for selected closeable item.
Note that this method is called from within a stateless slot implementation, and thus should be stateless as well.
protected AbstractSignal activateSignal()
The default implementation will tries to cast the
getItemWidget() or its first child if
item is closeable to a
WInteractWidget and returns the clicked signal.
protected AbstractSignal closeSignal()
The default implementation will tries to cast the
getItemWidget() (or its second child if
item is closeable) to a
WInteractWidget and returns the clicked signal.
protected void enableAjax()
This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the menu and the contents event handling to use AJAX instead of full page reloads.
You may want to reimplement this method if you want to make changes to widget when AJAX is enabled.
WMenu.enableAjax()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||