Class 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<java.lang.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<java.lang.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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static I_CmsInputCss CSS
      The CSS bundle used for this widget.
      protected java.lang.String m_ghostValue
      The ghost value.
      protected com.google.gwt.user.client.ui.TextBox m_textbox
      The text box used internally by this widget.
      protected static int[] NAVIGATION_CODES
      Key codes for functional keys.
      static java.lang.String WIDGET_TYPE
      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
      CmsTextBox()
      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

      All Methods Static Methods Instance Methods Concrete Methods 
      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<java.lang.String> handler)  
      void blur()
      Makes the widget lose focus.
      CmsTextBox colorWhite()
      Sets the background color to white.
      protected void fireValueChangedEvent()
      Fires a value change event.
      protected void fireValueChangedEvent​(boolean inhibitValidation)
      Helper method for firing a 'value changed' event.
      java.lang.String getApparentValue()
      Returns the "apparent value", i.e.
      I_CmsFormWidget.FieldType getFieldType()
      Returns the type of data this widget produces.
      java.lang.Object getFormValue()
      Gets the selected/entered value from the widget.
      java.lang.String getFormValueAsString()
      Gets the current value of the widget as a string.
      java.lang.String getId()
      Returns the HTML id of the internal textbox used by this widget.
      java.lang.String getText()
      Returns the text in the text box.
      com.google.gwt.user.client.ui.TextBox getTextBox()
      Returns the Textbox of this widget.
      CmsPaddedPanel getTextBoxContainer()
      Returns the Panel of this widget.
      boolean hasError()
      Returns true if this textbox has an error set.
      protected void hideError()
      Hides the error for this textbox.
      static void initClass()
      Initializes this class.
      boolean isEnabled()
      Gets whether this widget is enabled.
      protected boolean isNavigationKey​(int keyCode)
      Checks if the given key code represents a functional key.
      boolean isPreventShowError()
      Returns the preventShowError.
      boolean isReadOnly()
      Returns the read only flag.
      boolean isTriggerChangeOnKeyPress()
      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 reset()
      Resets the widget to its default state.
      void selectAll()
      Selects text in the text box.
      void setAutoHideParent​(I_CmsAutoHider autoHideParent)
      Call this when auto hiding parents are shown.
      void setChangedStyle()
      Sets the changed style on the text box.
      void setEnabled​(boolean enabled)
      Enables or disables the widget.
      void setErrorMessage​(java.lang.String errorMessage)
      Sets the error message for this widget.
      void setErrorMessageWidth​(java.lang.String width)
      Sets the width of the error message for this textbox.
      void setFocus​(boolean focused)
      Sets the focus on the text box.
      void setFormValueAsString​(java.lang.String newValue)
      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​(java.lang.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 setName​(java.lang.String name)
      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 showError()
      Shows the error for this textbox.
      void updateLayout()
      Updates the layout of the text box.
      • 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 Detail

      • CSS

        public static final I_CmsInputCss CSS
        The CSS bundle used for this widget.
      • NAVIGATION_CODES

        protected static final int[] NAVIGATION_CODES
        Key codes for functional keys.
      • m_ghostValue

        protected java.lang.String m_ghostValue
        The ghost value.
      • m_textbox

        protected com.google.gwt.user.client.ui.TextBox m_textbox
        The text box used internally by this widget.
    • Constructor Detail

      • 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 Detail

      • 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<java.lang.String> handler)
        Specified by:
        addValueChangeHandler in interface com.google.gwt.event.logical.shared.HasValueChangeHandlers<java.lang.String>
        See Also:
        HasValueChangeHandlers.addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler)
      • colorWhite

        public CmsTextBox colorWhite()
        Sets the background color to white.

        Returns:
        this widget
      • getId

        public java.lang.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 java.lang.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
      • 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)
      • selectAll

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

      • setChangedStyle

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

      • setErrorMessageWidth

        public void setErrorMessageWidth​(java.lang.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
      • 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​(java.lang.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:
        I_CmsHasGhostValue.setGhostValue(java.lang.String, boolean)
      • setInhibitValidationForKeypresses

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

        Parameters:
        inhibitValidationForKeypresses - the new flag value
      • setName

        public void setName​(java.lang.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
      • updateLayout

        public void updateLayout()
        Updates the layout of the text box.

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