Search in sources :

Example 6 with TimeField

use of com.extjs.gxt.ui.client.widget.form.TimeField in project kapua by eclipse.

the class DateRangeSelector method showCustomDateRangeDialog.

private void showCustomDateRangeDialog() {
    Date end = m_endDate;
    Date start = m_startDate;
    if (end == null) {
        end = new Date();
    }
    if (start == null) {
        start = new Date(end.getTime() - 24L * 60L * 60L * 1000L);
    }
    final Dialog dialog = new Dialog();
    dialog.setBodyBorder(false);
    dialog.setHeading(MSGS.dataDateRangeCustomTitle());
    dialog.setWidth(300);
    dialog.setHeight(200);
    dialog.setHideOnButtonClick(true);
    dialog.setButtons(Dialog.OKCANCEL);
    dialog.setHideOnButtonClick(false);
    FormData formData = new FormData("-20");
    final FormPanel form = new FormPanel();
    form.setHeaderVisible(false);
    final DateField startDateField = new DateField();
    startDateField.setFieldLabel(MSGS.dataDateRangeStartDate());
    startDateField.setAllowBlank(false);
    startDateField.setValue(start);
    startDateField.setEditable(false);
    form.add(startDateField, formData);
    final TimeField startTimeField = new TimeField();
    startTimeField.setFormat(DateTimeFormat.getFormat("HH:mm"));
    startTimeField.setTriggerAction(TriggerAction.ALL);
    startTimeField.setFieldLabel(MSGS.dataDateRangeStartTime());
    startTimeField.setAllowBlank(false);
    startTimeField.setDateValue(start);
    startTimeField.setEditable(false);
    form.add(startTimeField, formData);
    final DateField endDateField = new DateField();
    endDateField.setFieldLabel(MSGS.dataDateRangeStopDate());
    endDateField.setAllowBlank(false);
    endDateField.setValue(end);
    endDateField.setEditable(false);
    form.add(endDateField, formData);
    final TimeField endTimeField = new TimeField();
    endTimeField.setFormat(DateTimeFormat.getFormat("HH:mm"));
    endTimeField.setTriggerAction(TriggerAction.ALL);
    endTimeField.setFieldLabel(MSGS.dataDateRangeStopTime());
    endTimeField.setAllowBlank(false);
    endTimeField.setDateValue(end);
    endTimeField.setEditable(false);
    form.add(endTimeField, formData);
    startDateField.setValidator(new Validator() {

        @Override
        public String validate(Field<?> field, String value) {
            if (startDateField.getValue().after(endDateField.getValue())) {
                return MSGS.dataDateRangeInvalidStartDate();
            }
            return null;
        }
    });
    endDateField.setValidator(new Validator() {

        @Override
        public String validate(Field<?> field, String value) {
            if (endDateField.getValue().before(startDateField.getValue())) {
                return MSGS.dataDateRangeInvalidStopDate();
            }
            return null;
        }
    });
    startTimeField.setValidator(new Validator() {

        @Override
        public String validate(Field<?> field, String value) {
            if (startDateField.getValue().equals(endDateField.getValue()) && startTimeField.getDateValue().after(endTimeField.getDateValue())) {
                return MSGS.dataDateRangeInvalidStartTime();
            }
            return null;
        }
    });
    endTimeField.setValidator(new Validator() {

        @Override
        public String validate(Field<?> field, String value) {
            if (startDateField.getValue().equals(endDateField.getValue()) && endTimeField.getDateValue().before(startTimeField.getDateValue())) {
                return MSGS.dataDateRangeInvalidStopTime();
            }
            return null;
        }
    });
    dialog.add(form);
    dialog.getButtonById("ok").addSelectionListener(new SelectionListener<ButtonEvent>() {

        public void componentSelected(ButtonEvent ce) {
            if (form.isValid()) {
                long lStartDate = startDateField.getValue().getTime();
                lStartDate = lStartDate + (long) startTimeField.getValue().getHour() * 60L * 60L * 1000L + (long) startTimeField.getValue().getMinutes() * 60L * 1000L;
                m_startDate = new Date(lStartDate);
                long lEndDate = endDateField.getValue().getTime();
                lEndDate = lEndDate + (long) endTimeField.getValue().getHour() * 60L * 60L * 1000L + (long) endTimeField.getValue().getMinutes() * 60L * 1000L;
                m_endDate = new Date(lEndDate);
                DateTimeFormat dtf = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_SHORT);
                StringBuilder sb = new StringBuilder();
                sb.append(dtf.format(m_startDate)).append(" - ").append(dtf.format(m_endDate));
                m_dateRange.setText(sb.toString());
                dialog.hide();
                if (m_listener != null) {
                    m_listener.onUpdate();
                }
            }
        }
    });
    dialog.getButtonById("cancel").addSelectionListener(new SelectionListener<ButtonEvent>() {

        public void componentSelected(ButtonEvent ce) {
            dialog.hide();
        }
    });
    dialog.show();
}
Also used : FormData(com.extjs.gxt.ui.client.widget.layout.FormData) Date(java.util.Date) TimeField(com.extjs.gxt.ui.client.widget.form.TimeField) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) Dialog(com.extjs.gxt.ui.client.widget.Dialog) DateField(com.extjs.gxt.ui.client.widget.form.DateField) Validator(com.extjs.gxt.ui.client.widget.form.Validator) DateTimeFormat(com.google.gwt.i18n.client.DateTimeFormat)

Aggregations

DateField (com.extjs.gxt.ui.client.widget.form.DateField)6 TimeField (com.extjs.gxt.ui.client.widget.form.TimeField)6 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)4 FormData (com.extjs.gxt.ui.client.widget.layout.FormData)4 Dialog (com.extjs.gxt.ui.client.widget.Dialog)2 Label (com.extjs.gxt.ui.client.widget.Label)2 LayoutContainer (com.extjs.gxt.ui.client.widget.LayoutContainer)2 Button (com.extjs.gxt.ui.client.widget.button.Button)2 FormPanel (com.extjs.gxt.ui.client.widget.form.FormPanel)2 FormLayout (com.extjs.gxt.ui.client.widget.layout.FormLayout)2 DateTimeFormat (com.google.gwt.i18n.client.DateTimeFormat)2 Date (java.util.Date)2 FieldEvent (com.extjs.gxt.ui.client.event.FieldEvent)1 Listener (com.extjs.gxt.ui.client.event.Listener)1 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)1 Radio (com.extjs.gxt.ui.client.widget.form.Radio)1 RadioGroup (com.extjs.gxt.ui.client.widget.form.RadioGroup)1 Validator (com.extjs.gxt.ui.client.widget.form.Validator)1 GeoPlatformWindow (org.geosdi.geoplatform.gui.client.widget.GeoPlatformWindow)1