/** * Sets the value of the date picker. * * <p> * * @param date the value to set * @param fireEvents signals whether the value changed event should be fired or not */ private void setPickerValue(Date date, boolean fireEvents) { if (date == null) { date = new Date(); } m_picker.setValue(date, fireEvents); m_picker.setCurrentMonth(date); m_time.setText(CmsDateConverter.cutSuffix(CmsDateConverter.getTime(date)).trim()); if (CmsDateConverter.isAm(date)) { m_ampmGroup.selectButton(m_am); } else { m_ampmGroup.selectButton(m_pm); } }
/** @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object, boolean) */ public void setValue(Date value, boolean fireEvents) { m_tmpValue = value; if (fireEvents) { fireChange(getValue(), value); m_oldValue = value; } m_box.setText(CmsDateConverter.toString(value)); }
/** * Checks if the String in the date box input field is a valid date format. * * <p> * * @return <code>true</code> if the String in the date box input field is a valid date format */ public boolean isValideDateBox() { try { CmsDateConverter.toDate(m_box.getText()); return true; } catch (Exception e) { return false; } }
/** * Sets the value of the date box. * * <p> * * @param date the new date */ private void updateFromPicker() { checkTime(); Date date = m_picker.getValue(); String timeAsString = getTimeText(); date = CmsDateConverter.getDateWithTime(date, timeAsString); setValue(date); setErrorMessage(null); fireChange(m_oldValue, date); m_oldValue = date; }
/** * 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(); } }
/** @see com.google.gwt.user.client.ui.HasValue#getValue() */ public Date getValue() { Date date = null; if (isEnabled()) { try { date = CmsDateConverter.toDate(m_box.getText()); setErrorMessage(null); } catch (Exception e) { setErrorMessage(Messages.get().key(Messages.ERR_DATEBOX_INVALID_DATE_FORMAT_0)); } } return date; }
/** * Returns the time text field value as string. * * <p> * * @return the time text field value as string */ private String getTimeText() { String timeAsString = m_time.getText().trim(); if (CmsDateConverter.is12HourPresentation()) { if (!(timeAsString.contains(CmsDateConverter.AM) || timeAsString.contains(CmsDateConverter.PM))) { if (m_am.isChecked()) { timeAsString = timeAsString + " " + CmsDateConverter.AM; } else { timeAsString = timeAsString + " " + CmsDateConverter.PM; } } } return timeAsString; }
/** 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); }
/** * Checks if the String in the time input field is a valid time format. * * <p> * * @return <code>true</code> if the String in the time input field is a valid time format */ private boolean isValidTime() { return CmsDateConverter.validateTime(getTimeText()); }
/** * Returns the date value as formated String or an empty String if the date value is null. * * <p> * * @return the date value as formated String */ public String getValueAsFormatedString() { return CmsDateConverter.toString(getValue()); }