/** * The date box on blur action. * * <p>If the date box loses the focus the date time picker should be updated from the date box * value. * * <p> */ protected void onDateBoxBlur() { if (!m_popup.isShowing()) { updateFromTextBox(); } updateCloseBehavior(); }
/** * Validates the time and prints out an error message if the time format is incorrect. * * <p> */ private void checkTime() { if (!isValidTime()) { m_time.setErrorMessageWidth(m_popup.getOffsetWidth() - 32 + Unit.PX.toString()); m_time.setErrorMessage(Messages.get().key(Messages.ERR_DATEBOX_INVALID_TIME_FORMAT_0)); } else if (isValidTime()) { m_time.setErrorMessage(null); } updateCloseBehavior(); }
/** * Hides the date time popup. * * <p> */ private void hidePopup() { if (CmsDateConverter.validateTime(getTimeText())) { // before hiding the date picker remove the date box popup from the auto hide partners of the // parent popup if (m_autoHideParent != null) { m_autoHideParent.removeAutoHidePartner(getElement()); } m_popup.hide(); } }
/** * Updates the auto hide partner from the parent widget. * * <p>If there is any invalid user input the parent widget should not be closed automatically. * * <p> */ protected void updateCloseBehavior() { if (isEnabled()) { if (!m_isValidTime && isValidTime()) { m_isValidTime = true; m_popup.setAutoHideEnabled(true); } else if (m_isValidTime && !isValidTime()) { m_isValidTime = false; m_popup.setAutoHideEnabled(false); } if (!m_isValidDateBox && isValideDateBox()) { m_isValidDateBox = true; if (m_autoHideParent != null) { m_autoHideParent.removeAutoHidePartner(RootPanel.getBodyElement().getParentElement()); } } else if (m_isValidDateBox && !isValideDateBox()) { m_isValidDateBox = false; if (m_autoHideParent != null) { m_autoHideParent.addAutoHidePartner(RootPanel.getBodyElement().getParentElement()); } } } }
/** Create a new date box widget with the date time picker. */ public CmsDateBox() { initWidget(uiBinder.createAndBindUi(this)); m_popup = new CmsPopup(); m_ampmGroup = new CmsRadioButtonGroup(); m_am.setText(Messages.get().key(Messages.GUI_DATE_AM_0)); m_am.setGroup(m_ampmGroup); m_pm.setText(Messages.get().key(Messages.GUI_DATE_PM_0)); m_pm.setGroup(m_ampmGroup); if (!CmsDateConverter.is12HourPresentation()) { m_pm.setVisible(false); m_am.setVisible(false); } CmsDateBoxHandler dateBoxHandler = new CmsDateBoxHandler(); m_picker.addValueChangeHandler(dateBoxHandler); m_box.addBlurHandler(dateBoxHandler); m_box.addClickHandler(dateBoxHandler); m_box.addKeyPressHandler(dateBoxHandler); m_am.addClickHandler(dateBoxHandler); m_pm.addClickHandler(dateBoxHandler); m_time.addClickHandler(dateBoxHandler); m_time.addBlurHandler(dateBoxHandler); m_time.addKeyPressHandler(dateBoxHandler); m_time.addFocusHandler(dateBoxHandler); m_popup.add(m_dateTimePanel); m_popup.setWidth(0); m_popup.setModal(true); m_popup.removePadding(); m_popup.setBackgroundColor( I_CmsLayoutBundle.INSTANCE.constants().css().backgroundColorDialog()); m_popup.addCloseHandler(dateBoxHandler); m_popup.addAutoHidePartner(m_box.getElement()); m_popup.setAutoHideEnabled(true); }
/** * Shows the date picker popup. * * <p> */ private void showPopup() { updateFromTextBox(); m_box.setPreventShowError(true); m_popup.showRelativeTo(m_box); }
/** * The date box on click action. * * <p>If the date box is clicked the time date picker should be shown. * * <p> */ protected void onDateBoxClick() { if (!m_popup.isShowing()) { showPopup(); } }