Пример #1
0
  /**
   * Returns <code>true</code> if the box and the time input fields don't have any errors.
   *
   * <p>
   *
   * @return <code>true</code> if the box and the time input fields don't have any errors
   */
  public boolean hasErrors() {

    if (m_box.hasError() || m_time.hasError()) {
      return true;
    }
    return false;
  }
Пример #2
0
  /**
   * 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();
  }
Пример #3
0
  /** @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#setEnabled(boolean) */
  public void setEnabled(boolean enabled) {

    if (!enabled) {
      m_tmpValue = getValue();
      m_box.setText(Messages.get().key(Messages.GUI_INPUT_NOT_USED_0));
    } else {
      setValue(m_tmpValue);
    }
    m_box.setEnabled(enabled);
  }
Пример #4
0
  /**
   * Blurs the time box if the user clicks outside of it.
   *
   * <p>
   *
   * @param event the native preview event
   */
  protected void previewNativeEvent(NativePreviewEvent event) {

    Event nativeEvent = Event.as(event.getNativeEvent());
    if ((nativeEvent.getTypeInt() == Event.ONCLICK)) {
      EventTarget target = nativeEvent.getEventTarget();
      if (!Element.is(target)) {
        return;
      }
      Element element = Element.as(target);
      if (!m_time.getElement().isOrHasChild(element)) {
        m_time.blur();
      }
    }
  }
Пример #5
0
  /**
   * Updates the picker if the user manually modified the date of the text box.
   *
   * <p>
   */
  private void updateFromTextBox() {

    Date date = getValue();
    setPickerValue(date, false);
    m_time.setErrorMessage(null);
    fireChange(m_oldValue, getValue());
    m_oldValue = date;
  }
Пример #6
0
  /** @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));
  }
Пример #7
0
  /**
   * 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;
    }
  }
Пример #8
0
  /** @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;
  }
Пример #9
0
  /**
   * 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);
    }
  }
Пример #10
0
  /**
   * 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;
  }
Пример #11
0
  /** 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);
  }
Пример #12
0
  /**
   * Shows the date picker popup.
   *
   * <p>
   */
  private void showPopup() {

    updateFromTextBox();
    m_box.setPreventShowError(true);
    m_popup.showRelativeTo(m_box);
  }
Пример #13
0
  /** @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#setErrorMessage(java.lang.String) */
  public void setErrorMessage(String errorMessage) {

    m_box.setErrorMessage(errorMessage);
  }
Пример #14
0
  /** @see org.opencms.gwt.client.ui.input.I_CmsFormWidget#isEnabled() */
  public boolean isEnabled() {

    return m_box.isEnabled();
  }
Пример #15
0
  /**
   * @see
   *     com.google.gwt.event.dom.client.HasKeyPressHandlers#addKeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler)
   */
  public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {

    return m_box.addHandler(handler, KeyPressEvent.getType());
  }