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();
}
Aggregations