| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.uruma.binding.value.binder; |
| 17 | |
|
| 18 | |
import java.text.DecimalFormat; |
| 19 | |
import java.text.ParseException; |
| 20 | |
import java.text.SimpleDateFormat; |
| 21 | |
import java.util.Calendar; |
| 22 | |
import java.util.Date; |
| 23 | |
|
| 24 | |
import org.eclipse.swt.widgets.DateTime; |
| 25 | |
import org.seasar.framework.beans.PropertyDesc; |
| 26 | |
import org.seasar.uruma.binding.value.ValueBinder; |
| 27 | |
import org.seasar.uruma.component.UIComponent; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | 8 | public class DateTimeValueBinder extends AbstractValueBinder<DateTime> { |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public DateTimeValueBinder() { |
| 40 | 4 | super(DateTime.class); |
| 41 | 4 | } |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
@Override |
| 48 | |
protected void doImportValue(final DateTime widget, final Object formObj, |
| 49 | |
final PropertyDesc propDesc, final UIComponent uiComp) { |
| 50 | |
|
| 51 | 0 | Date date = null; |
| 52 | 0 | SimpleDateFormat sdFormat = new SimpleDateFormat("yyyyMMddHHmmss"); |
| 53 | 0 | DecimalFormat dFormat = new DecimalFormat("00"); |
| 54 | |
try { |
| 55 | 0 | date = sdFormat.parse(widget.getYear() |
| 56 | |
+ dFormat.format(widget.getMonth() + 1) |
| 57 | |
+ dFormat.format(widget.getDay()) |
| 58 | |
+ dFormat.format(widget.getHours()) |
| 59 | |
+ dFormat.format(widget.getMinutes()) |
| 60 | |
+ dFormat.format(widget.getSeconds())); |
| 61 | 0 | } catch (ParseException ex) { |
| 62 | 0 | date = new Date(); |
| 63 | 0 | } |
| 64 | |
|
| 65 | 0 | logBinding(IMPORT_VALUE, formObj, propDesc, widget, propDesc, date); |
| 66 | 0 | propDesc.setValue(formObj, date); |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
@Override |
| 74 | |
protected void doExportValue(final DateTime widget, final Object formObj, |
| 75 | |
final PropertyDesc propDesc, final UIComponent uiComp) { |
| 76 | 8 | Object value = propDesc.getValue(formObj); |
| 77 | 8 | if (value == null || !(value instanceof Date)) { |
| 78 | 0 | value = new Date(); |
| 79 | |
} |
| 80 | |
|
| 81 | 8 | logBinding(EXPORT_VALUE, formObj, propDesc, widget, propDesc, value); |
| 82 | |
|
| 83 | 8 | Calendar cal = Calendar.getInstance(); |
| 84 | 8 | cal.setTime((Date) value); |
| 85 | 8 | widget.setYear(cal.get(Calendar.YEAR)); |
| 86 | 8 | widget.setMonth(cal.get(Calendar.MONTH)); |
| 87 | 8 | widget.setDay(cal.get(Calendar.DATE)); |
| 88 | 8 | widget.setHours(cal.get(Calendar.HOUR_OF_DAY)); |
| 89 | 8 | widget.setMinutes(cal.get(Calendar.MINUTE)); |
| 90 | 8 | widget.setSeconds(cal.get(Calendar.SECOND)); |
| 91 | 8 | } |
| 92 | |
} |