|
@@ -1,100 +1,100 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.forms.client.components.impls.input; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
5 |
|
- |
import org.litesoft.GWT.forms.client.components.nonpublic.*; |
6 |
|
- |
import org.litesoft.commonfoundation.typeutils.gregorian.*; |
7 |
|
- |
import org.litesoft.core.simpletypes.temporal.*; |
8 |
|
- |
import org.litesoft.core.simpletypes.temporal.nonpublic.*; |
9 |
|
- |
import org.litesoft.uispecification.*; |
10 |
|
- |
|
11 |
|
- |
import java.util.*; |
12 |
|
- |
|
13 |
|
- |
public class FormDatePicker extends AbstractTextFieldWithPicker { |
14 |
|
- |
private DateFormat mDateFormat; |
15 |
|
- |
private TemporalParser mTemporalParser; |
16 |
|
- |
|
17 |
|
- |
public FormDatePicker( String pFieldLabel, UiFont pLabelFont, String pTooltip, String pCancelText, String pTodayText, DateFormat pDateFormat ) { |
18 |
|
- |
// 1234567-101 |
19 |
|
- |
// 04 JAN 1957 |
20 |
|
- |
super( pTooltip, true, pDateFormat.getFormat().length(), "Calendar", new MyPicker( pCancelText, pTodayText ) ); |
21 |
|
- |
initialize( pFieldLabel, pLabelFont, pTooltip ); |
22 |
|
- |
|
23 |
|
- |
mDateFormat = pDateFormat; |
24 |
|
- |
String zFieldOrder = pDateFormat.getFieldOrder(); |
25 |
|
- |
if ( zFieldOrder.equals( "dMy" ) && mDateFormat.getFormat().contains( "MMM" ) ) { |
26 |
|
- |
zFieldOrder = "Mdy"; |
27 |
|
- |
} |
28 |
|
- |
mTemporalParser = new TemporalParser( zFieldOrder ); |
29 |
|
- |
} |
30 |
|
- |
|
31 |
|
- |
@Override |
32 |
|
- |
protected Object parseNotEmptyTextFieldToInternalForm( String pText, Object pLastValidInternalFormValue ) |
33 |
|
- |
throws IllegalArgumentException { |
34 |
|
- |
UtilDateAdaptor zInadequatePartsSource = |
35 |
|
- |
(pLastValidInternalFormValue instanceof CalendarYMD) ? ((CalendarYMD) pLastValidInternalFormValue).toUtilDateAdaptor() : null; |
36 |
|
- |
return mTemporalParser.parseDate( pText, mDateFormat.getDateRes(), zInadequatePartsSource ); |
37 |
|
- |
} |
38 |
|
- |
|
39 |
|
- |
@Override |
40 |
|
- |
protected void pickerClosed( boolean autoClosed ) { |
41 |
|
- |
super.pickerClosed( autoClosed ); |
42 |
|
- |
Date value = getPicker().getExitValue(); |
43 |
|
- |
|
44 |
|
- |
if ( value != null ) { |
45 |
|
- |
setTextValueFromPicker( mDateFormat.format( new CalendarYMD( value ) ) ); |
46 |
|
- |
} |
47 |
|
- |
} |
48 |
|
- |
|
49 |
|
- |
@Override |
50 |
|
- |
protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop, Object pCurrentValue, Object pLastValidInternalFormValue ) { |
51 |
|
- |
Date zDate; |
52 |
|
- |
if ( pCurrentValue instanceof CalendarYMD ) { |
53 |
|
- |
zDate = ((CalendarYMD) pCurrentValue).toUtilDate(); |
54 |
|
- |
} else if ( pLastValidInternalFormValue instanceof CalendarYMD ) { |
55 |
|
- |
zDate = ((CalendarYMD) pLastValidInternalFormValue).toUtilDate(); |
56 |
|
- |
} else { |
57 |
|
- |
zDate = new Date(); |
58 |
|
- |
} |
59 |
|
- |
getPicker().setFullDate( zDate ); |
60 |
|
- |
super.showPicker( pAbsoluteLeft, pAbsoluteTop, pCurrentValue, pLastValidInternalFormValue ); |
61 |
|
- |
} |
62 |
|
- |
|
63 |
|
- |
private MyPicker getPicker() { |
64 |
|
- |
return (MyPicker) mPicker; |
65 |
|
- |
} |
66 |
|
- |
|
67 |
|
- |
private static class MyPicker extends ExtendableDatePicker { |
68 |
|
- |
private Date mExitValue = null; |
69 |
|
- |
private Button mTodayButton; |
70 |
|
- |
|
71 |
|
- |
public MyPicker( String pCancelText, String pTodayText ) { |
72 |
|
- |
addDialogButtonPanel( Button.named( pCancelText ).red().text().create(), // |
73 |
|
- |
mTodayButton = Button.named( "Today" ).blue().text( pTodayText ).create() ); |
74 |
|
- |
} |
75 |
|
- |
|
76 |
|
- |
@Override |
77 |
|
- |
protected void dialogButtonClicked( Button pButton ) { |
78 |
|
- |
if ( mTodayButton == pButton ) { |
79 |
|
- |
mExitValue = new Date(); |
80 |
|
- |
} |
81 |
|
- |
hide(); |
82 |
|
- |
} |
83 |
|
- |
|
84 |
|
- |
public Date getExitValue() { |
85 |
|
- |
return mExitValue; |
86 |
|
- |
} |
87 |
|
- |
|
88 |
|
- |
@Override |
89 |
|
- |
public void show() { |
90 |
|
- |
mExitValue = null; |
91 |
|
- |
super.show(); |
92 |
|
- |
} |
93 |
|
- |
|
94 |
|
- |
@Override |
95 |
|
- |
protected void dateSelectedByClick( Date pDate ) { |
96 |
|
- |
mExitValue = selectedDate(); |
97 |
|
- |
hide(); |
98 |
|
- |
} |
99 |
|
- |
} |
100 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.forms.client.components.impls.input; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
5 |
+ |
import org.litesoft.GWT.forms.client.components.nonpublic.*; |
|
6 |
+ |
import org.litesoft.commonfoundation.typeutils.gregorian.*; |
|
7 |
+ |
import org.litesoft.core.simpletypes.temporal.*; |
|
8 |
+ |
import org.litesoft.core.simpletypes.temporal.nonpublic.*; |
|
9 |
+ |
import org.litesoft.uispecification.*; |
|
10 |
+ |
|
|
11 |
+ |
import java.util.*; |
|
12 |
+ |
|
|
13 |
+ |
public class FormDatePicker extends AbstractTextFieldWithPicker { |
|
14 |
+ |
private DateFormat mDateFormat; |
|
15 |
+ |
private TemporalParser mTemporalParser; |
|
16 |
+ |
|
|
17 |
+ |
public FormDatePicker( String pFieldLabel, UiFont pLabelFont, String pTooltip, String pCancelText, String pTodayText, DateFormat pDateFormat ) { |
|
18 |
+ |
// 1234567-101 |
|
19 |
+ |
// 04 JAN 1957 |
|
20 |
+ |
super( pTooltip, true, pDateFormat.getFormat().length(), "Calendar", new MyPicker( pCancelText, pTodayText ) ); |
|
21 |
+ |
initialize( pFieldLabel, pLabelFont, pTooltip ); |
|
22 |
+ |
|
|
23 |
+ |
mDateFormat = pDateFormat; |
|
24 |
+ |
String zFieldOrder = pDateFormat.getFieldOrder(); |
|
25 |
+ |
if ( zFieldOrder.equals( "dMy" ) && mDateFormat.getFormat().contains( "MMM" ) ) { |
|
26 |
+ |
zFieldOrder = "Mdy"; |
|
27 |
+ |
} |
|
28 |
+ |
mTemporalParser = new TemporalParser( zFieldOrder ); |
|
29 |
+ |
} |
|
30 |
+ |
|
|
31 |
+ |
@Override |
|
32 |
+ |
protected Object parseNotEmptyTextFieldToInternalForm( String pText, Object pLastValidInternalFormValue ) |
|
33 |
+ |
throws IllegalArgumentException { |
|
34 |
+ |
UtilDateAdaptor zInadequatePartsSource = |
|
35 |
+ |
(pLastValidInternalFormValue instanceof CalendarYMD) ? ((CalendarYMD) pLastValidInternalFormValue).toUtilDateAdaptor() : null; |
|
36 |
+ |
return mTemporalParser.parseDate( pText, mDateFormat.getDateRes(), zInadequatePartsSource ); |
|
37 |
+ |
} |
|
38 |
+ |
|
|
39 |
+ |
@Override |
|
40 |
+ |
protected void pickerClosed( boolean autoClosed ) { |
|
41 |
+ |
super.pickerClosed( autoClosed ); |
|
42 |
+ |
Date value = getPicker().getExitValue(); |
|
43 |
+ |
|
|
44 |
+ |
if ( value != null ) { |
|
45 |
+ |
setTextValueFromPicker( mDateFormat.format( new CalendarYMD( value ) ) ); |
|
46 |
+ |
} |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
@Override |
|
50 |
+ |
protected void showPicker( int pAbsoluteLeft, int pAbsoluteTop, Object pCurrentValue, Object pLastValidInternalFormValue ) { |
|
51 |
+ |
Date zDate; |
|
52 |
+ |
if ( pCurrentValue instanceof CalendarYMD ) { |
|
53 |
+ |
zDate = ((CalendarYMD) pCurrentValue).toUtilDate(); |
|
54 |
+ |
} else if ( pLastValidInternalFormValue instanceof CalendarYMD ) { |
|
55 |
+ |
zDate = ((CalendarYMD) pLastValidInternalFormValue).toUtilDate(); |
|
56 |
+ |
} else { |
|
57 |
+ |
zDate = new Date(); |
|
58 |
+ |
} |
|
59 |
+ |
getPicker().setFullDate( zDate ); |
|
60 |
+ |
super.showPicker( pAbsoluteLeft, pAbsoluteTop, pCurrentValue, pLastValidInternalFormValue ); |
|
61 |
+ |
} |
|
62 |
+ |
|
|
63 |
+ |
private MyPicker getPicker() { |
|
64 |
+ |
return (MyPicker) mPicker; |
|
65 |
+ |
} |
|
66 |
+ |
|
|
67 |
+ |
private static class MyPicker extends ExtendableDatePicker { |
|
68 |
+ |
private Date mExitValue = null; |
|
69 |
+ |
private Button mTodayButton; |
|
70 |
+ |
|
|
71 |
+ |
public MyPicker( String pCancelText, String pTodayText ) { |
|
72 |
+ |
addDialogButtonPanel( Button.named( pCancelText ).red().text().create(), // |
|
73 |
+ |
mTodayButton = Button.named( "Today" ).blue().text( pTodayText ).create() ); |
|
74 |
+ |
} |
|
75 |
+ |
|
|
76 |
+ |
@Override |
|
77 |
+ |
protected void dialogButtonClicked( Button pButton ) { |
|
78 |
+ |
if ( mTodayButton == pButton ) { |
|
79 |
+ |
mExitValue = new Date(); |
|
80 |
+ |
} |
|
81 |
+ |
hide(); |
|
82 |
+ |
} |
|
83 |
+ |
|
|
84 |
+ |
public Date getExitValue() { |
|
85 |
+ |
return mExitValue; |
|
86 |
+ |
} |
|
87 |
+ |
|
|
88 |
+ |
@Override |
|
89 |
+ |
public void show() { |
|
90 |
+ |
mExitValue = null; |
|
91 |
+ |
super.show(); |
|
92 |
+ |
} |
|
93 |
+ |
|
|
94 |
+ |
@Override |
|
95 |
+ |
protected void dateSelectedByClick( Date pDate ) { |
|
96 |
+ |
mExitValue = selectedDate(); |
|
97 |
+ |
hide(); |
|
98 |
+ |
} |
|
99 |
+ |
} |
|
100 |
+ |
} |