Class CmsDateBox

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.datebox.CmsDateBox
All Implemented Interfaces:
com.google.gwt.event.dom.client.HasKeyPressHandlers, com.google.gwt.event.logical.shared.HasAttachHandlers, com.google.gwt.event.logical.shared.HasValueChangeHandlers<Date>, com.google.gwt.event.shared.HasHandlers, com.google.gwt.user.client.EventListener, com.google.gwt.user.client.TakesValue<Date>, com.google.gwt.user.client.ui.HasValue<Date>, com.google.gwt.user.client.ui.HasVisibility, com.google.gwt.user.client.ui.IsRenderable, com.google.gwt.user.client.ui.IsWidget, I_CmsHasInit, I_CmsHasDateBoxEventHandlers, I_CmsFormWidget

public class CmsDateBox extends com.google.gwt.user.client.ui.Composite implements com.google.gwt.user.client.ui.HasValue<Date>, I_CmsFormWidget, I_CmsHasInit, com.google.gwt.event.dom.client.HasKeyPressHandlers, I_CmsHasDateBoxEventHandlers
A text box that shows a date time picker widget when the user clicks on it.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected class 
    Drag and drop event preview handler.
    protected class 
    This inner class implements the handler for the date box widget.

    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 Date
    Dummy value used for invalid dates.
    protected CmsRadioButton
    The am radio button.
    The radio button group for am/pm selection.
    protected I_CmsAutoHider
    The auto hide parent.
    protected CmsTextBox
    The input field to show the result of picking a date.
    protected com.google.gwt.user.client.ui.FlowPanel
    The panel for the date time picker.
    protected com.google.gwt.user.datepicker.client.DatePicker
    The gwt date picker.
    protected CmsRadioButton
    The pm radio button.
    protected com.google.gwt.event.shared.HandlerRegistration
    Event preview handler registration.
    protected CmsTextBox
    The text box to input the time.
    protected com.google.gwt.user.client.ui.FlowPanel
    The panel for the time selection.
    static final com.google.gwt.i18n.client.DateTimeFormat
    Format used to parse the configured time in fixed-time mode.
    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
    Create a new date box widget with the date time picker.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.google.gwt.event.shared.HandlerRegistration
    Adds a new event handler for date box events.
    com.google.gwt.event.shared.HandlerRegistration
    addKeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler handler)
     
    com.google.gwt.event.shared.HandlerRegistration
    addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler<Date> handler)
     
    boolean
    Returns true if invalid values should be allowed.
    protected void
    Updates the updates the close behavior and sets the value of the date box to the value from the picker.
    protected void
    fireChange(Date newValue, boolean isTyping)
    Fires the value change event if needed.
    Returns the "apparent value", i.e.
    Returns the type of data this widget produces.
    Gets the selected/entered value from the widget.
    Returns the value of the date box as String in form of a long.
    Returns the text box of this widget.
     
    Returns the date value as formated String or an empty String if the date value is null.
    boolean
    Returns true if the box and the time input fields don't have any errors.
    protected void
    Hides the date time popup.
    static void
    Initializes this class.
    boolean
    Returns true if this widget is enabled.
    boolean
    Checks if the String in the date box input field is a valid date format.
    protected void
    If the am or pm radio button is clicked update the date box from the date time picker.
    protected void
    The date box on blur action.
    protected void
    The date box on click action.
    protected void
    onDateBoxKeyPress(com.google.gwt.event.dom.client.KeyUpEvent event)
    The date box on key down action.
    protected void
    Adds the preview handler.
    protected void
    If the value of the picker changes, the value of the date time picker should be updated.
    protected void
    If the time field loses the focus the entered time should be checked.
    void
    Updates the date box when the user has clicked on the time field.
    protected void
    onTimeKeyPressed(com.google.gwt.event.dom.client.KeyUpEvent event)
    If the user presses enter in the time field the value of the picker should be updated and the the popup should be closed.
    protected void
    previewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent event)
    Blurs the time box if the user clicks outside of it.
    void
    Resets the widget to its default state.
    void
    setAllowInvalidValue(boolean allowInvalidValue)
    Enables or disables whether invalid values are allowed.
    void
    Call this when auto hiding parents are shown.
    void
    setDateOnly(boolean dateOnly)
    Sets the value if the date only should be shown.
    void
    setEnabled(boolean enabled)
    Enables or disables the widget.
    void
    setErrorMessage(String errorMessage)
    Sets the error message for this widget.
    void
    Sets the time to be used when the widget is in date-only mode.
    void
    Expects the value as String in form of a long.
    void
    setInitialDate(Date initialDate)
    Sets the initial date shown, when the date picker is opened and no date was set before.
    void
    Sets the name of the input field.
    void
    setValue(Date value)
     
    void
    setValue(Date value, boolean fireEvents)
     
    protected void
    Updates the auto hide partner from the parent widget.

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

    claimElement, getWidget, initializeClaimedElement, initWidget, isAttached, onAttach, onBrowserEvent, 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

    • INVALID_DATE

      public static final Date INVALID_DATE
      Dummy value used for invalid dates.
    • TIME_FORMAT_24H

      public static final com.google.gwt.i18n.client.DateTimeFormat TIME_FORMAT_24H
      Format used to parse the configured time in fixed-time mode.
    • WIDGET_TYPE

      public static final String WIDGET_TYPE
      The widget type identifier for this widget.
      See Also:
    • m_am

      @UiField protected CmsRadioButton m_am
      The am radio button.
    • m_ampmGroup

      The radio button group for am/pm selection.
    • m_autoHideParent

      The auto hide parent.
    • m_box

      @UiField protected CmsTextBox m_box
      The input field to show the result of picking a date.
    • m_dateTimePanel

      @UiField protected com.google.gwt.user.client.ui.FlowPanel m_dateTimePanel
      The panel for the date time picker.
    • m_picker

      @UiField protected com.google.gwt.user.datepicker.client.DatePicker m_picker
      The gwt date picker.
    • m_pm

      @UiField protected CmsRadioButton m_pm
      The pm radio button.
    • m_previewHandlerRegistration

      protected com.google.gwt.event.shared.HandlerRegistration m_previewHandlerRegistration
      Event preview handler registration.
    • m_time

      @UiField protected CmsTextBox m_time
      The text box to input the time.
    • m_timeField

      @UiField protected com.google.gwt.user.client.ui.FlowPanel m_timeField
      The panel for the time selection.
  • Constructor Details

    • CmsDateBox

      public CmsDateBox()
      Create a new date box widget with the date time picker.
  • Method Details

    • initClass

      public static void initClass()
      Initializes this class.

    • addCmsDateBoxEventHandler

      public com.google.gwt.event.shared.HandlerRegistration addCmsDateBoxEventHandler(I_CmsDateBoxEventHandler handler)
      Description copied from interface: I_CmsHasDateBoxEventHandlers
      Adds a new event handler for date box events.

      Specified by:
      addCmsDateBoxEventHandler in interface I_CmsHasDateBoxEventHandlers
      Parameters:
      handler - the event handler
      Returns:
      the handler registration
      See Also:
    • 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)
    • addValueChangeHandler

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

      public boolean allowInvalidValue()
      Returns true if invalid values should be allowed.

      If invalid values are allowed, methods returning a Date will return a special dummy date in case the date is invalid.

      Returns:
      true if invalid values should be allowed
    • 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

      Returns the value of the date box as String in form of a long.

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

      Returns the text box of this widget.

      Returns:
      the CmsText Box
    • getValue

      public Date getValue()
      Specified by:
      getValue in interface com.google.gwt.user.client.ui.HasValue<Date>
      Specified by:
      getValue in interface com.google.gwt.user.client.TakesValue<Date>
      See Also:
      • HasValue.getValue()
    • getValueAsFormatedString

      Returns the date value as formated String or an empty String if the date value is null.

      Returns:
      the date value as formated String
    • hasErrors

      public boolean hasErrors()
      Returns true if the box and the time input fields don't have any errors.

      Returns:
      true if the box and the time input fields don't have any errors
    • isEnabled

      public boolean isEnabled()
      Description copied from interface: I_CmsFormWidget
      Returns true if this widget is enabled.

      Specified by:
      isEnabled in interface I_CmsFormWidget
      Returns:
      true if this widget is enabled
      See Also:
    • isValideDateBox

      public boolean isValideDateBox()
      Checks if the String in the date box input field is a valid date format.

      Returns:
      true if the String in the date box input field is a valid date format
    • onTimeClick

      public void onTimeClick()
      Updates the date box when the user has clicked on the time field.

    • 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:
    • setAllowInvalidValue

      public void setAllowInvalidValue(boolean allowInvalidValue)
      Enables or disables whether invalid values are allowed.

      If invalid values are allowed, they will be returned as a special dummy date (INVALID_DATE).

      Parameters:
      allowInvalidValue - true if invalid values should be allowed
    • 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:
    • setDateOnly

      public void setDateOnly(boolean dateOnly)
      Sets the value if the date only should be shown.
      Parameters:
      dateOnly - if the date only should be shown
    • 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:
    • setFixedTime

      public void setFixedTime(String time)
      Sets the time to be used when the widget is in date-only mode.
      Parameters:
      time - the time to use when the widget is in date-only mode
    • setFormValueAsString

      public void setFormValueAsString(String value)
      Expects the value as String in form of a long.

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

      public void setInitialDate(Date initialDate)
      Sets the initial date shown, when the date picker is opened and no date was set before.

      Parameters:
      initialDate - the initial date
    • setName

      public void setName(String name)
      Sets the name of the input field.

      Parameters:
      name - of the input field
    • setValue

      public void setValue(Date value)
      Specified by:
      setValue in interface com.google.gwt.user.client.ui.HasValue<Date>
      Specified by:
      setValue in interface com.google.gwt.user.client.TakesValue<Date>
      See Also:
      • HasValue.setValue(java.lang.Object)
    • setValue

      public void setValue(Date value, boolean fireEvents)
      Specified by:
      setValue in interface com.google.gwt.user.client.ui.HasValue<Date>
      See Also:
      • HasValue.setValue(java.lang.Object, boolean)
    • executeTimeAction

      protected void executeTimeAction()
      Updates the updates the close behavior and sets the value of the date box to the value from the picker.

    • fireChange

      protected void fireChange(Date newValue, boolean isTyping)
      Fires the value change event if needed.

      Parameters:
      newValue - the new value
      isTyping - true if the user is currently typing
    • hidePopup

      protected void hidePopup()
      Hides the date time popup.

    • onAmPmClick

      protected void onAmPmClick()
      If the am or pm radio button is clicked update the date box from the date time picker.

    • onDateBoxBlur

      protected void onDateBoxBlur()
      The date box on blur action.

      If the date box loses the focus the date time picker should be updated from the date box value.

    • onDateBoxClick

      protected void onDateBoxClick()
      The date box on click action.

      If the date box is clicked the time date picker should be shown.

    • onDateBoxKeyPress

      protected void onDateBoxKeyPress(com.google.gwt.event.dom.client.KeyUpEvent event)
      The date box on key down action.

      • If enter or tab is pressed in the date box the date time picker should be updated with the value from the date box.
      • If the escape key is pressed the picker should be hided.
      • If the up key is pressed the value should be taken from the date box.
      • If the down key is pressed the picker should be hided.
      Parameters:
      event - the key down event
    • onFocusTimeBox

      protected void onFocusTimeBox()
      Adds the preview handler.

    • onPickerValueChanged

      protected void onPickerValueChanged()
      If the value of the picker changes, the value of the date time picker should be updated.

    • onTimeBlur

      protected void onTimeBlur()
      If the time field loses the focus the entered time should be checked.

    • onTimeKeyPressed

      protected void onTimeKeyPressed(com.google.gwt.event.dom.client.KeyUpEvent event)
      If the user presses enter in the time field the value of the picker should be updated and the the popup should be closed.

      In any other case the popup should be prevented to being closed.

      Parameters:
      event - the key pressed event
    • previewNativeEvent

      protected void previewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent event)
      Blurs the time box if the user clicks outside of it.

      Parameters:
      event - the native preview event
    • updateCloseBehavior

      protected void updateCloseBehavior()
      Updates the auto hide partner from the parent widget.

      If there is any invalid user input the parent widget should not be closed automatically.