Class 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<java.util.Date>, com.google.gwt.event.shared.HasHandlers, com.google.gwt.user.client.EventListener, com.google.gwt.user.client.TakesValue<java.util.Date>, com.google.gwt.user.client.ui.HasValue<java.util.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<java.util.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  CmsDateBox.CloseEventPreviewHandler
      Drag and drop event preview handler.
      protected class  CmsDateBox.CmsDateBoxHandler
      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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.Date INVALID_DATE
      Dummy value used for invalid dates.
      protected CmsRadioButton m_am
      The am radio button.
      protected CmsRadioButtonGroup m_ampmGroup
      The radio button group for am/pm selection.
      protected I_CmsAutoHider m_autoHideParent
      The auto hide parent.
      protected CmsTextBox m_box
      The input field to show the result of picking a date.
      protected com.google.gwt.user.client.ui.FlowPanel m_dateTimePanel
      The panel for the date time picker.
      protected com.google.gwt.user.datepicker.client.DatePicker m_picker
      The gwt date picker.
      protected CmsRadioButton m_pm
      The pm radio button.
      protected com.google.gwt.event.shared.HandlerRegistration m_previewHandlerRegistration
      Event preview handler registration.
      protected CmsTextBox m_time
      The text box to input the time.
      protected com.google.gwt.user.client.ui.FlowPanel m_timeField
      The panel for the time selection.
      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
      CmsDateBox()
      Create a new date box widget with the date time picker.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.google.gwt.event.shared.HandlerRegistration addCmsDateBoxEventHandler​(I_CmsDateBoxEventHandler handler)
      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<java.util.Date> handler)  
      boolean allowInvalidValue()
      Returns true if invalid values should be allowed.
      protected void executeTimeAction()
      Updates the updates the close behavior and sets the value of the date box to the value from the picker.
      protected void fireChange​(java.util.Date newValue, boolean isTyping)
      Fires the value change event if needed.
      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()
      Returns the value of the date box as String in form of a long.
      CmsTextBox getTextField()
      Returns the text box of this widget.
      java.util.Date getValue()  
      java.lang.String getValueAsFormatedString()
      Returns the date value as formated String or an empty String if the date value is null.
      boolean hasErrors()
      Returns true if the box and the time input fields don't have any errors.
      protected void hidePopup()
      Hides the date time popup.
      static void initClass()
      Initializes this class.
      boolean isEnabled()
      Returns true if this widget is enabled.
      boolean isValideDateBox()
      Checks if the String in the date box input field is a valid date format.
      protected void onAmPmClick()
      If the am or pm radio button is clicked update the date box from the date time picker.
      protected void onDateBoxBlur()
      The date box on blur action.
      protected void onDateBoxClick()
      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 onFocusTimeBox()
      Adds the preview handler.
      protected void onPickerValueChanged()
      If the value of the picker changes, the value of the date time picker should be updated.
      protected void onTimeBlur()
      If the time field loses the focus the entered time should be checked.
      void onTimeClick()
      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 reset()
      Resets the widget to its default state.
      void setAllowInvalidValue​(boolean allowInvalidValue)
      Enables or disables whether invalid values are allowed.
      void setAutoHideParent​(I_CmsAutoHider autoHideParent)
      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​(java.lang.String errorMessage)
      Sets the error message for this widget.
      void setFormValueAsString​(java.lang.String value)
      Expects the value as String in form of a long.
      void setInitialDate​(java.util.Date initialDate)
      Sets the initial date shown, when the date picker is opened and no date was set before.
      void setName​(java.lang.String name)
      Sets the name of the input field.
      void setValue​(java.util.Date value)  
      void setValue​(java.util.Date value, boolean fireEvents)  
      protected void updateCloseBehavior()
      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 Detail

      • INVALID_DATE

        public static final java.util.Date INVALID_DATE
        Dummy value used for invalid dates.
      • 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_previewHandlerRegistration

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

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

      • CmsDateBox

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

      • initClass

        public static void initClass()
        Initializes this class.

      • 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<java.util.Date> handler)
        Specified by:
        addValueChangeHandler in interface com.google.gwt.event.logical.shared.HasValueChangeHandlers<java.util.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
      • getTextField

        public CmsTextBox getTextField()
        Returns the text box of this widget.

        Returns:
        the CmsText Box
      • getValue

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

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

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

        public void setInitialDate​(java.util.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​(java.lang.String name)
        Sets the name of the input field.

        Parameters:
        name - of the input field
      • setValue

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

        public void setValue​(java.util.Date value,
                             boolean fireEvents)
        Specified by:
        setValue in interface com.google.gwt.user.client.ui.HasValue<java.util.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​(java.util.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.