eu.webtoolkit.jwt
Class WInPlaceEdit

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.WInPlaceEdit

public class WInPlaceEdit
extends WCompositeWidget

A widget that provides in-place-editable text.

The WInPlaceEdit provides a text that may be edited in place by the user by clicking on it. When clicked, the text turns into a line edit, with optionally a save and cancel button (see setButtonsEnabled()).

When the user saves the edit, the valueChanged() signal is emitted.

Usage example:

 {
        @code
        WContainerWidget w = new WContainerWidget();
        new WText("Name: ", w);
        WInPlaceEdit edit = new WInPlaceEdit("Bob Smith", w);
        edit.setStyleClass("inplace");
 }
 

This code will produce an edit that looks like:

WInPlaceEdit text mode

WInPlaceEdit text mode

When the text is clicked, the edit will expand to become:
WInPlaceEdit edit mode

WInPlaceEdit edit mode

CSS

A WInPlaceEdit widget renders as a <span> containing a WText, a WLineEdit and optional buttons ( WPushButton). All these widgets may be styled as such. It does not provide style information.

In particular, you may want to provide a visual indication that the text is editable e.g. using a hover effect:

CSS stylesheet:

 .inplace span:hover {
     background-color: gray;
  }
 
 


Constructor Summary
WInPlaceEdit(java.lang.CharSequence text)
          Creates an in-place edit with the given text.
WInPlaceEdit(java.lang.CharSequence text, WContainerWidget parent)
          Creates an in-place edit with the given text.
 
Method Summary
 WPushButton getCancelButton()
          Returns the cancel button.
 WString getEmptyText()
          Returns the empty text to be shown when the field is empty and not being edited.
 WLineEdit getLineEdit()
          Returns the line edit.
 WPushButton getSaveButton()
          Returns the save button.
 WString getText()
          Returns the current value.
 WText getTextWidget()
          Returns the WText widget that renders the current string.
 void setButtonsEnabled()
          Displays the Save and 'Cancel' button during editing.
 void setButtonsEnabled(boolean enabled)
          Displays the Save and 'Cancel' button during editing.
 void setEmptyText(java.lang.CharSequence emptyText)
          Sets the empty text to be shown when the field is empty and not being edited.
 void setText(java.lang.CharSequence text)
          Sets the current value.
 Signal1<WString> valueChanged()
          Signal emitted when the value has been changed.
 
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

WInPlaceEdit

public WInPlaceEdit(java.lang.CharSequence text,
                    WContainerWidget parent)
Creates an in-place edit with the given text.


WInPlaceEdit

public WInPlaceEdit(java.lang.CharSequence text)
Creates an in-place edit with the given text.

Calls this(text, (WContainerWidget)null)

Method Detail

getText

public WString getText()
Returns the current value.

See Also:
setText(CharSequence text)

setText

public void setText(java.lang.CharSequence text)
Sets the current value.

See Also:
getText()

setEmptyText

public void setEmptyText(java.lang.CharSequence emptyText)
Sets the empty text to be shown when the field is empty and not being edited.

See Also:
getEmptyText()

getEmptyText

public WString getEmptyText()
Returns the empty text to be shown when the field is empty and not being edited.

See Also:
setEmptyText(CharSequence emptyText)

getLineEdit

public WLineEdit getLineEdit()
Returns the line edit.

You may use this for example to set a validator on the line edit.


getTextWidget

public WText getTextWidget()
Returns the WText widget that renders the current string.

You may use this for example to set the text format of the displayed string.


getSaveButton

public WPushButton getSaveButton()
Returns the save button.

This method returns null if the buttons were disabled.

See Also:
getCancelButton(), setButtonsEnabled(boolean enabled)

getCancelButton

public WPushButton getCancelButton()
Returns the cancel button.

This method returns null if the buttons were disabled.

See Also:
getSaveButton(), setButtonsEnabled(boolean enabled)

valueChanged

public Signal1<WString> valueChanged()
Signal emitted when the value has been changed.

The signal argument provides the new value.


setButtonsEnabled

public void setButtonsEnabled(boolean enabled)
Displays the Save and 'Cancel' button during editing.

By default, the Save and Cancel buttons are shown. Call this function with enabled = false to only show a line edit.

In this mode, the enter key or any event that causes focus to be lost saves the value while the escape key cancels the editing.


setButtonsEnabled

public final void setButtonsEnabled()
Displays the Save and 'Cancel' button during editing.

Calls setButtonsEnabled(true)