1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/*
@VaadinApache2LicenseForJavaFiles@
*/
package com.vaadin.terminal.gwt.client.ui;
import java.util.Date;
import com.google.gwt.event.dom.client.DomEvent;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.DateTimeService;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusChangeListener;
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.FocusOutListener;
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.SubmitListener;
import com.vaadin.terminal.gwt.client.ui.VCalendarPanel.TimeChangeListener;
/**
* A client side implementation for InlineDateField
*/
public class VDateFieldCalendar extends VDateField {
private final VCalendarPanel calendarPanel;
public VDateFieldCalendar() {
super();
calendarPanel = new VCalendarPanel();
add(calendarPanel);
calendarPanel.setSubmitListener(new SubmitListener() {
public void onSubmit() {
updateValueFromPanel();
}
public void onCancel() {
// TODO Auto-generated method stub
}
});
calendarPanel.setFocusOutListener(new FocusOutListener() {
public boolean onFocusOut(DomEvent<?> event) {
updateValueFromPanel();
return false;
}
});
}
@Override
@SuppressWarnings("deprecation")
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
super.updateFromUIDL(uidl, client);
calendarPanel.setShowISOWeekNumbers(isShowISOWeekNumbers());
calendarPanel.setDateTimeService(getDateTimeService());
calendarPanel.setResolution(getCurrentResolution());
Date currentDate = getCurrentDate();
if (currentDate != null) {
calendarPanel.setDate(new Date(currentDate.getTime()));
} else {
calendarPanel.setDate(null);
}
if (currentResolution > RESOLUTION_DAY) {
calendarPanel.setTimeChangeListener(new TimeChangeListener() {
public void changed(int hour, int min, int sec, int msec) {
Date d = getDate();
if (d == null) {
// date currently null, use the value from calendarPanel
// (~ client time at the init of the widget)
d = (Date) calendarPanel.getDate().clone();
}
d.setHours(hour);
d.setMinutes(min);
d.setSeconds(sec);
DateTimeService.setMilliseconds(d, msec);
// Always update time changes to the server
calendarPanel.setDate(d);
updateValueFromPanel();
}
});
}
if (currentResolution <= RESOLUTION_MONTH) {
calendarPanel.setFocusChangeListener(new FocusChangeListener() {
public void focusChanged(Date date) {
Date date2 = new Date();
if (calendarPanel.getDate() != null) {
date2.setTime(calendarPanel.getDate().getTime());
}
/*
* Update the value of calendarPanel
*/
date2.setYear(date.getYear());
date2.setMonth(date.getMonth());
calendarPanel.setDate(date2);
/*
* Then update the value from panel to server
*/
updateValueFromPanel();
}
});
} else {
calendarPanel.setFocusChangeListener(null);
}
// Update possible changes
calendarPanel.renderCalendar();
}
/**
* TODO refactor: almost same method as in VPopupCalendar.updateValue
*/
@SuppressWarnings("deprecation")
private void updateValueFromPanel() {
Date date2 = calendarPanel.getDate();
Date currentDate = getCurrentDate();
if (currentDate == null || date2.getTime() != currentDate.getTime()) {
setCurrentDate((Date) date2.clone());
getClient().updateVariable(getId(), "year", date2.getYear() + 1900,
false);
if (getCurrentResolution() > VDateField.RESOLUTION_YEAR) {
getClient().updateVariable(getId(), "month",
date2.getMonth() + 1, false);
if (getCurrentResolution() > RESOLUTION_MONTH) {
getClient().updateVariable(getId(), "day", date2.getDate(),
false);
if (getCurrentResolution() > RESOLUTION_DAY) {
getClient().updateVariable(getId(), "hour",
date2.getHours(), false);
if (getCurrentResolution() > RESOLUTION_HOUR) {
getClient().updateVariable(getId(), "min",
date2.getMinutes(), false);
if (getCurrentResolution() > RESOLUTION_MIN) {
getClient().updateVariable(getId(), "sec",
date2.getSeconds(), false);
if (getCurrentResolution() > RESOLUTION_SEC) {
getClient().updateVariable(
getId(),
"msec",
DateTimeService
.getMilliseconds(date2),
false);
}
}
}
}
}
}
if (isImmediate()) {
getClient().sendPendingVariableChanges();
}
}
}
}
|