Class CmsTextBox

java.lang.Object
com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Composite
org.opencms.gwt.client.ui.input.CmsTextBox
All Implemented Interfaces:
com.google.gwt.event.dom.client.HasBlurHandlers, com.google.gwt.event.dom.client.HasClickHandlers, com.google.gwt.event.dom.client.HasFocusHandlers, com.google.gwt.event.dom.client.HasKeyPressHandlers, com.google.gwt.event.logical.shared.HasAttachHandlers, com.google.gwt.event.logical.shared.HasValueChangeHandlers<String>, com.google.gwt.event.shared.HasHandlers, com.google.gwt.user.client.EventListener, com.google.gwt.user.client.ui.HasVisibility, com.google.gwt.user.client.ui.IsRenderable, com.google.gwt.user.client.ui.IsWidget, I_CmsHasInit, I_CmsFormWidget, I_CmsHasBlur, I_CmsHasGhostValue
Direct Known Subclasses:
CmsFocusAwareTextBox

public class CmsTextBox extends com.google.gwt.user.client.ui.Composite implements I_CmsFormWidget, I_CmsHasInit, com.google.gwt.event.dom.client.HasFocusHandlers, com.google.gwt.event.dom.client.HasBlurHandlers, com.google.gwt.event.logical.shared.HasValueChangeHandlers<String>, com.google.gwt.event.dom.client.HasKeyPressHandlers, com.google.gwt.event.dom.client.HasClickHandlers, I_CmsHasBlur, I_CmsHasGhostValue
Basic text box class for forms.
Since:
8.0.0
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject

    com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled

    Nested classes/interfaces inherited from interface org.opencms.gwt.client.ui.input.I_CmsFormWidget

    I_CmsFormWidget.FieldType
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final I_CmsInputCss
    The CSS bundle used for this widget.
    protected String
    The ghost value.
    protected com.google.gwt.user.client.ui.TextBox
    The text box used internally by this widget.
    protected static final int[]
    Key codes for functional keys.
    static final String
    The widget type identifier for this widget.

    Fields inherited from class com.google.gwt.user.client.ui.UIObject

    DEBUG_ID_PREFIX
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new instance of this widget.
    CmsTextBox(com.google.gwt.user.client.ui.TextBox textbox)
    Creates a new text box based on an underlying GWT text box instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.google.gwt.event.shared.HandlerRegistration
    addBlurHandler(com.google.gwt.event.dom.client.BlurHandler handler)
     
    com.google.gwt.event.shared.HandlerRegistration
    addClickHandler(com.google.gwt.event.dom.client.ClickHandler handler)
     
    com.google.gwt.event.shared.HandlerRegistration
    addFocusHandler(com.google.gwt.event.dom.client.FocusHandler handler)
     
    com.google.gwt.event.shared.HandlerRegistration
    addKeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler handler)
     
    com.google.gwt.event.shared.HandlerRegistration
    addKeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler handler)
    Adds a handler for the keyup event.
    com.google.gwt.event.shared.HandlerRegistration
    addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler<String> handler)
     
    void
    Makes the widget lose focus.
    Sets the background color to white.
    protected void
    Fires a value change event.
    protected void
    fireValueChangedEvent(boolean inhibitValidation)
    Helper method for firing a 'value changed' event.
    Returns the "apparent value", i.e.
    Returns the type of data this widget produces.
    Gets the selected/entered value from the widget.
    Gets the current value of the widget as a string.
    Returns the HTML id of the internal textbox used by this widget.
    Returns the text in the text box.
    com.google.gwt.user.client.ui.TextBox
    Returns the Textbox of this widget.
    com.google.gwt.user.client.ui.FlowPanel
    Returns the Panel of this widget.
    boolean
    Returns true if this textbox has an error set.
    protected void
    Hides the error for this textbox.
    static void
    Initializes this class.
    boolean
    Gets whether this widget is enabled.
    protected boolean
    isNavigationKey(int keyCode)
    Checks if the given key code represents a functional key.
    boolean
    Returns the preventShowError.
    boolean
    Returns the read only flag.
    boolean
    Returns if the text box is set to trigger the value changed event on key press and not on blur only.
    void
    onBrowserEvent(com.google.gwt.user.client.Event event)
     
    void
    Resets the widget to its default state.
    void
    Selects text in the text box.
    void
    Call this when auto hiding parents are shown.
    void
    Sets the changed style on the text box.
    void
    setEnabled(boolean enabled)
    Enables or disables the widget.
    void
    setErrorMessage(String errorMessage)
    Sets the error message for this widget.
    void
    Sets the width of the error message for this textbox.
    void
    setFocus(boolean focused)
    Sets the focus on the text box.
    void
    Sets the current value of the widget as a string.
    void
    setGhostMode(boolean ghostMode)
    Enables or disables ghost mode.
    void
    setGhostModeClear(boolean clearOnChangeMode)
    Sets if the input field should be cleared when leaving the ghost mode.
    void
    setGhostStyleEnabled(boolean enabled)
    Enables or disables the "ghost mode" style.
    void
    setGhostValue(String value, boolean ghostMode)
    Sets the "ghost value" of the widget and optionally sets it to "ghost mode".
    void
    setInhibitValidationForKeypresses(boolean inhibitValidationForKeypresses)
    Sets the 'inhibitValidationForKeypresses' flag.
    void
    Sets the name of the input box.
    void
    setPreventShowError(boolean preventShowError)
    Sets the preventShowError.
    void
    setReadOnly(boolean readOnly)
    Enables or disables read-only mode.
    void
    setTriggerChangeOnKeyPress(boolean triggerOnKeyPress)
    Sets if the value changed event should be triggered on key press and not on blur only.
    protected void
    Shows the error for this textbox.

    Methods inherited from class com.google.gwt.user.client.ui.Composite

    claimElement, getWidget, initializeClaimedElement, initWidget, isAttached, onAttach, onDetach, render, render, resolvePotentialElement, setWidget

    Methods inherited from class com.google.gwt.user.client.ui.Widget

    addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isOrWasAttached, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEvents

    Methods inherited from class com.google.gwt.user.client.ui.UIObject

    addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.google.gwt.event.shared.HasHandlers

    fireEvent
  • Field Details

  • Constructor Details

    • CmsTextBox

      public CmsTextBox()
      Constructs a new instance of this widget.
    • CmsTextBox

      public CmsTextBox(com.google.gwt.user.client.ui.TextBox textbox)
      Creates a new text box based on an underlying GWT text box instance.

      Parameters:
      textbox - the GWT text box instance to wrap
  • Method Details

    • initClass

      public static void initClass()
      Initializes this class.

    • addBlurHandler

      public com.google.gwt.event.shared.HandlerRegistration addBlurHandler(com.google.gwt.event.dom.client.BlurHandler handler)
      Specified by:
      addBlurHandler in interface com.google.gwt.event.dom.client.HasBlurHandlers
      See Also:
      • HasBlurHandlers.addBlurHandler(com.google.gwt.event.dom.client.BlurHandler)
    • addClickHandler

      public com.google.gwt.event.shared.HandlerRegistration addClickHandler(com.google.gwt.event.dom.client.ClickHandler handler)
      Specified by:
      addClickHandler in interface com.google.gwt.event.dom.client.HasClickHandlers
      See Also:
      • HasClickHandlers.addClickHandler(com.google.gwt.event.dom.client.ClickHandler)
    • addFocusHandler

      public com.google.gwt.event.shared.HandlerRegistration addFocusHandler(com.google.gwt.event.dom.client.FocusHandler handler)
      Specified by:
      addFocusHandler in interface com.google.gwt.event.dom.client.HasFocusHandlers
      See Also:
      • HasFocusHandlers.addFocusHandler(com.google.gwt.event.dom.client.FocusHandler)
    • addKeyPressHandler

      public com.google.gwt.event.shared.HandlerRegistration addKeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler handler)
      Specified by:
      addKeyPressHandler in interface com.google.gwt.event.dom.client.HasKeyPressHandlers
      See Also:
      • HasKeyPressHandlers.addKeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler)
    • addKeyUpHandler

      public com.google.gwt.event.shared.HandlerRegistration addKeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler handler)
      Adds a handler for the keyup event.

      Parameters:
      handler - the handler
      Returns:
      the handler registration
    • addValueChangeHandler

      public com.google.gwt.event.shared.HandlerRegistration addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler<String> handler)
      Specified by:
      addValueChangeHandler in interface com.google.gwt.event.logical.shared.HasValueChangeHandlers<String>
      See Also:
      • HasValueChangeHandlers.addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler)
    • blur

      public void blur()
      Description copied from interface: I_CmsHasBlur
      Makes the widget lose focus.

      Specified by:
      blur in interface I_CmsHasBlur
      See Also:
    • colorWhite

      Sets the background color to white.

      Returns:
      this widget
    • getApparentValue

      Description copied from interface: I_CmsFormWidget
      Returns the "apparent value", i.e. either the real value if available, or else the ghost value if available, or null otherwise.

      Specified by:
      getApparentValue in interface I_CmsFormWidget
      Returns:
      the apparent value
      See Also:
    • getFieldType

      Description copied from interface: I_CmsFormWidget
      Returns the type of data this widget produces.
      Specified by:
      getFieldType in interface I_CmsFormWidget
      Returns:
      the data type
      See Also:
    • getFormValue

      public Object getFormValue()
      Description copied from interface: I_CmsFormWidget
      Gets the selected/entered value from the widget.

      Specified by:
      getFormValue in interface I_CmsFormWidget
      Returns:
      the value
      See Also:
    • getFormValueAsString

      Description copied from interface: I_CmsFormWidget
      Gets the current value of the widget as a string.

      Specified by:
      getFormValueAsString in interface I_CmsFormWidget
      Returns:
      the current value of the widget
      See Also:
    • getId

      public String getId()
      Returns the HTML id of the internal textbox used by this widget.

      Returns:
      the HTML id of the internal textbox used by this widget
    • getText

      public String getText()
      Returns the text in the text box.

      Returns:
      the text
    • getTextBox

      public com.google.gwt.user.client.ui.TextBox getTextBox()
      Returns the Textbox of this widget.

      Returns:
      the CmsTextBox
    • getTextBoxContainer

      public com.google.gwt.user.client.ui.FlowPanel getTextBoxContainer()
      Returns the Panel of this widget.

      Returns:
      the Panel
    • hasError

      public boolean hasError()
      Returns true if this textbox has an error set.

      Returns:
      true if this textbox has an error set
    • isEnabled

      public boolean isEnabled()
      Gets whether this widget is enabled.
      Specified by:
      isEnabled in interface I_CmsFormWidget
      Returns:
      true if the widget is enabled
    • isPreventShowError

      public boolean isPreventShowError()
      Returns the preventShowError.

      Returns:
      the preventShowError
    • isReadOnly

      public boolean isReadOnly()
      Returns the read only flag.

      Returns:
      true if this text box is only readable
    • isTriggerChangeOnKeyPress

      public boolean isTriggerChangeOnKeyPress()
      Returns if the text box is set to trigger the value changed event on key press and not on blur only.

      Returns:
      true if the text box is set to trigger the value changed event on key press
    • onBrowserEvent

      public void onBrowserEvent(com.google.gwt.user.client.Event event)
      Specified by:
      onBrowserEvent in interface com.google.gwt.user.client.EventListener
      Overrides:
      onBrowserEvent in class com.google.gwt.user.client.ui.Composite
      See Also:
      • Composite.onBrowserEvent(com.google.gwt.user.client.Event)
    • reset

      public void reset()
      Description copied from interface: I_CmsFormWidget
      Resets the widget to its default state.
      Specified by:
      reset in interface I_CmsFormWidget
      See Also:
    • selectAll

      public void selectAll()
      Selects text in the text box.

    • setAutoHideParent

      public void setAutoHideParent(I_CmsAutoHider autoHideParent)
      Description copied from interface: I_CmsFormWidget
      Call this when auto hiding parents are shown.

      Specified by:
      setAutoHideParent in interface I_CmsFormWidget
      Parameters:
      autoHideParent - the auto hide parent
      See Also:
    • setChangedStyle

      public void setChangedStyle()
      Sets the changed style on the text box.

    • setEnabled

      public void setEnabled(boolean enabled)
      Description copied from interface: I_CmsFormWidget
      Enables or disables the widget.

      Specified by:
      setEnabled in interface I_CmsFormWidget
      Parameters:
      enabled - if true, the widget will be enabled, else disabled
      See Also:
    • setErrorMessage

      public void setErrorMessage(String errorMessage)
      Description copied from interface: I_CmsFormWidget
      Sets the error message for this widget.

      If the error message is null, no error message will be displayed.

      Specified by:
      setErrorMessage in interface I_CmsFormWidget
      Parameters:
      errorMessage - an error message or null
      See Also:
    • setErrorMessageWidth

      public void setErrorMessageWidth(String width)
      Sets the width of the error message for this textbox.

      Parameters:
      width - the object's new width, in CSS units (e.g. "10px", "1em")
    • setFocus

      public void setFocus(boolean focused)
      Sets the focus on the text box.

      Parameters:
      focused - signals if the focus should be set
    • setFormValueAsString

      public void setFormValueAsString(String newValue)
      Description copied from interface: I_CmsFormWidget
      Sets the current value of the widget as a string.

      Specified by:
      setFormValueAsString in interface I_CmsFormWidget
      Parameters:
      newValue - the new value of the widget
      See Also:
    • setGhostMode

      public void setGhostMode(boolean ghostMode)
      Enables or disables ghost mode.

      Specified by:
      setGhostMode in interface I_CmsHasGhostValue
      Parameters:
      ghostMode - if true, enables ghost mode, else disables it
    • setGhostModeClear

      public void setGhostModeClear(boolean clearOnChangeMode)
      Sets if the input field should be cleared when leaving the ghost mode.

      Parameters:
      clearOnChangeMode - true to clear on leaving the ghost mode
    • setGhostStyleEnabled

      public void setGhostStyleEnabled(boolean enabled)
      Enables or disables the "ghost mode" style.

      This *only* changes the style, not the actual mode.

      Parameters:
      enabled - true if the ghost mode style should be enabled, false if it should be disabled
    • setGhostValue

      public void setGhostValue(String value, boolean ghostMode)
      Description copied from interface: I_CmsHasGhostValue
      Sets the "ghost value" of the widget and optionally sets it to "ghost mode".

      "Ghost mode" can be used to show the user the value (called "ghost value") which will be used if he either doesn't choose an option in the widget, or explicitly chooses an "empty" or "default" option.

      Specified by:
      setGhostValue in interface I_CmsHasGhostValue
      Parameters:
      value - the ghost value
      ghostMode - if true, sets the widget to ghost mode
      See Also:
    • setInhibitValidationForKeypresses

      public void setInhibitValidationForKeypresses(boolean inhibitValidationForKeypresses)
      Sets the 'inhibitValidationForKeypresses' flag.

      Parameters:
      inhibitValidationForKeypresses - the new flag value
    • setName

      public void setName(String name)
      Sets the name of the input box.
      Parameters:
      name - of the input box
    • setPreventShowError

      public void setPreventShowError(boolean preventShowError)
      Sets the preventShowError.

      Parameters:
      preventShowError - the preventShowError to set
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Enables or disables read-only mode.

      Parameters:
      readOnly - if true, enables read-only mode, else disables it
    • setTriggerChangeOnKeyPress

      public void setTriggerChangeOnKeyPress(boolean triggerOnKeyPress)
      Sets if the value changed event should be triggered on key press and not on blur only.

      Parameters:
      triggerOnKeyPress - true if the value changed event should be triggered on key press
    • fireValueChangedEvent

      protected void fireValueChangedEvent()
      Fires a value change event.

    • fireValueChangedEvent

      protected void fireValueChangedEvent(boolean inhibitValidation)
      Helper method for firing a 'value changed' event.

      Parameters:
      inhibitValidation - if true, some additional information will be added to the event to ask event handlers to not perform any validation directly
    • hideError

      protected void hideError()
      Hides the error for this textbox.

    • isNavigationKey

      protected boolean isNavigationKey(int keyCode)
      Checks if the given key code represents a functional key.

      Parameters:
      keyCode - the key code to check
      Returns:
      true if the given key code represents a functional key
    • showError

      protected void showError()
      Shows the error for this textbox.