• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package autotest.common.table;
2 
3 import autotest.common.ui.DateTimeBox;
4 
5 import com.google.gwt.event.logical.shared.ValueChangeEvent;
6 import com.google.gwt.event.logical.shared.ValueChangeHandler;
7 import com.google.gwt.i18n.client.DateTimeFormat;
8 import com.google.gwt.user.client.ui.HorizontalPanel;
9 import com.google.gwt.user.client.ui.Label;
10 import com.google.gwt.user.client.ui.Panel;
11 import com.google.gwt.user.client.ui.Widget;
12 import com.google.gwt.user.datepicker.client.CalendarUtil;
13 
14 import java.util.Date;
15 
16 public class DatetimeSegmentFilter extends SimpleFilter {
17     protected DateTimeBox startDatetimeBox;
18     protected DateTimeBox endDatetimeBox;
19     protected Panel panel;
20     protected Label fromLabel;
21     protected Label toLabel;
22     private String placeHolderStartDatetime;
23     private String placeHolderEndDatetime;
24 
DatetimeSegmentFilter()25     public DatetimeSegmentFilter() {
26         startDatetimeBox = new DateTimeBox();
27         endDatetimeBox = new DateTimeBox();
28         fromLabel = new Label("From");
29         toLabel = new Label("to");
30 
31         panel = new HorizontalPanel();
32         panel.add(fromLabel);
33         panel.add(startDatetimeBox);
34         panel.add(toLabel);
35         panel.add(endDatetimeBox);
36 
37         DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd");
38         Date placeHolderDate = new Date();
39         // We want all entries from today, so advance end date to tomorrow.
40         CalendarUtil.addDaysToDate(placeHolderDate, 1);
41         placeHolderEndDatetime = dateTimeFormat.format(placeHolderDate) + "T00:00";
42         setEndTimeToPlaceHolderValue();
43 
44         CalendarUtil.addDaysToDate(placeHolderDate, -7);
45         placeHolderStartDatetime = dateTimeFormat.format(placeHolderDate) + "T00:00";
46         setStartTimeToPlaceHolderValue();
47 
48         addValueChangeHandler(
49             new ValueChangeHandler() {
50                 public void onValueChange(ValueChangeEvent event) {
51                     notifyListeners();
52                 }
53             },
54             new ValueChangeHandler() {
55                 public void onValueChange(ValueChangeEvent event) {
56                     notifyListeners();
57                 }
58             }
59         );
60     }
61 
62     @Override
getWidget()63     public Widget getWidget() {
64         return panel;
65     }
66 
setStartTimeToPlaceHolderValue()67     public void setStartTimeToPlaceHolderValue() {
68         startDatetimeBox.setValue(placeHolderStartDatetime);
69     }
70 
setEndTimeToPlaceHolderValue()71     public void setEndTimeToPlaceHolderValue() {
72         endDatetimeBox.setValue(placeHolderEndDatetime);
73     }
74 
addValueChangeHandler(ValueChangeHandler<String> startTimeHandler, ValueChangeHandler<String> endTimeHandler)75     public void addValueChangeHandler(ValueChangeHandler<String> startTimeHandler,
76                                       ValueChangeHandler<String> endTimeHandler) {
77         startDatetimeBox.addValueChangeHandler(startTimeHandler);
78         endDatetimeBox.addValueChangeHandler(endTimeHandler);
79     }
80 }
81