eu.webtoolkit.jwt
Class WMenuItem

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WMenuItem
Direct Known Subclasses:
WSubMenuItem

public class WMenuItem
extends WObject

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:

To provide another look for the close icon you can override Wt-closeicon CSS class (see WMenu for more details).

See Also:
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

WMenuItem

public WMenuItem(java.lang.CharSequence text,
                 WWidget contents,
                 WMenuItem.LoadPolicy policy)
Creates a new item.

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.


WMenuItem

public WMenuItem(java.lang.CharSequence text,
                 WWidget contents)
Creates a new item.

Calls this(text, contents, WMenuItem.LoadPolicy.LazyLoading)

Method Detail

setText

public void setText(java.lang.CharSequence text)
Sets the text for this item.

Unless a custom path component was defined, the getPathComponent() is also updated based on the new text.

The item widget is updated using updateItemWidget().

See Also:
setPathComponent(String path)

getText

public WString getText()
Returns the text for this item.

See Also:
setText(CharSequence text)

setPathComponent

public void setPathComponent(java.lang.String path)
Sets the path component for this item.

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 '_'.

See Also:
setText(CharSequence text), WMenu.setInternalPathEnabled(String basePath)

getPathComponent

public java.lang.String getPathComponent()
Returns the path component for this item.

You may want to reimplement this to customize the path component set by the item in the application internal path.

See Also:
setPathComponent(String path)

setCloseable

public void setCloseable(boolean closeable)
Make it possible to close this item interactively or by close().

See Also:
close(), isCloseable()

isCloseable

public boolean isCloseable()
Returns whether the item is closeable.

See Also:
setCloseable(boolean closeable)

close

public void close()
Closes this item.

Hides the item widget and emits WMenu#itemClosed() signal. Only closeable items can be closed.

See Also:
setCloseable(boolean closeable), hide()

setHidden

public void setHidden(boolean hidden)
Sets whether the item widget is hidden.

Hides or show the item widget.

See Also:
hide(), show(), isHidden()

isHidden

public boolean isHidden()
Returns whether the item widget is hidden.

See Also:
setHidden(boolean hidden)

hide

public void hide()
Hides the item widget.

This calls setHidden(true).

See Also:
show()

show

public void show()
Shows the item widget.

If the item was previously closed it will be shown.

This calls setHidden(false).

See Also:
hide(), select()

setDisabled

public void setDisabled(boolean disabled)
Enables or disables an item.

A disabled item cannot be activated.

See Also:
enable(), disable()

isDisabled

public boolean isDisabled()
Returns whether an item is enabled.

See Also:
setDisabled(boolean disabled)

enable

public void enable()
Enables the item.

This calls setDisabled(false).

See Also:
disable()

disable

public void disable()
Disables the item.

This calls setDisabled(true).

See Also:
enable()

setToolTip

public void setToolTip(java.lang.CharSequence tip)
Sets a tooltip.

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

See Also:
getToolTip()

getToolTip

public WString getToolTip()
Returns the tooltip.


getMenu

public WMenu getMenu()
Returns the menu.


getContents

public WWidget getContents()
Returns the contents widget for this item.

The contents widget is the widget in the WStackedWidget associated with this item.


getItemWidget

public WWidget getItemWidget()
Returns the widget that represents the item.

This returns the item widget, creating it using createItemWidget() if necessary.


select

public void select()
Selects this item.

If the item was previously closed it will be shown.

See Also:
close()

createItemWidget

protected WWidget createItemWidget()
Creates the widget that represents the item.

The default implementation will return:

A call to createItemWidget() is immediately followed by updateItemWidget().

If you reimplement this method, you should probably also reimplement updateItemWidget().


updateItemWidget

protected void updateItemWidget(WWidget itemWidget)
Updates the widget that represents the item.

The default implementation will cast the itemWidget to a WAnchor, and set the anchor's text and destination according to getText() and getPathComponent().

See Also:
createItemWidget()

renderSelected

protected void renderSelected(boolean selected)
Renders the item as selected or unselected.

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.


activateSignal

protected AbstractSignal activateSignal()
Returns the signal used to activate the item.

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.


closeSignal

protected AbstractSignal closeSignal()
Returns the signal used to close the item.

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.


enableAjax

protected void enableAjax()
Progresses to an Ajax-enabled widget.

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.

See Also:
WMenu.enableAjax()